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

200 lines
7.7 KiB
Dart

3 years ago
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/app_state/app_state.dart';
3 years ago
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';
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_basic_details.model.dart';
import 'package:mohem_flutter_app/models/member_information_list_model.dart';
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
import 'package:mohem_flutter_app/ui/profile/dynamic_screens/dynamic_input_basic_details_screen.dart';
3 years ago
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 BasicDetails extends StatefulWidget {
const BasicDetails({Key? key}) : super(key: key);
@override
_BasicDetailsState createState() => _BasicDetailsState();
}
// TODO(Sultan): kindly follow structure of code written. use extension methods for widgets, use localization and format code
3 years ago
class _BasicDetailsState extends State<BasicDetails> {
String? fullName = "";
String? maritalStatus = "";
String? birthDate = "";
String? civilIdentityNumber = "";
String? emailAddress = "";
String? employeeNo = "";
int correctOrNew = 1;
List<GetEmployeeBasicDetailsList>? getEmployeeBasicDetailsList;
late MemberInformationListModel memberInformationList;
GetMenuEntriesList menuEntries = GetMenuEntriesList();
3 years ago
@override
void initState() {
super.initState();
memberInformationList = AppState().memberInformationList!;
List<GetMenuEntriesList> menuData = Provider.of<DashboardProviderModel>(context, listen: false).getMenuEntriesList!;
3 years ago
for (int i = 0; i < menuData.length; i++) {
3 years ago
menuData[i].icon == "";
}
var filterList = menuData.where((e) => e.requestType == 'BASIC_DETAILS').toList();
3 years ago
if (filterList.isNotEmpty) {
3 years ago
menuEntries = filterList.first;
}
3 years ago
getEmployeeBasicDetails();
}
void getEmployeeBasicDetails() async {
try {
Utils.showLoading(context);
getEmployeeBasicDetailsList = await ProfileApiClient().getEmployeeBasicDetails();
Utils.hideLoading(context);
setState(() {});
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
}
}
Widget build(BuildContext context) {
return Scaffold(
3 years ago
appBar: AppBarWidget(
context,
title: LocaleKeys.profile_basicDetails.tr(),
3 years ago
),
backgroundColor: MyColors.backgroundColor,
body: Column(
children: [
3 years ago
Expanded(
child: ListView(
padding: const EdgeInsets.all(21),
children: [
getEmployeeBasicDetailsList == null
? const SizedBox()
: (getEmployeeBasicDetailsList!.isEmpty
? Utils.getNoDataWidget(context)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: getEmployeeBasicDetailsList!
.map((e) => Column(
children: [
e.dISPLAYFLAG == "Y"
? Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
"${e.sEGMENTPROMPT}".toText13(color: MyColors.lightGrayColor),
"${e.sEGMENTVALUEDSP}".toText16(isBold: true, color: MyColors.blackColor),
12.height
])
: Container(),
],
))
.toList())
.objectContainerView())
],
),
),
3 years ago
DefaultButton(
LocaleKeys.update.tr(),
menuEntries.updateButton == 'Y'
? () async {
showAlertDialog(context);
}
: null)
.insideContainer,
3 years ago
],
3 years ago
));
3 years ago
}
3 years ago
void showAlertDialog(BuildContext context) {
3 years ago
Widget cancelButton = TextButton(
3 years ago
child: Text(LocaleKeys.cancel.tr()),
3 years ago
onPressed: () {
Navigator.pop(context);
},
);
Widget continueButton = TextButton(
3 years ago
child: Text(LocaleKeys.next.tr()),
onPressed: () {
continueDynamicForms();
},
3 years ago
);
StatefulBuilder alert = StatefulBuilder(builder: (context, setState) {
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(10.0))),
3 years ago
title: Text(LocaleKeys.confirm.tr()),
3 years ago
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(
3 years ago
LocaleKeys.selectType.tr(),
3 years ago
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
Divider(),
Column(
children: [
ListTile(
3 years ago
title: Text(LocaleKeys.correctCurrentDatails.tr()),
3 years ago
leading: Radio(
value: 1,
groupValue: correctOrNew,
3 years ago
onChanged: (value) {
setState(() {
correctOrNew = int.parse(value.toString());
3 years ago
});
},
activeColor: Colors.green,
),
),
ListTile(
3 years ago
title: Text(LocaleKeys.enterNewInfo.tr()),
3 years ago
leading: Radio(
value: 2,
groupValue: correctOrNew,
3 years ago
onChanged: (value) {
setState(() {
correctOrNew = int.parse(value.toString());
3 years ago
});
},
activeColor: Colors.green,
),
),
],
)
]));
}),
actions: [
cancelButton,
continueButton,
],
);
});
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
void continueDynamicForms() {
Navigator.pushNamed(context, AppRoutes.addDynamicInputProfile,
3 years ago
arguments: DynamicProfileParams(LocaleKeys.profile_basicDetails.tr(), 'HR_PERINFO_SS',
uRL: 'GET_BASIC_DET_DFF_STRUCTURE', requestID: 'BASIC_DETAILS', getEmployeeBasicDetailsList: getEmployeeBasicDetailsList, correctOrNew: correctOrNew));
}
3 years ago
}