Merge branch 'development_sikander' into 'master'
Development sikander See merge request Cloud_Solution/mohemm-flutter-app!185merge-requests/3/head
						commit
						77abf6da45
					
				@ -0,0 +1,166 @@
 | 
				
			|||||||
 | 
					import 'package:easy_localization/src/public_ext.dart';
 | 
				
			||||||
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					import 'package:mohem_flutter_app/api/login_api_client.dart';
 | 
				
			||||||
 | 
					import 'package:mohem_flutter_app/app_state/app_state.dart';
 | 
				
			||||||
 | 
					import 'package:mohem_flutter_app/classes/colors.dart';
 | 
				
			||||||
 | 
					import 'package:mohem_flutter_app/classes/utils.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/generic_response_model.dart';
 | 
				
			||||||
 | 
					import 'package:mohem_flutter_app/widgets/button/default_button.dart';
 | 
				
			||||||
 | 
					import 'package:mohem_flutter_app/widgets/input_widget.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ChangeItgAdPasswordScreen extends StatefulWidget {
 | 
				
			||||||
 | 
					  ChangeItgAdPasswordScreen({Key? key}) : super(key: key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override
 | 
				
			||||||
 | 
					  _ChangeItgAdPasswordScreenState createState() {
 | 
				
			||||||
 | 
					    return _ChangeItgAdPasswordScreenState();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class _ChangeItgAdPasswordScreenState extends State<ChangeItgAdPasswordScreen> {
 | 
				
			||||||
 | 
					  TextEditingController password = TextEditingController();
 | 
				
			||||||
 | 
					  TextEditingController confirmPassword = TextEditingController();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override
 | 
				
			||||||
 | 
					  void initState() {
 | 
				
			||||||
 | 
					    super.initState();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override
 | 
				
			||||||
 | 
					  void dispose() {
 | 
				
			||||||
 | 
					    super.dispose();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  void setNewPassword() async {
 | 
				
			||||||
 | 
					    Utils.showLoading(context);
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      GenericResponseModel response = await LoginApiClient().changePasswordFromActiveDirectorySession(password.text, AppState().memberInformationList!.eMPLOYEEEMAILADDRESS!);
 | 
				
			||||||
 | 
					      Utils.hideLoading(context);
 | 
				
			||||||
 | 
					      if ((response.messageStatus ?? 0) == 1) {
 | 
				
			||||||
 | 
					        Utils.showToast(LocaleKeys.passwordChangedSuccessfully.tr());
 | 
				
			||||||
 | 
					        Navigator.pop(context);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } catch (ex) {
 | 
				
			||||||
 | 
					      Utils.hideLoading(context);
 | 
				
			||||||
 | 
					      Utils.handleException(ex, context, (msg) {
 | 
				
			||||||
 | 
					        Utils.confirmDialog(context, msg);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @override
 | 
				
			||||||
 | 
					  Widget build(BuildContext context) {
 | 
				
			||||||
 | 
					    return Scaffold(
 | 
				
			||||||
 | 
					      appBar: AppBar(
 | 
				
			||||||
 | 
					        backgroundColor: Colors.transparent,
 | 
				
			||||||
 | 
					        leading: IconButton(
 | 
				
			||||||
 | 
					          icon: const Icon(Icons.arrow_back_ios, color: MyColors.darkIconColor),
 | 
				
			||||||
 | 
					          onPressed: () => Navigator.pop(context),
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					      ),
 | 
				
			||||||
 | 
					      body: Column(
 | 
				
			||||||
 | 
					        children: [
 | 
				
			||||||
 | 
					          ListView(
 | 
				
			||||||
 | 
					            padding: const EdgeInsets.all(21),
 | 
				
			||||||
 | 
					            children: [
 | 
				
			||||||
 | 
					              LocaleKeys.changePassword.tr().toText24(isBold: true),
 | 
				
			||||||
 | 
					              LocaleKeys.typeYourNewActiveDirectoryPasswordBelow.tr().toText16(),
 | 
				
			||||||
 | 
					              16.height,
 | 
				
			||||||
 | 
					              InputWidget(
 | 
				
			||||||
 | 
					                LocaleKeys.password.tr(),
 | 
				
			||||||
 | 
					                "**********",
 | 
				
			||||||
 | 
					                password,
 | 
				
			||||||
 | 
					                onChange: (value) {
 | 
				
			||||||
 | 
					                  setState(() {});
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              ),
 | 
				
			||||||
 | 
					              12.height,
 | 
				
			||||||
 | 
					              InputWidget(
 | 
				
			||||||
 | 
					                LocaleKeys.confirmPassword.tr(),
 | 
				
			||||||
 | 
					                "**********",
 | 
				
			||||||
 | 
					                confirmPassword,
 | 
				
			||||||
 | 
					                isTextIsPassword: true,
 | 
				
			||||||
 | 
					                onChange: (value) {
 | 
				
			||||||
 | 
					                  setState(() {});
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              ),
 | 
				
			||||||
 | 
					              16.height,
 | 
				
			||||||
 | 
					              passwordConstraintsUI(LocaleKeys.doNotUseRecentPassword.tr(), true),
 | 
				
			||||||
 | 
					              8.height,
 | 
				
			||||||
 | 
					              passwordConstraintsUI(LocaleKeys.atLeastOneLowercase.tr(), checkRegEx(r'[a-z]')),
 | 
				
			||||||
 | 
					              // 8.height,
 | 
				
			||||||
 | 
					              // passwordConstraintsUI(LocaleKeys.atLeastOneUppercase.tr(), checkRegEx(r'[A-Z]')),
 | 
				
			||||||
 | 
					              8.height,
 | 
				
			||||||
 | 
					              passwordConstraintsUI(LocaleKeys.atLeastOneNumeric.tr(), checkRegEx(r'[0-9]')),
 | 
				
			||||||
 | 
					              8.height,
 | 
				
			||||||
 | 
					              passwordConstraintsUI(LocaleKeys.minimum8Characters.tr(), password.text.length >= 8),
 | 
				
			||||||
 | 
					              8.height,
 | 
				
			||||||
 | 
					              passwordConstraintsUI(LocaleKeys.doNotAddRepeatingLetters.tr(), checkRepeatedChars(password.text)),
 | 
				
			||||||
 | 
					              // 8.height,
 | 
				
			||||||
 | 
					              // passwordConstraintsUI(LocaleKeys.itShouldContainSpecialCharacter.tr(), checkRegEx(r'[!@#$%^&*(),.?":{}|<>]')),
 | 
				
			||||||
 | 
					              8.height,
 | 
				
			||||||
 | 
					              passwordConstraintsUI(LocaleKeys.confirmPasswordMustMatch.tr(), password.text.isNotEmpty && password.text == confirmPassword.text),
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					          ).expanded,
 | 
				
			||||||
 | 
					          DefaultButton(LocaleKeys.changePassword.tr(), (!isPasswordCompliant(password.text, 8)) ? null : setNewPassword).insideContainer
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					      ),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  bool checkRegEx(String pattern) {
 | 
				
			||||||
 | 
					    return RegExp(pattern).hasMatch(password.text);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  String recentPassword = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  bool isPasswordCompliant(String? password, int minLength) {
 | 
				
			||||||
 | 
					    if (password == null || password.isEmpty) {
 | 
				
			||||||
 | 
					      return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // bool hasUppercase = password.contains(RegExp(r'[A-Z]'));
 | 
				
			||||||
 | 
					    bool hasDigits = password.contains(RegExp(r'[0-9]'));
 | 
				
			||||||
 | 
					    bool hasLowercase = password.contains(RegExp(r'[a-z]'));
 | 
				
			||||||
 | 
					    // bool hasSpecialCharacters = password.contains(RegExp(r'[!@#$%^&*(),.?":{}|<>]'));
 | 
				
			||||||
 | 
					    bool hasMinLength = password.length >= minLength;
 | 
				
			||||||
 | 
					    bool isMatched = password == confirmPassword.text;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return hasDigits && hasLowercase && hasMinLength && isMatched && checkRepeatedChars(password);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  bool checkRepeatedChars(String password) {
 | 
				
			||||||
 | 
					    bool isNonRepeatedLetters = true;
 | 
				
			||||||
 | 
					    if (password.length > 2) {
 | 
				
			||||||
 | 
					      for (int i = 0; i < password.length; i++) {
 | 
				
			||||||
 | 
					        String char = password[i];
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					          if (char == password[i + 1]) {
 | 
				
			||||||
 | 
					            isNonRepeatedLetters = false;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        } catch (ex) {}
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return isNonRepeatedLetters;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Widget passwordConstraintsUI(String description, bool check) {
 | 
				
			||||||
 | 
					    return Row(
 | 
				
			||||||
 | 
					      children: [
 | 
				
			||||||
 | 
					        4.width,
 | 
				
			||||||
 | 
					        SizedBox(
 | 
				
			||||||
 | 
					          width: 12,
 | 
				
			||||||
 | 
					          height: 12,
 | 
				
			||||||
 | 
					          child: Checkbox(fillColor: MaterialStateProperty.all(MyColors.gradiantEndColor), shape: const CircleBorder(), value: check, onChanged: null),
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					        8.width,
 | 
				
			||||||
 | 
					        description.toText14()
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Loading…
					
					
				
		Reference in New Issue