2023-03-24 06:46:17 +00:00
|
|
|
import 'package:app_popup_menu/app_popup_menu.dart';
|
2023-02-03 03:34:09 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-06 00:57:39 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
|
|
|
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
2023-03-24 06:46:17 +00:00
|
|
|
import 'package:fluttericon/font_awesome_icons.dart';
|
2023-03-06 00:57:39 +00:00
|
|
|
import 'package:unit2/bloc/profile/profile_bloc.dart';
|
|
|
|
import 'package:unit2/bloc/user/user_bloc.dart';
|
2023-03-24 06:46:17 +00:00
|
|
|
import 'package:unit2/screens/profile/components/reference/add_modal.dart';
|
|
|
|
import 'package:unit2/screens/profile/components/reference/edit_modal.dart';
|
2023-02-09 08:48:19 +00:00
|
|
|
import 'package:unit2/theme-data.dart/box_shadow.dart';
|
2023-02-03 03:34:09 +00:00
|
|
|
import 'package:unit2/theme-data.dart/colors.dart';
|
2023-02-09 08:48:19 +00:00
|
|
|
import 'package:unit2/utils/text_container.dart';
|
2023-03-02 00:40:47 +00:00
|
|
|
import 'package:unit2/widgets/Leadings/add_leading.dart';
|
2023-03-24 06:46:17 +00:00
|
|
|
import 'package:unit2/widgets/Leadings/close_leading.dart';
|
|
|
|
import 'package:unit2/widgets/error_state.dart';
|
2023-02-03 03:34:09 +00:00
|
|
|
|
2023-03-07 02:31:28 +00:00
|
|
|
import '../../../bloc/profile/references/references_bloc.dart';
|
2023-03-24 06:46:17 +00:00
|
|
|
import '../../../utils/alerts.dart';
|
2023-03-07 02:31:28 +00:00
|
|
|
|
2023-02-10 07:39:00 +00:00
|
|
|
class ReferencesScreen extends StatelessWidget {
|
2023-03-06 00:57:39 +00:00
|
|
|
const ReferencesScreen({super.key});
|
2023-03-24 06:46:17 +00:00
|
|
|
|
2023-02-03 03:34:09 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-03-24 06:46:17 +00:00
|
|
|
int? profileId;
|
|
|
|
String? token;
|
2023-02-10 07:39:00 +00:00
|
|
|
return Scaffold(
|
2023-04-11 01:27:53 +00:00
|
|
|
resizeToAvoidBottomInset: true,
|
2023-03-06 00:57:39 +00:00
|
|
|
appBar: AppBar(
|
2023-04-11 01:27:53 +00:00
|
|
|
title: context.watch<ReferencesBloc>().state is AddReferenceState
|
|
|
|
? const Text("Add Personal Reference")
|
|
|
|
: context.watch<ReferencesBloc>().state is EditReferenceState
|
|
|
|
? const Text("Edit Personal Reference")
|
|
|
|
: const Text("Personal References"),
|
|
|
|
centerTitle: true,
|
|
|
|
backgroundColor: primary,
|
|
|
|
////if state is adding or editing state show close button
|
|
|
|
actions: (context.watch<ReferencesBloc>().state
|
|
|
|
is AddReferenceState ||
|
|
|
|
context.watch<ReferencesBloc>().state is EditReferenceState)
|
|
|
|
? [
|
|
|
|
//// close button
|
|
|
|
CloseLeading(onPressed: () {
|
|
|
|
context.read<ReferencesBloc>().add(
|
|
|
|
GetReferences(profileId: profileId!, token: token!));
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
:
|
|
|
|
//// if state is loaded state show add button
|
|
|
|
context.watch<ReferencesBloc>().state is ReferencesLoadedState
|
|
|
|
? [
|
|
|
|
AddLeading(onPressed: () {
|
|
|
|
context
|
|
|
|
.read<ReferencesBloc>()
|
|
|
|
.add(ShowAddReferenceForm());
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
: []),
|
2023-03-06 00:57:39 +00:00
|
|
|
body: ProgressHUD(
|
2023-03-24 06:46:17 +00:00
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
backgroundColor: Colors.black87,
|
|
|
|
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
2023-03-06 00:57:39 +00:00
|
|
|
child: BlocBuilder<UserBloc, UserState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
//userbloc
|
|
|
|
if (state is UserLoggedIn) {
|
2023-03-24 06:46:17 +00:00
|
|
|
token = state.userData!.user!.login!.token;
|
|
|
|
profileId = state.userData!.user!.login!.user!.profileId;
|
2023-03-06 00:57:39 +00:00
|
|
|
return BlocBuilder<ProfileBloc, ProfileState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
//profilebloc
|
|
|
|
if (state is ProfileLoaded) {
|
|
|
|
return BlocConsumer<ReferencesBloc, ReferencesState>(
|
|
|
|
//listener
|
|
|
|
listener: (context, state) {
|
2023-03-24 06:46:17 +00:00
|
|
|
if (state is ReferencesLoadingState) {
|
|
|
|
final progress = ProgressHUD.of(context);
|
|
|
|
progress!.showWithText("Please wait...");
|
|
|
|
}
|
|
|
|
if (state is ReferencesLoadedState ||
|
|
|
|
state is AddReferenceState ||
|
|
|
|
state is ReferencesErrorState ||
|
|
|
|
state is DeleteReferenceState ||
|
|
|
|
state is ReferencesAddedState ||
|
|
|
|
state is EditReferenceState) {
|
|
|
|
final progress = ProgressHUD.of(context);
|
|
|
|
progress!.dismiss();
|
2023-03-06 00:57:39 +00:00
|
|
|
}
|
2023-03-24 06:46:17 +00:00
|
|
|
////ADDED STATE
|
|
|
|
if (state is ReferencesAddedState) {
|
|
|
|
if (state.response['success']) {
|
|
|
|
successAlert(context, "Adding Successfull!",
|
|
|
|
state.response['message'], () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context.read<ReferencesBloc>().add(
|
|
|
|
LoadReferences(
|
2023-04-11 01:27:53 +00:00
|
|
|
));
|
2023-03-24 06:46:17 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
errorAlert(context, "Adding Failed",
|
|
|
|
"Something went wrong. Please try again.",
|
|
|
|
() {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context.read<ReferencesBloc>().add(
|
|
|
|
LoadReferences(
|
2023-04-11 01:27:53 +00:00
|
|
|
));
|
2023-03-24 06:46:17 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
////EDIT REFERENCE STATE
|
|
|
|
if (state is ReferenceEditedState) {
|
|
|
|
if (state.response['success']) {
|
|
|
|
successAlert(context, "Update Successfull!",
|
|
|
|
state.response['message'], () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context.read<ReferencesBloc>().add(
|
|
|
|
LoadReferences(
|
2023-04-11 01:27:53 +00:00
|
|
|
));
|
2023-03-24 06:46:17 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
errorAlert(context, "Update Failed",
|
|
|
|
"Something went wrong. Please try again.",
|
|
|
|
() {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context.read<ReferencesBloc>().add(
|
|
|
|
LoadReferences(
|
2023-04-11 01:27:53 +00:00
|
|
|
));
|
2023-03-24 06:46:17 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////DELETED STATE
|
|
|
|
if (state is DeleteReferenceState) {
|
|
|
|
if (state.success) {
|
|
|
|
successAlert(context, "Deletion Successfull",
|
|
|
|
"Eligibility has been deleted successfully",
|
|
|
|
() {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context.read<ReferencesBloc>().add(
|
|
|
|
LoadReferences(
|
2023-04-11 01:27:53 +00:00
|
|
|
));
|
2023-03-24 06:46:17 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
errorAlert(context, "Deletion Failed",
|
|
|
|
"Error deleting eligibility", () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context.read<ReferencesBloc>().add(
|
|
|
|
LoadReferences(
|
2023-04-11 01:27:53 +00:00
|
|
|
));
|
2023-03-24 06:46:17 +00:00
|
|
|
});
|
|
|
|
}
|
2023-03-06 00:57:39 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
//builder
|
|
|
|
builder: (context, state) {
|
|
|
|
//references bloc
|
|
|
|
if (state is ReferencesLoadedState) {
|
|
|
|
if (state.references.isNotEmpty) {
|
2023-03-24 06:46:17 +00:00
|
|
|
return ListView.builder(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 8, horizontal: 10),
|
|
|
|
itemCount: state.references.length,
|
|
|
|
itemBuilder:
|
|
|
|
(BuildContext context, int index) {
|
|
|
|
String fullname =
|
|
|
|
"${state.references[index].firstName} ${state.references[index].middleName} ${state.references[index].lastName}";
|
|
|
|
String addres = state.references[index]
|
|
|
|
.address!.country?.id !=
|
|
|
|
175
|
|
|
|
? "COUNTRY: ${state.references[index].address!.country!.name!.toUpperCase()}"
|
|
|
|
: "${state.references[index].address?.cityMunicipality?.description}, ${state.references[index].address?.cityMunicipality?.province?.description}, ${state.references[index].address?.cityMunicipality?.province?.region?.description}";
|
|
|
|
|
|
|
|
String mobile = state
|
|
|
|
.references[index].contactNo
|
|
|
|
.toString();
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 12, vertical: 8),
|
|
|
|
decoration: box1(),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(fullname.toUpperCase(),
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.titleMedium!
|
|
|
|
.copyWith(
|
|
|
|
fontWeight:
|
|
|
|
FontWeight
|
|
|
|
.w500)),
|
|
|
|
const Divider(),
|
|
|
|
const SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
|
|
|
Text(addres,
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.titleSmall!
|
|
|
|
.copyWith(
|
|
|
|
fontWeight:
|
|
|
|
FontWeight
|
|
|
|
.w500)),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${mobileOrPhone.toUpperCase()} : $mobile",
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.labelMedium!),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
AppPopupMenu<int>(
|
|
|
|
offset: const Offset(-10, -10),
|
|
|
|
elevation: 3,
|
|
|
|
onSelected: (value) {
|
|
|
|
////delete eligibilty-= = = = = = = = =>>
|
|
|
|
if (value == 2) {
|
2023-04-11 01:27:53 +00:00
|
|
|
|
2023-03-24 06:46:17 +00:00
|
|
|
confirmAlert(context, () {
|
2023-04-11 01:27:53 +00:00
|
|
|
final progress =
|
|
|
|
ProgressHUD.of(context);
|
|
|
|
progress!.showWithText(
|
|
|
|
"Please wait...");
|
2023-03-24 06:46:17 +00:00
|
|
|
context
|
|
|
|
.read<
|
|
|
|
ReferencesBloc>()
|
|
|
|
.add(DeleteReference(
|
|
|
|
profileId:
|
|
|
|
profileId!,
|
|
|
|
refId: state
|
|
|
|
.references[
|
|
|
|
index]
|
|
|
|
.id!,
|
|
|
|
references: state
|
|
|
|
.references,
|
|
|
|
token: token!));
|
|
|
|
}, "Delete?",
|
|
|
|
"Confirm Delete?");
|
|
|
|
}
|
|
|
|
if (value == 1) {
|
|
|
|
////edit reference-= = = = = = = = =>>
|
2023-04-11 01:27:53 +00:00
|
|
|
final progress =
|
|
|
|
ProgressHUD.of(context);
|
|
|
|
progress!.showWithText(
|
|
|
|
"Please wait...");
|
2023-03-24 06:46:17 +00:00
|
|
|
context
|
|
|
|
.read<ReferencesBloc>()
|
|
|
|
.add(ShowEditReferenceForm(
|
|
|
|
personalReference:
|
|
|
|
state.references[
|
|
|
|
index]));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
menuItems: [
|
|
|
|
popMenuItem(
|
|
|
|
text: "Edit",
|
|
|
|
value: 1,
|
|
|
|
icon: Icons.edit),
|
|
|
|
popMenuItem(
|
|
|
|
text: "Delete",
|
|
|
|
value: 2,
|
|
|
|
icon: Icons.delete),
|
|
|
|
popMenuItem(
|
|
|
|
text: "Attachment",
|
|
|
|
value: 3,
|
|
|
|
icon: FontAwesome.attach)
|
|
|
|
],
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.more_vert,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
|
|
|
tooltip: "Options",
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
});
|
2023-03-06 00:57:39 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-24 06:46:17 +00:00
|
|
|
if (state is AddReferenceState) {
|
2023-04-11 01:27:53 +00:00
|
|
|
return AddReferenceScreen(profileId: profileId!, token: token!,);
|
2023-03-24 06:46:17 +00:00
|
|
|
}
|
|
|
|
if (state is EditReferenceState) {
|
2023-04-11 01:27:53 +00:00
|
|
|
return EditReferenceScreen(profileId: profileId!,token: token!,);
|
2023-03-24 06:46:17 +00:00
|
|
|
}
|
|
|
|
if (state is ReferencesErrorState) {
|
|
|
|
return SomethingWentWrong(
|
2023-04-11 01:27:53 +00:00
|
|
|
message: state.message, onpressed: () {
|
|
|
|
context.read<ReferencesBloc>().add(GetReferences(profileId: profileId!, token: token!));
|
|
|
|
});
|
2023-03-24 06:46:17 +00:00
|
|
|
}
|
2023-03-06 00:57:39 +00:00
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
));
|
2023-02-03 03:34:09 +00:00
|
|
|
}
|
2023-03-06 00:57:39 +00:00
|
|
|
|
2023-03-24 06:46:17 +00:00
|
|
|
PopupMenuItem<int> popMenuItem({String? text, int? value, IconData? icon}) {
|
|
|
|
return PopupMenuItem(
|
|
|
|
value: value,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
icon,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
text!,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|