You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
267 lines
11 KiB
Dart
267 lines
11 KiB
Dart
import 'package:easy_localization/src/public_ext.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mohem_flutter_app/api/profile_api_client.dart';
|
|
import 'package:mohem_flutter_app/classes/colors.dart';
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
import 'package:mohem_flutter_app/config/routes.dart';
|
|
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
|
|
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
|
|
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
|
|
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
|
|
import 'package:mohem_flutter_app/models/dashboard/menu_entries.dart';
|
|
import 'package:mohem_flutter_app/models/get_employee_contacts.model.dart';
|
|
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
|
|
import 'package:mohem_flutter_app/ui/profile/profile_screen.dart';
|
|
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
|
|
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class FamilyMembers extends StatefulWidget {
|
|
const FamilyMembers({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_FamilyMembersState createState() => _FamilyMembersState();
|
|
}
|
|
|
|
class _FamilyMembersState extends State<FamilyMembers> {
|
|
List<GetEmployeeContactsList> getEmployeeContactsList = [];
|
|
|
|
int? relationId;
|
|
int? flag;
|
|
GetMenuEntriesList menuEntries = GetMenuEntriesList();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
List<GetMenuEntriesList> menuData = Provider.of<DashboardProviderModel>(context, listen: false).getMenuEntriesList!;
|
|
menuEntries = menuData.where((GetMenuEntriesList e) => e.requestType == 'CONTACT').toList()[0];
|
|
getEmployeeContacts();
|
|
}
|
|
|
|
void getEmployeeContacts() async {
|
|
try {
|
|
Utils.showLoading(context);
|
|
getEmployeeContactsList = await ProfileApiClient().getEmployeeContacts();
|
|
Utils.hideLoading(context);
|
|
setState(() {});
|
|
} catch (ex) {
|
|
Utils.hideLoading(context);
|
|
Utils.handleException(ex, context, null);
|
|
}
|
|
}
|
|
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBarWidget(
|
|
context,
|
|
title: LocaleKeys.profile_familyDetails.tr(),
|
|
),
|
|
backgroundColor: MyColors.backgroundColor,
|
|
body: Column(
|
|
children: [
|
|
20.height,
|
|
Expanded(
|
|
child: getEmployeeContactsList.length != 0
|
|
? SingleChildScrollView(
|
|
padding: const EdgeInsets.all(21),
|
|
scrollDirection: Axis.vertical,
|
|
child: ListView.separated(
|
|
scrollDirection: Axis.vertical,
|
|
shrinkWrap: true,
|
|
physics: ScrollPhysics(),
|
|
separatorBuilder: (cxt, index) => 12.height,
|
|
itemCount: getEmployeeContactsList.length,
|
|
itemBuilder: (context, index) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
"${getEmployeeContactsList[index].cONTACTNAME}".toText16(isBold: true, color: MyColors.grey3AColor),
|
|
"${getEmployeeContactsList[index].rELATIONSHIP}".toText11(isBold: true, color: MyColors.textMixColor),
|
|
]),
|
|
const Divider(
|
|
color: Color(0xffEFEFEF),
|
|
thickness: 1,
|
|
indent: 0,
|
|
endIndent: 0,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: <Widget>[
|
|
menuEntries.updateButton == 'Y'
|
|
? InkWell(
|
|
onTap: () async{
|
|
relationId = getEmployeeContactsList[index]!.cONTACTRELATIONSHIPID!.toInt();
|
|
showUpdateAlertDialog(context, relationId!.toInt(), 2, LocaleKeys.update.tr());
|
|
},
|
|
child: RichText(
|
|
text: TextSpan(
|
|
children: [
|
|
WidgetSpan(
|
|
child: Icon(
|
|
Icons.edit,
|
|
size: 15,
|
|
color: MyColors.grey67Color,
|
|
),
|
|
),
|
|
TextSpan(
|
|
text: LocaleKeys.update.tr(),
|
|
style: TextStyle(
|
|
color: MyColors.grey67Color,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: RichText(
|
|
text: TextSpan(
|
|
children: [
|
|
WidgetSpan(
|
|
child: Icon(
|
|
Icons.edit,
|
|
size: 15,
|
|
color: MyColors.lightGreyColor,
|
|
),
|
|
),
|
|
TextSpan(
|
|
text: LocaleKeys.update.tr(),
|
|
style: TextStyle(
|
|
color: MyColors.lightGreyColor,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
height: 35,
|
|
width: 1,
|
|
color: Color(0xffEFEFEF),
|
|
),
|
|
InkWell(
|
|
onTap: () {
|
|
relationId = getEmployeeContactsList[index]!.cONTACTRELATIONSHIPID!.toInt();
|
|
showRemoveAlertDialog(context, relationId!.toInt());
|
|
},
|
|
child: RichText(
|
|
text: TextSpan(
|
|
children: [
|
|
WidgetSpan(
|
|
child: Icon(
|
|
Icons.delete,
|
|
size: 15,
|
|
color: MyColors.redColor,
|
|
),
|
|
),
|
|
TextSpan(
|
|
text: LocaleKeys.remove.tr(),
|
|
style: TextStyle(
|
|
color: MyColors.redColor,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
).objectContainerView();
|
|
}),
|
|
)
|
|
: Container(),
|
|
),
|
|
DefaultButton(
|
|
LocaleKeys.addNewFamilyMember.tr(), () async {
|
|
Navigator.pushNamed(context, AppRoutes.addUpdateFamilyMember, arguments: {"relationID": relationId, "flag": 1, "actionType": "ADD"});
|
|
ProfileScreen();
|
|
}
|
|
).insideContainer,
|
|
],
|
|
));
|
|
}
|
|
|
|
|
|
void showUpdateAlertDialog(BuildContext context, int relationId, int flag, String actionType) {
|
|
Widget cancelButton = TextButton(
|
|
child: Text(
|
|
LocaleKeys.cancel.tr(),
|
|
),
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
);
|
|
Widget continueButton = TextButton(
|
|
child: Text(
|
|
LocaleKeys.ok.tr(),
|
|
),
|
|
onPressed: () {
|
|
Navigator.pushNamed(
|
|
context,
|
|
AppRoutes.addUpdateFamilyMember,
|
|
arguments: {"relationID": relationId, "flag": flag, "actionType": "UPDATE"},
|
|
);
|
|
},
|
|
);
|
|
AlertDialog alert = AlertDialog(
|
|
title: Text(
|
|
LocaleKeys.confirm.tr(),
|
|
),
|
|
content: Text(LocaleKeys.updateThisMember.tr()),
|
|
actions: [
|
|
cancelButton,
|
|
continueButton,
|
|
],
|
|
);
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return alert;
|
|
},
|
|
);
|
|
}
|
|
|
|
void showRemoveAlertDialog(BuildContext context, int relationId) {
|
|
Widget cancelButton = TextButton(
|
|
child: Text(
|
|
LocaleKeys.cancel.tr(),
|
|
),
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
);
|
|
Widget continueButton = TextButton(
|
|
child: Text(
|
|
LocaleKeys.ok.tr(),
|
|
),
|
|
onPressed: () {
|
|
Navigator.pushNamed(context, AppRoutes.deleteFamilyMember, arguments: relationId);
|
|
// continueDynamicForms();
|
|
},
|
|
);
|
|
AlertDialog alert = AlertDialog(
|
|
title: Text(
|
|
LocaleKeys.confirm.tr(),
|
|
),
|
|
content: Text(LocaleKeys.removeThisMember.tr()),
|
|
actions: [
|
|
cancelButton,
|
|
continueButton,
|
|
],
|
|
);
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return alert;
|
|
},
|
|
);
|
|
}
|
|
|
|
|
|
}
|