diff --git a/lib/pages/auth/bloc/auth_bloc.dart b/lib/pages/auth/bloc/auth_bloc.dart index 851811e9..cf01a73c 100644 --- a/lib/pages/auth/bloc/auth_bloc.dart +++ b/lib/pages/auth/bloc/auth_bloc.dart @@ -34,6 +34,8 @@ class AuthBloc extends Bloc { final TextEditingController forgetPasswordController = TextEditingController(); final TextEditingController forgetOtp = TextEditingController(); final forgetFormKey = GlobalKey(); + final forgetEmailKey = GlobalKey(); + final forgetRegionKey = GlobalKey(); late bool checkValidate = false; Timer? _timer; @@ -93,34 +95,36 @@ class AuthBloc extends Bloc { } Future changePassword(ChangePasswordEvent event, Emitter emit) async { - try { - emit(LoadingForgetState()); - var response = await AuthenticationAPI.verifyOtp( - email: forgetEmailController.text, otpCode: forgetOtp.text); - if (response == true) { - await AuthenticationAPI.forgetPassword( - password: forgetPasswordController.text, email: forgetEmailController.text); - _timer?.cancel(); - emit(const TimerState(isButtonEnabled: true, remainingTime: 0)); - emit(SuccessForgetState()); + emit(LoadingForgetState()); + try { + var response = await AuthenticationAPI.verifyOtp( + email: forgetEmailController.text, otpCode: forgetOtp.text); + if (response == true) { + await AuthenticationAPI.forgetPassword( + password: forgetPasswordController.text, + email: forgetEmailController.text); + _timer?.cancel(); + emit(const TimerState(isButtonEnabled: true, remainingTime: 0)); + emit(SuccessForgetState()); + } + } on DioException catch (e) { + final errorData = e.response!.data; + String errorMessage = errorData['message']; + if (errorMessage == 'this email is not registered') { + validate = 'Invalid Credentials!'; + emit(AuthInitialState()); + } else if (errorMessage == "You entered wrong otp") { + forgetValidate = 'Wrong one time password.'; + emit(AuthInitialState()); + } else if (errorMessage == "OTP expired") { + forgetValidate = 'One time password has been expired.'; + emit(AuthInitialState()); + } else { + validate = ''; + emit(AuthInitialState()); + } } - } on DioException catch (e) { - final errorData = e.response!.data; - String errorMessage = errorData['message']; - if (errorMessage == 'this email is not registered') { - validate = 'Invalid Credentials!'; - emit(AuthInitialState()); - } else if (errorMessage == "You entered wrong otp") { - forgetValidate = 'Wrong one time password.'; - emit(AuthInitialState()); - } else if (errorMessage == "OTP expired") { - forgetValidate = 'One time password has been expired.'; - emit(AuthInitialState()); - } else { - validate = ''; - emit(AuthInitialState()); - } - } + } String? validateCode(String? value) { @@ -231,9 +235,10 @@ class AuthBloc extends Bloc { return 'Email is required'; } else if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value)) { return 'Enter a valid email address'; - } else if (regionUuid == '') { - return 'Please select your region'; } + // else if (regionUuid == '') { + // return 'Please select your region'; + // } validate = ''; return null; } @@ -371,6 +376,7 @@ class AuthBloc extends Bloc { try { emit(AuthLoading()); regionUuid = event.val; + add(CheckEnableEvent()); emit(AuthInitialState()); } catch (e) { emit(FailureForgetState(error: e.toString())); diff --git a/lib/pages/auth/view/forget_password_web_page.dart b/lib/pages/auth/view/forget_password_web_page.dart index 60270908..427e8b35 100644 --- a/lib/pages/auth/view/forget_password_web_page.dart +++ b/lib/pages/auth/view/forget_password_web_page.dart @@ -64,91 +64,94 @@ class ForgetPasswordWebPage extends StatelessWidget { Size size = MediaQuery.of(context).size; return FirstLayer( second: Center( - child: Stack( + child: Stack( + children: [ + if (state is AuthLoading) + const Center(child: CircularProgressIndicator()), + ListView( + shrinkWrap: true, + controller: _scrollController, children: [ - if (state is AuthLoading) - const Center(child: CircularProgressIndicator()), - ListView( - shrinkWrap: true, - controller: _scrollController, - children: [ - Container( - padding: EdgeInsets.all(size.width * 0.02), - margin: EdgeInsets.all(size.width * 0.09), - decoration: BoxDecoration( - color: Colors.black.withOpacity(0.3), - borderRadius: const BorderRadius.all(Radius.circular(20)), - ), - child: Center( - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Spacer(), - Expanded( - flex: 3, - child: SvgPicture.asset( - Assets.loginLogo, - ), - ), - const Spacer(), - Expanded( - flex: 3, - child: Container( - decoration: BoxDecoration( - color: Colors.white.withOpacity(0.1), - borderRadius: + Container( + padding: EdgeInsets.all(size.width * 0.02), + margin: EdgeInsets.all(size.width * 0.09), + decoration: BoxDecoration( + color: Colors.black.withOpacity(0.3), + borderRadius: const BorderRadius.all(Radius.circular(20)), + ), + child: Center( + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Spacer(), + Expanded( + flex: 3, + child: SvgPicture.asset( + Assets.loginLogo, + ), + ), + const Spacer(), + Expanded( + flex: 3, + child: Container( + decoration: BoxDecoration( + color: Colors.white.withOpacity(0.1), + borderRadius: const BorderRadius.all(Radius.circular(30)), - border: Border.all( - color: + border: Border.all( + color: ColorsManager.graysColor.withOpacity(0.2)), - ), - child: Form( - key: forgetBloc.forgetFormKey, - child: Padding( - padding: EdgeInsets.symmetric( - horizontal: size.width * 0.02, - vertical: size.width * 0.003), - child: Column( - mainAxisAlignment: + ), + child: Form( + key: forgetBloc.forgetFormKey, + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: size.width * 0.02, + vertical: size.width * 0.003), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox(height: 10), - const Text( - 'Forget Password', - style: TextStyle( - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.bold), - ), - const SizedBox(height: 10), - Text( - 'Please fill in your account information to\nretrieve your password', - style: Theme.of(context) - .textTheme - .bodySmall! - .copyWith( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 10), + const Text( + 'Forget Password', + style: TextStyle( + color: Colors.white, + fontSize: 24, + fontWeight: FontWeight.bold), + ), + const SizedBox(height: 10), + Text( + 'Please fill in your account information to\nretrieve your password', + style: Theme.of(context) + .textTheme + .bodySmall! + .copyWith( fontSize: 14, fontWeight: FontWeight.w400), - ), + ), + const SizedBox(height: 10), + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ const SizedBox(height: 10), - Column( + SizedBox( + child: _buildDropdownField( + context, forgetBloc, size)) + ], + ), + const SizedBox(height: 20), + Form( + key: forgetBloc.forgetEmailKey, + child: Column( crossAxisAlignment: - CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const SizedBox(height: 10), - SizedBox( - child: _buildDropdownField(context, forgetBloc, size) - ) - ], - ), - const SizedBox(height: 20), - Column( - crossAxisAlignment: - CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, + CrossAxisAlignment.start, + mainAxisAlignment: + MainAxisAlignment.start, children: [ Text( "Account", @@ -156,17 +159,20 @@ class ForgetPasswordWebPage extends StatelessWidget { .textTheme .bodySmall! .copyWith( - fontSize: 14, - fontWeight: FontWeight.w400), + fontSize: 14, + fontWeight: + FontWeight.w400), ), const SizedBox(height: 10), SizedBox( child: TextFormField( - controller:forgetBloc.forgetEmailController , + controller: forgetBloc.forgetEmailController, validator: forgetBloc.validateEmail, - decoration: textBoxDecoration()!.copyWith( + decoration: + textBoxDecoration()!.copyWith( hintText: 'Enter your email', - hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith( + hintStyle: Theme.of(context) + .textTheme.bodySmall!.copyWith( color: ColorsManager.grayColor, fontWeight: FontWeight.w400), ), @@ -174,200 +180,239 @@ class ForgetPasswordWebPage extends StatelessWidget { color: Colors.black), ), ), - if(forgetBloc.forgetEmailValidate!='') - SizedBox( - child: Text( - forgetBloc.forgetEmailValidate, - style: const TextStyle( - fontWeight: FontWeight.w700, - color: ColorsManager.red), - ), - ), - const SizedBox(height: 10.0), - ], - ), - const SizedBox(height: 20.0), - Column( - crossAxisAlignment: + )), + const SizedBox(height: 20.0), + Column( + crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - "One Time Password", - style: Theme.of(context) + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + "One Time Password", + style: Theme.of(context) + .textTheme + .bodySmall! + .copyWith( + fontSize: 14, + fontWeight: FontWeight.w400), + ), + const SizedBox(height: 10), + SizedBox( + child: TextFormField( + validator: forgetBloc.validateCode, + keyboardType: + TextInputType.visiblePassword, + controller: forgetBloc.forgetOtp, + decoration: + textBoxDecoration()!.copyWith( + hintText: 'Enter Code', + hintStyle: Theme.of(context) .textTheme .bodySmall! .copyWith( - fontSize: 14, - fontWeight: FontWeight.w400), - ), - const SizedBox(height: 10), - SizedBox( - child: TextFormField( - validator: forgetBloc.validateCode, - keyboardType: - TextInputType.visiblePassword, - controller: forgetBloc.forgetOtp, - decoration: - textBoxDecoration()!.copyWith( - hintText: 'Enter Code', - hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith( - color: ColorsManager.grayColor, - fontWeight: FontWeight.w400), - suffixIcon: SizedBox( - width: 100, - child: Center( - child: InkWell( - onTap: state is TimerState && - !state.isButtonEnabled && - state.remainingTime != 1 - ? null : () { - forgetBloc.add(StartTimerEvent()); - - }, - child: Text( - 'Get Code ${state is TimerState && !state.isButtonEnabled && state.remainingTime != 1 ? "(${forgetBloc.formattedTime(state.remainingTime)}) " : ""}', - style: TextStyle( - color: state is TimerState && - !state.isButtonEnabled - ? Colors.grey - : ColorsManager.btnColor, - ), - ), + color: + ColorsManager.grayColor, + fontWeight: + FontWeight.w400), + suffixIcon: SizedBox( + width: 100, + child: Center( + child: InkWell( + onTap: state is TimerState && + !state + .isButtonEnabled && + state.remainingTime != + 1 + ? null + : () { + if (forgetBloc + .forgetEmailKey + .currentState! + .validate()) { + forgetBloc.add( + StartTimerEvent()); + } + }, + child: Text( + 'Get Code ${state is TimerState && !state.isButtonEnabled && state.remainingTime != 1 ? "(${forgetBloc.formattedTime(state.remainingTime)}) " : ""}', + style: TextStyle( + color: state + is TimerState && + !state + .isButtonEnabled + ? Colors.grey + : ColorsManager + .btnColor, ), ), ), ), - style: const TextStyle( - color: Colors.black), ), ), - if (forgetBloc.forgetValidate != '') // Check if there is a validation message - Padding( - padding: + style: const TextStyle( + color: Colors.black), + ), + ), + if (forgetBloc.forgetValidate != + '') // Check if there is a validation message + Padding( + padding: const EdgeInsets.only(top: 8.0), - child: Text( - forgetBloc.forgetValidate, - style: const TextStyle( - color: ColorsManager.red, - fontSize: 10, - fontWeight: FontWeight.w700), + child: Text( + forgetBloc.forgetValidate, + style: const TextStyle( + color: ColorsManager.red, + fontSize: 10, + fontWeight: FontWeight.w700), + ), + ), + ], + ), + const SizedBox(height: 20.0), + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + "Password", + style: Theme.of(context) + .textTheme + .bodySmall! + .copyWith( + fontSize: 14, + fontWeight: FontWeight.w400), + ), + const SizedBox(height: 10), + SizedBox( + child: TextFormField( + obscureText: forgetBloc.obscureText, + keyboardType: + TextInputType.visiblePassword, + validator: + forgetBloc.passwordValidator, + controller: forgetBloc + .forgetPasswordController, + decoration: + textBoxDecoration()!.copyWith( + suffixIcon: IconButton( + onPressed: () { + forgetBloc.add( + PasswordVisibleEvent( + newValue: forgetBloc + .obscureText)); + }, + icon: SizedBox( + child: SvgPicture.asset( + forgetBloc.obscureText + ? Assets.visiblePassword + : Assets + .invisiblePassword, + height: 15, + width: 15, + ), ), ), - ], - ), - const SizedBox(height: 20.0), - Column( - crossAxisAlignment: - CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - "Password", - style: Theme.of(context) + hintText: 'At least 8 characters', + hintStyle: Theme.of(context) .textTheme .bodySmall! .copyWith( - fontSize: 14, - fontWeight: FontWeight.w400), - ), - const SizedBox(height: 10), - SizedBox( - child: TextFormField( - validator: forgetBloc.passwordValidator, - keyboardType: TextInputType.visiblePassword, - controller: forgetBloc.forgetPasswordController, - decoration: textBoxDecoration()!.copyWith( - hintText: 'At least 8 characters', - hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith( - color: ColorsManager.grayColor, - fontWeight: FontWeight.w400), - ), - style: const TextStyle(color: Colors.black), - ), - ), - ], - ), - const SizedBox( - height: 10, - ), - const SizedBox(height: 20.0), - Row( - crossAxisAlignment: - CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox( - width: size.width * 0.2, - child: DefaultButton( - backgroundColor: - ColorsManager.btnColor, - child: const Text('Submit'), - onPressed: () { - if (forgetBloc.forgetFormKey.currentState!.validate()) { - forgetBloc.add(ChangePasswordEvent()); - } - }, - ), - ), - ], - ), - const SizedBox(height: 10.0), - Center( - child: SizedBox( - child: Text( - forgetBloc.validate, - style: const TextStyle( - fontWeight: FontWeight.w700, - color: ColorsManager.red), + color: + ColorsManager.grayColor, + fontWeight: + FontWeight.w400), ), + style: const TextStyle( + color: Colors.black), ), ), - const SizedBox( - height: 10, - ), - SizedBox( - child: Center( - child: Wrap( - children: [ - const Text( - "Do you have an account? ", - style: TextStyle(color: Colors.white), - ), - InkWell( - onTap: () { - forgetBloc.add(StopTimerEvent()); - Navigator.pop(context); - }, - child: const Text( - "Sign in", - ), - ), - ], - ), - ), - ), - const SizedBox(height: 15.0), ], ), - ), + const SizedBox( + height: 10, + ), + const SizedBox(height: 20.0), + Row( + crossAxisAlignment: + CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + width: size.width * 0.2, + child: DefaultButton( + backgroundColor: + ColorsManager.btnColor, + child: const Text('Submit'), + onPressed: () { + if (forgetBloc.forgetFormKey.currentState!.validate() || + forgetBloc.forgetEmailKey.currentState!.validate() ) { + if( forgetBloc.forgetEmailKey.currentState!.validate() + &&forgetBloc.forgetFormKey.currentState!.validate() ){ + forgetBloc.add(ChangePasswordEvent()); + } + } + }, + ), + ), + ], + ), + const SizedBox(height: 10.0), + Center( + child: SizedBox( + child: Text( + forgetBloc.validate, + style: const TextStyle( + fontWeight: FontWeight.w700, + color: ColorsManager.red), + ), + ), + ), + const SizedBox( + height: 10, + ), + SizedBox( + child: Center( + child: Wrap( + children: [ + const Text( + "Do you have an account? ", + style: + TextStyle(color: Colors.white), + ), + InkWell( + onTap: () { + forgetBloc.add(StopTimerEvent()); + Navigator.pop(context); + }, + child: const Text( + "Sign in", + ), + ), + ], + ), + ), + ), + const SizedBox(height: 15.0), + ], ), ), ), - const Spacer(), - ], + ), ), - ), + const Spacer(), + ], ), - ], + ), ), ], ), - )); + ], + ), + )); } - Widget _buildDropdownField( BuildContext context, AuthBloc loginBloc, Size size) { final TextEditingController textEditingController = TextEditingController(); @@ -378,100 +423,396 @@ class ForgetPasswordWebPage extends StatelessWidget { Text( "Country/Region", style: Theme.of(context).textTheme.bodySmall!.copyWith( - fontSize: 14, - fontWeight: FontWeight.w400, - ), + fontSize: 14, + fontWeight: FontWeight.w400, + ), ), const SizedBox(height: 10), Container( - height: 50, - decoration: const BoxDecoration( - color: ColorsManager.boxColor, - borderRadius: BorderRadius.all(Radius.circular(8)), - ), width: size.width * 0.9, - child: DropdownButtonHideUnderline( - child: DropdownButton2( - style: TextStyle(color: Colors.black), - isExpanded: true, - hint: Text( - 'Select your region/country', - style: Theme.of(context).textTheme.bodySmall!.copyWith( - color: ColorsManager.grayColor, - fontWeight: FontWeight.w400, - ), - overflow: TextOverflow.ellipsis, - ), - items: loginBloc.regionList!.map((RegionModel region) { - return DropdownMenuItem( - value: region.id, // Use region.id as the value - child: Text( - region.name, - overflow: TextOverflow.ellipsis, - maxLines: 1, + child: FormField( + validator: (value) { + if (value == null || value.isEmpty) { + return 'Please select a country/region'; + } + return null; + }, + builder: (FormFieldState field) { + return InputDecorator( + decoration: InputDecoration( + contentPadding: + const EdgeInsets.symmetric(horizontal: 16, vertical: 10), + errorText: field.errorText, + filled: + true, // Ensure the dropdown is filled with the background color + fillColor: ColorsManager + .boxColor, // Match the dropdown container color + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8.0), + borderSide: BorderSide( + color: field.hasError ? Colors.red : Colors.transparent, + width: 1.5, + ), ), - ); - }).toList(), - value: loginBloc.regionList!.any( - (region) => region.id == loginBloc.regionUuid,) - ? loginBloc.regionUuid - : null, - onChanged: (String? value) { - if (value != null) { - - loginBloc.add(SelectRegionEvent( - val: value, - )); - } - }, - buttonStyleData: const ButtonStyleData( - padding: EdgeInsets.symmetric(horizontal: 16), - height: 40, - width: double.infinity, - ), - dropdownStyleData: DropdownStyleData( - maxHeight: size.height * 0.70, - ), - menuItemStyleData: const MenuItemStyleData( - height: 40, - ), - dropdownSearchData: DropdownSearchData( - searchController: textEditingController, - searchInnerWidgetHeight: 50, - searchInnerWidget: Container( - height: 50, - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), - child: TextFormField( - style: const TextStyle(color: Colors.black), - controller: textEditingController, - decoration: textBoxDecoration()!.copyWith( - errorStyle: const TextStyle(height: 0), - contentPadding: const EdgeInsets.symmetric( - vertical: 12, - horizontal: 10, - ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8.0), + borderSide: BorderSide( + color: + field.hasError ? Colors.red : ColorsManager.grayColor, + width: 1.5, + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8.0), + borderSide: BorderSide( + color: + field.hasError ? Colors.red : ColorsManager.grayColor, + width: 1.5, + ), + ), + errorBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8.0), + borderSide: BorderSide( + color: Colors.red, + width: 1.5, ), ), ), - searchMatchFn: (item, searchValue) { - // Use the item's child text (region name) for searching. - final regionName = (item.child as Text).data?.toLowerCase() ?? ''; - final search = searchValue.toLowerCase().trim(); - // Debugging print statement to ensure values are captured correctly. - // Return true if the region name contains the search term. - return regionName.contains(search); - }, - ), - onMenuStateChange: (isOpen) { - if (!isOpen) { - textEditingController.clear(); - } - }, - ), + child: DropdownButtonHideUnderline( + child: DropdownButton2( + isExpanded: true, + hint: Text( + 'Select your region/country', + style: Theme.of(context).textTheme.bodySmall!.copyWith( + color: ColorsManager.grayColor, + fontWeight: FontWeight.w400, + ), + overflow: TextOverflow.ellipsis, + ), + items: loginBloc.regionList!.map((RegionModel region) { + return DropdownMenuItem( + value: region.id, + child: Text( + region.name, + overflow: TextOverflow.ellipsis, + maxLines: 1, + ), + ); + }).toList(), + value: loginBloc.regionList! + .any((region) => region.id == loginBloc.regionUuid) + ? loginBloc.regionUuid + : null, + onChanged: (String? value) { + if (value != null) { + loginBloc.add(SelectRegionEvent(val: value)); + field.didChange( + value); // Notify the form field of the change + } + }, + buttonStyleData: const ButtonStyleData( + padding: EdgeInsets.symmetric(horizontal: 16), + height: 40, + width: double.infinity, + ), + dropdownStyleData: DropdownStyleData( + maxHeight: size.height * 0.70, + decoration: BoxDecoration( + color: ColorsManager + .boxColor, // Match dropdown background color to the container + borderRadius: BorderRadius.circular(8.0), + ), + ), + menuItemStyleData: const MenuItemStyleData( + height: 40, + ), + dropdownSearchData: DropdownSearchData( + searchController: textEditingController, + searchInnerWidgetHeight: 50, + searchInnerWidget: Container( + height: 50, + padding: const EdgeInsets.symmetric( + horizontal: 8, vertical: 4), + child: TextFormField( + style: const TextStyle(color: Colors.black), + controller: textEditingController, + decoration: textBoxDecoration()!.copyWith( + errorStyle: const TextStyle(height: 0), + contentPadding: const EdgeInsets.symmetric( + vertical: 12, + horizontal: 10, + ), + ), + ), + ), + searchMatchFn: (item, searchValue) { + final regionName = + (item.child as Text).data?.toLowerCase() ?? ''; + final search = searchValue.toLowerCase().trim(); + return regionName.contains(search); + }, + ), + onMenuStateChange: (isOpen) { + if (!isOpen) { + textEditingController.clear(); + } + }, + ), + ), + ); + }, ), ), - ], ); } + +// Widget _buildDropdownField(BuildContext context, AuthBloc loginBloc, Size size) { + // final TextEditingController textEditingController = TextEditingController(); + // + // return Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // mainAxisAlignment: MainAxisAlignment.start, + // children: [ + // Text( + // "Country/Region", + // style: Theme.of(context).textTheme.bodySmall!.copyWith( + // fontSize: 14, + // fontWeight: FontWeight.w400, + // ), + // ), + // const SizedBox(height: 10), + // Container( + // decoration: const BoxDecoration( + // color: ColorsManager.boxColor, + // borderRadius: BorderRadius.all(Radius.circular(8)), + // ), + // width: size.width * 0.9, + // child: FormField( + // validator: (value) { + // if (value == null || value.isEmpty) { + // return 'Please select a country/region'; + // } + // return null; + // }, + // builder: (FormFieldState field) { + // return InputDecorator( + // decoration: InputDecoration( + // contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10), + // errorText: field.errorText, + // border: OutlineInputBorder( + // borderRadius: BorderRadius.circular(8.0), + // borderSide: BorderSide( + // color: field.hasError ? Colors.red : Colors.transparent, + // width: 1.5, + // ), + // ), + // enabledBorder: OutlineInputBorder( + // borderRadius: BorderRadius.circular(8.0), + // borderSide: BorderSide( + // color: field.hasError ? Colors.red : ColorsManager.grayColor, + // width: 1.5, + // ), + // ), + // focusedBorder: OutlineInputBorder( + // borderRadius: BorderRadius.circular(8.0), + // borderSide: BorderSide( + // color: field.hasError ? Colors.red : ColorsManager.grayColor, + // width: 1.5, + // ), + // ), + // errorBorder: OutlineInputBorder( + // borderRadius: BorderRadius.circular(8.0), + // borderSide: BorderSide( + // color: Colors.red, + // width: 1.5, + // ), + // ), + // ), + // child: DropdownButtonHideUnderline( + // child: DropdownButton2( + // isExpanded: true, + // hint: Text( + // 'Select your region/country', + // style: Theme.of(context).textTheme.bodySmall!.copyWith( + // color: ColorsManager.grayColor, + // fontWeight: FontWeight.w400, + // ), + // overflow: TextOverflow.ellipsis, + // ), + // items: loginBloc.regionList!.map((RegionModel region) { + // return DropdownMenuItem( + // value: region.id, + // child: Text( + // region.name, + // overflow: TextOverflow.ellipsis, + // maxLines: 1, + // ), + // ); + // }).toList(), + // value: loginBloc.regionList!.any((region) => region.id == loginBloc.regionUuid) + // ? loginBloc.regionUuid + // : null, + // onChanged: (String? value) { + // if (value != null) { + // loginBloc.add(SelectRegionEvent(val: value)); + // field.didChange(value); // Notify the form field of the change + // } + // }, + // buttonStyleData: const ButtonStyleData( + // padding: EdgeInsets.symmetric(horizontal: 16), + // height: 40, + // width: double.infinity, + // ), + // dropdownStyleData: DropdownStyleData( + // maxHeight: size.height * 0.70, + // ), + // menuItemStyleData: const MenuItemStyleData( + // height: 40, + // ), + // dropdownSearchData: DropdownSearchData( + // searchController: textEditingController, + // searchInnerWidgetHeight: 50, + // searchInnerWidget: Container( + // height: 50, + // padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + // child: TextFormField( + // style: const TextStyle(color: Colors.black), + // controller: textEditingController, + // decoration: textBoxDecoration()!.copyWith( + // errorStyle: const TextStyle(height: 0), + // contentPadding: const EdgeInsets.symmetric( + // vertical: 12, + // horizontal: 10, + // ), + // ), + // ), + // ), + // searchMatchFn: (item, searchValue) { + // final regionName = (item.child as Text).data?.toLowerCase() ?? ''; + // final search = searchValue.toLowerCase().trim(); + // return regionName.contains(search); + // }, + // ), + // onMenuStateChange: (isOpen) { + // if (!isOpen) { + // textEditingController.clear(); + // } + // }, + // ), + // ), + // ); + // }, + // ), + // ), + // ], + // ); + // } + +// Widget _buildDropdownField( + // BuildContext context, AuthBloc loginBloc, Size size) { + // final TextEditingController textEditingController = TextEditingController(); + // return Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // mainAxisAlignment: MainAxisAlignment.start, + // children: [ + // Text( + // "Country/Region", + // style: Theme.of(context).textTheme.bodySmall!.copyWith( + // fontSize: 14, + // fontWeight: FontWeight.w400, + // ), + // ), + // const SizedBox(height: 10), + // Container( + // height: 50, + // decoration: const BoxDecoration( + // color: ColorsManager.boxColor, + // borderRadius: BorderRadius.all(Radius.circular(8)), + // ), + // width: size.width * 0.9, + // child: DropdownButtonHideUnderline( + // child: DropdownButton2( + // style: TextStyle(color: Colors.black), + // isExpanded: true, + // hint: Text( + // 'Select your region/country', + // style: Theme.of(context).textTheme.bodySmall!.copyWith( + // color: ColorsManager.grayColor, + // fontWeight: FontWeight.w400, + // ), + // overflow: TextOverflow.ellipsis, + // ), + // items: loginBloc.regionList!.map((RegionModel region) { + // return DropdownMenuItem( + // value: region.id, // Use region.id as the value + // child: Text( + // region.name, + // overflow: TextOverflow.ellipsis, + // maxLines: 1, + // ), + // ); + // }).toList(), + // value: loginBloc.regionList!.any( + // (region) => region.id == loginBloc.regionUuid,) + // ? loginBloc.regionUuid + // : null, + // onChanged: (String? value) { + // if (value != null) { + // + // loginBloc.add(SelectRegionEvent( + // val: value, + // )); + // } + // }, + // buttonStyleData: const ButtonStyleData( + // padding: EdgeInsets.symmetric(horizontal: 16), + // height: 40, + // width: double.infinity, + // ), + // dropdownStyleData: DropdownStyleData( + // maxHeight: size.height * 0.70, + // ), + // menuItemStyleData: const MenuItemStyleData( + // height: 40, + // ), + // dropdownSearchData: DropdownSearchData( + // searchController: textEditingController, + // searchInnerWidgetHeight: 50, + // searchInnerWidget: Container( + // height: 50, + // padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + // child: TextFormField( + // style: const TextStyle(color: Colors.black), + // controller: textEditingController, + // decoration: textBoxDecoration()!.copyWith( + // errorStyle: const TextStyle(height: 0), + // contentPadding: const EdgeInsets.symmetric( + // vertical: 12, + // horizontal: 10, + // ), + // ), + // ), + // ), + // searchMatchFn: (item, searchValue) { + // // Use the item's child text (region name) for searching. + // final regionName = (item.child as Text).data?.toLowerCase() ?? ''; + // final search = searchValue.toLowerCase().trim(); + // // Debugging print statement to ensure values are captured correctly. + // // Return true if the region name contains the search term. + // return regionName.contains(search); + // }, + // ), + // onMenuStateChange: (isOpen) { + // if (!isOpen) { + // textEditingController.clear(); + // } + // }, + // ), + // ), + // ), + // + // ], + // ); + // } } diff --git a/lib/pages/common/hour_picker_dialog.dart b/lib/pages/common/hour_picker_dialog.dart index 091fca26..6fb4f83a 100644 --- a/lib/pages/common/hour_picker_dialog.dart +++ b/lib/pages/common/hour_picker_dialog.dart @@ -10,7 +10,7 @@ class HourPickerDialog extends StatefulWidget { class _HourPickerDialogState extends State { late int _selectedHour; - bool _isPm = false; + bool _isPm = true; @override void initState() { @@ -18,7 +18,7 @@ class _HourPickerDialogState extends State { _selectedHour = widget.initialTime.hour > 12 ? widget.initialTime.hour - 12 : widget.initialTime.hour; - _isPm = widget.initialTime.period == DayPeriod.pm; + _isPm = widget.initialTime.period == DayPeriod.am; } @override diff --git a/lib/pages/device_managment/ac/view/ac_device_control.dart b/lib/pages/device_managment/ac/view/ac_device_control.dart index 3e47885c..c2b554b9 100644 --- a/lib/pages/device_managment/ac/view/ac_device_control.dart +++ b/lib/pages/device_managment/ac/view/ac_device_control.dart @@ -69,7 +69,7 @@ class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout { deviceId: device.uuid!, description: 'Child Lock', icon: - state.status.childLock ? Assets.unlock : Assets.childLock, + state.status.childLock ? Assets.childLock:Assets.unlock , ), ], );