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/contact_details.dart

293 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/string_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_address_model.dart';
import 'package:mohem_flutter_app/models/get_employee_basic_details.model.dart';
import 'package:mohem_flutter_app/models/get_employee_phones_model.dart';
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
import 'package:mohem_flutter_app/ui/profile/dynamic_screens/dynamic_input_address_screen.dart';
import 'package:mohem_flutter_app/ui/profile/phone_numbers.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 ContactDetails extends StatefulWidget {
const ContactDetails({Key? key}) : super(key: key);
@override
_ContactDetailsState createState() => _ContactDetailsState();
}
class _ContactDetailsState extends State<ContactDetails> {
String? fullName = "";
String? maritalStatus = "";
String? birthDate = "";
String? civilIdentityNumber = "";
String? emailAddress = "";
String? employeeNo = "";
int? correctOrNew = 1;
List<GetEmployeePhonesList> getEmployeePhonesList = [];
List<GetEmployeeAddressList> getEmployeeAddressList = [];
List<GetEmployeeBasicDetailsList> getEmployeeBasicDetailsList = [];
GetMenuEntriesList menuEntriesPhone = GetMenuEntriesList();
GetMenuEntriesList menuEntriesAddress = GetMenuEntriesList();
@override
void initState() {
super.initState();
List<GetMenuEntriesList> menuData = Provider.of<DashboardProviderModel>(context, listen: false).getMenuEntriesList!;
menuEntriesPhone = menuData.where((GetMenuEntriesList e) => e.requestType == 'PHONE_NUMBERS').toList()[0];
menuEntriesAddress = menuData.where((GetMenuEntriesList e) => e.requestType == 'ADDRESS').toList()[0];
getEmployeePhones();
setState(() {});
}
void getEmployeePhones() async {
try {
Utils.showLoading(context);
getEmployeePhonesList = await ProfileApiClient().getEmployeePhones();
getEmployeeAddress();
Utils.hideLoading(context);
setState(() {});
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
}
}
void getEmployeeAddress() async {
try {
Utils.showLoading(context);
getEmployeeAddressList = await ProfileApiClient().getEmployeeAddress();
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_contactDetails.tr(),
),
backgroundColor: MyColors.backgroundColor,
body: SingleChildScrollView(
child: Column(children: [
Container(
width: double.infinity,
margin: EdgeInsets.only(
top: 20,
left: 26,
right: 26,
),
padding: EdgeInsets.all(15),
///height: 200,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 26,
offset: Offset(0, 3),
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child: Stack(children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
menuEntriesPhone.updateButton == 'Y'
? IconButton(
icon: Icon(
Icons.edit_location_alt_outlined,
size: 20,
),
onPressed: () {
updatePhone();
},
)
: Container()
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: getEmployeePhonesList
.map((e) => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
"${e.pHONETYPEMEANING}".toText13(color: MyColors.lightGrayColor),
"${e.pHONENUMBER}".toText16(isBold: true, color: MyColors.blackColor),
]))
.toList())
])),
Container(
width: double.infinity,
margin: EdgeInsets.only(
top: 20,
left: 26,
right: 26,
),
padding: EdgeInsets.all(15),
// height: 400,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 26,
offset: Offset(0, 3),
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child: Stack(children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
menuEntriesAddress.updateButton == 'Y'
? IconButton(
icon: Icon(
Icons.edit_location_alt_outlined,
size: 20,
),
onPressed: () {
addUpdateAddress();
},
)
: Container()
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: getEmployeeAddressList
.map((e) => Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
"${e.sEGMENTPROMPT}".toText13(color: MyColors.lightGrayColor),
"${e.sEGMENTVALUEDSP}".toText16(isBold: true, color: MyColors.blackColor),
SizedBox(
height: 20,
),
]))
.toList())
]))
])));
}
// Widget footer() {
// return Container(
// decoration: BoxDecoration(
// // borderRadius: BorderRadius.circular(10),
// color: MyColors.white,
// boxShadow: [
// BoxShadow(color: MyColors.lightGreyEFColor, spreadRadius: 3),
// ],
// ),
// child: DefaultButton(LocaleKeys.update.tr(), () async {
// // context.setLocale(const Locale("en", "US")); // to change Loacle
// ProfileScreen();
// }).insideContainer,
// );
// }
void updatePhone() {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PhoneNumbers(getEmployeePhonesList: this.getEmployeePhonesList)),
);
}
void addUpdateAddress() {
Widget cancelButton = TextButton(
child: Text("Cancel"),
onPressed: () {
Navigator.pop(context);
},
);
Widget continueButton = TextButton(
child: Text("Next"),
onPressed: () {
continueDynamicForms();
},
);
StatefulBuilder alert = StatefulBuilder(builder: (context, setState) {
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10.0))),
title: Text("Confirm"),
content: Builder(builder: (context) {
// Get available height and width of the build area of this widget. Make a choice depending on the size.
var height = MediaQuery.of(context).size.height * .5;
return Container(
height: height,
child: Column(children: [
Text(
"Select the type of change you want to make.",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
Divider(),
Column(
children: [
ListTile(
title: Text("Correct or amend this address"),
leading: Radio(
value: 1,
groupValue: correctOrNew,
onChanged: (value) {
setState(() {
correctOrNew = int.parse(value.toString());
});
},
activeColor: Colors.green,
),
),
ListTile(
title: Text("Enter a new address if you have moved"),
leading: Radio(
value: 2,
groupValue: correctOrNew,
onChanged: (value) {
setState(() {
correctOrNew = int.parse(value.toString());
});
},
activeColor: Colors.green,
),
),
],
)
]));
}),
actions: [
cancelButton,
continueButton,
],
);
});
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
void continueDynamicForms() {
Navigator.pushNamed(context, AppRoutes.addDynamicAddressScreen,
arguments: DynamicProfileParams(LocaleKeys.profile_address.tr(), 'HR_PERINFO_SS',
uRL: 'GET_ADDRESS_DFF_STRUCTURE', requestID: 'BASIC_DETAILS', getEmployeeAddressList: getEmployeeAddressList, correctOrNew: correctOrNew!));
}
}