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.
mohemm-flutter-app/lib/ui/profile/family_members.dart

215 lines
8.4 KiB
Dart

3 years ago
import 'package:easy_localization/src/public_ext.dart';
3 years ago
import 'package:flutter/gestures.dart';
3 years ago
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';
3 years ago
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
3 years ago
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
3 years ago
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';
3 years ago
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';
3 years ago
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
import 'package:provider/provider.dart';
3 years ago
class FamilyMembers extends StatefulWidget {
const FamilyMembers({Key? key}) : super(key: key);
@override
_FamilyMembersState createState() => _FamilyMembersState();
}
class _FamilyMembersState extends State<FamilyMembers> {
List<GetEmployeeContactsList> getEmployeeContactsList = [];
3 years ago
dynamic? relationId;
int? flag;
GetMenuEntriesList menuEntries = GetMenuEntriesList();
3 years ago
@override
void initState() {
super.initState();
3 years ago
List<GetMenuEntriesList> menuData = Provider.of<DashboardProviderModel>(context, listen: false).getMenuEntriesList!;
List<GetMenuEntriesList> arr = menuData.where((GetMenuEntriesList e) => e.requestType == 'CONTACT').toList();
if(arr.isNotEmpty){
menuEntries = arr[0];
}else{
menuEntries = new GetMenuEntriesList();
}
3 years ago
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(),
3 years ago
),
backgroundColor: MyColors.backgroundColor,
3 years ago
body: Column(
3 years ago
children: [
3 years ago
Expanded(
3 years ago
child: getEmployeeContactsList.isEmpty ? Utils.getNoDataWidget(context)
: ListView.separated(
padding: const EdgeInsets.all(21),
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(color: MyColors.grey3AColor),
"${getEmployeeContactsList[index].rELATIONSHIP}".toText11(color: MyColors.textMixColor),
]).paddingOnly(top: 15, left: 13, right: 13, bottom: 12),
1.divider,
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
// todo @faitma clean below logic and write clean code.
RichText(
text: TextSpan(
children: [
WidgetSpan(
3 years ago
child: Icon(Icons.edit, size: 14, color: menuEntries.updateButton == 'Y' ? MyColors.grey67Color : MyColors.lightGreyColor,)
),
3 years ago
TextSpan(
text: LocaleKeys.update.tr(),
3 years ago
style:TextStyle(color: menuEntries.updateButton == 'Y' ? MyColors.grey67Color : MyColors.lightGreyColor, fontSize: 12, letterSpacing: -0.36, fontWeight: FontWeight.w600),
recognizer: TapGestureRecognizer()
..onTap = () async {
3 years ago
relationId = getEmployeeContactsList[index]!.cONTACTRELATIONSHIPID;
menuEntries.updateButton == 'Y'? showUpdateAlertDialog(context, relationId, 2, "UPDATE"):null;
3 years ago
}
)
],
),
),
Container(height: 35, width: 1, color: const Color(0xffEFEFEF)),
3 years ago
RichText(
text: TextSpan(
children: [
const WidgetSpan(
child: Icon(
Icons.delete, size: 15, color: MyColors.redColor,),
3 years ago
),
TextSpan(
text: LocaleKeys.remove.tr(),
style: const TextStyle(color: MyColors.redColor, fontSize: 12, letterSpacing: -0.36, fontWeight: FontWeight.w600),
),
3 years ago
],
),
3 years ago
).onPress(() { relationId = getEmployeeContactsList[index]!.cONTACTRELATIONSHIPID;
showRemoveAlertDialog(context, relationId);}),
],
),
],
).objectContainerView(disablePadding: true);
3 years ago
}),
3 years ago
),
3 years ago
DefaultButton(LocaleKeys.addNewFamilyMember.tr(),
menuEntries.updateButton == 'Y'
3 years ago
?
() async {
3 years ago
Navigator.pushNamed(context, AppRoutes.addUpdateFamilyMember, arguments: {"relationID": relationId, "flag": 1, "actionType": "ADD"});
3 years ago
// ProfileScreen();
} : null).insideContainer,
3 years ago
],
));
3 years ago
}
3 years ago
void showUpdateAlertDialog(BuildContext context, 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,
3 years ago
arguments: {"relationID": relationId, "flag": 2, "actionType": "UPDATE"},
);
},
);
AlertDialog alert = AlertDialog(
title: Text(
LocaleKeys.confirm.tr(),
),
3 years ago
content: Text(LocaleKeys.updateMember.tr()),
actions: [
cancelButton,
continueButton,
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
3 years ago
void showRemoveAlertDialog(BuildContext context, relationId) {
3 years ago
Widget cancelButton = TextButton(
child: Text(
LocaleKeys.cancel.tr(),
),
onPressed: () {
3 years ago
Navigator.pop(context);
},
);
Widget continueButton = TextButton(
child: Text(
LocaleKeys.ok.tr(),
),
onPressed: () {
Navigator.pushNamed(context, AppRoutes.deleteFamilyMember, arguments: relationId);
// continueDynamicForms();
},
3 years ago
);
AlertDialog alert = AlertDialog(
title: Text(
LocaleKeys.confirm.tr(),
),
3 years ago
content: Text(LocaleKeys.removeThisMember.tr()),
3 years ago
actions: [
cancelButton,
continueButton,
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
}