From f27a9b0d8a5ffba80d18d57c0dc324aa7e90b048 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 28 Jul 2024 15:27:34 +0300 Subject: [PATCH 1/3] profile page fix bugs --- .../menu/bloc/profile_bloc/profile_bloc.dart | 13 ++----------- .../menu/view/widgets/profile/region_page.dart | 4 +--- .../view/widgets/profile/time_zone_screen_page.dart | 12 +++++------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/lib/features/menu/bloc/profile_bloc/profile_bloc.dart b/lib/features/menu/bloc/profile_bloc/profile_bloc.dart index 603fe20..cad8762 100644 --- a/lib/features/menu/bloc/profile_bloc/profile_bloc.dart +++ b/lib/features/menu/bloc/profile_bloc/profile_bloc.dart @@ -23,8 +23,7 @@ class ProfileBloc extends Bloc { String timeZoneSelected = ''; String regionSelected = ''; final TextEditingController searchController = TextEditingController(); - final TextEditingController nameController = TextEditingController( - text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}'); + final TextEditingController nameController = TextEditingController(text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}'); List? timeZoneList; List? regionList; @@ -240,25 +239,17 @@ class ProfileBloc extends Bloc { String? fullNameValidator(String? value) { if (value == null) return 'Full name is required'; - final withoutExtraSpaces = value.replaceAll(RegExp(r"\s+"), ' ').trim(); - if (withoutExtraSpaces.length < 2 || withoutExtraSpaces.length > 30) { return 'Full name must be between 2 and 30 characters long'; } - // Test if it contains anything but alphanumeric spaces and single quote - if (RegExp(r"/[^ a-zA-Z0-9-\']/").hasMatch(withoutExtraSpaces)) { return 'Only alphanumeric characters, space, dash and single quote are allowed'; } - final parts = withoutExtraSpaces.split(' '); - if (parts.length < 2) return 'Full name must contain first and last names'; - - if (parts.length > 3) return 'Full name can at most contain 3 parts'; - + if (parts.length > 2) return 'Full name can at most contain 3 parts'; if (parts.any((part) => part.length < 2 || part.length > 30)) { return 'Full name parts must be between 2 and 30 characters long'; } diff --git a/lib/features/menu/view/widgets/profile/region_page.dart b/lib/features/menu/view/widgets/profile/region_page.dart index 6a5ae74..0212cb2 100644 --- a/lib/features/menu/view/widgets/profile/region_page.dart +++ b/lib/features/menu/view/widgets/profile/region_page.dart @@ -24,9 +24,7 @@ class RegionPage extends StatelessWidget { ); } if (state is SaveState) { - new Future.delayed(const Duration(milliseconds: 500), () { - Navigator.of(context).pop(true); - }); + Navigator.of(context).pop(true); } }, builder: (context, state) { diff --git a/lib/features/menu/view/widgets/profile/time_zone_screen_page.dart b/lib/features/menu/view/widgets/profile/time_zone_screen_page.dart index 6fd50b0..747d89f 100644 --- a/lib/features/menu/view/widgets/profile/time_zone_screen_page.dart +++ b/lib/features/menu/view/widgets/profile/time_zone_screen_page.dart @@ -17,7 +17,7 @@ class TimeZoneScreenPage extends StatelessWidget { return BlocProvider( create: (BuildContext context) => ProfileBloc()..add(TimeZoneInitialEvent()), child: - BlocConsumer(listener: (context, state) { + BlocConsumer(listener: (context, state) { if (state is FailedState) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( @@ -26,10 +26,8 @@ class TimeZoneScreenPage extends StatelessWidget { ), ); }if (state is SaveState) { - new Future.delayed(const Duration(milliseconds: 500), () { - Navigator.of(context).pop(true); - }); - } + Navigator.of(context).pop(true); + } }, builder: (context, state) { final profileBloc = BlocProvider.of(context); @@ -38,8 +36,8 @@ class TimeZoneScreenPage extends StatelessWidget { padding: const EdgeInsets.all(0), title: 'Time Zone', child: state is LoadingInitialState - ? const Center(child: CircularProgressIndicator()) - : Column( + ? const Center(child: CircularProgressIndicator()) + : Column( children: [ TextFormField( controller:profileBloc.searchController , From eebd0faf1ea7b294d4e4f782897846f987494653 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 28 Jul 2024 15:40:47 +0300 Subject: [PATCH 2/3] profile page fix bugs --- lib/features/menu/view/widgets/profile/profile_view.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/features/menu/view/widgets/profile/profile_view.dart b/lib/features/menu/view/widgets/profile/profile_view.dart index bac4502..7139ec1 100644 --- a/lib/features/menu/view/widgets/profile/profile_view.dart +++ b/lib/features/menu/view/widgets/profile/profile_view.dart @@ -17,7 +17,6 @@ class ProfileView extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocProvider( create: (BuildContext context) => ProfileBloc()..add(InitialProfileEvent()), child: BlocConsumer( @@ -137,9 +136,9 @@ class ProfileView extends StatelessWidget { height: 1, color: ColorsManager.greyColor, ), - InkWell( onTap: () { + profileBloc.add(const ChangeNameEvent(value: false)); Navigator.push( context, MaterialPageRoute( @@ -166,6 +165,7 @@ class ProfileView extends StatelessWidget { ), InkWell( onTap: () { + profileBloc.add(const ChangeNameEvent(value: false)); Navigator.push( context, MaterialPageRoute( From cd8cdf0853b7256509d13dd35f2b027bf5c559da Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 29 Jul 2024 12:28:12 +0300 Subject: [PATCH 3/3] profile page fix bugs --- lib/features/menu/bloc/profile_bloc/profile_bloc.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/features/menu/bloc/profile_bloc/profile_bloc.dart b/lib/features/menu/bloc/profile_bloc/profile_bloc.dart index cad8762..112b7c0 100644 --- a/lib/features/menu/bloc/profile_bloc/profile_bloc.dart +++ b/lib/features/menu/bloc/profile_bloc/profile_bloc.dart @@ -157,6 +157,7 @@ class ProfileBloc extends Bloc { void _fetchRegion(RegionInitialEvent event, Emitter emit) async { try { emit(LoadingInitialState()); + regionList = await ProfileApi.fetchRegion(); emit(RegionsLoadedState(regions: regionList!)); } catch (e) { @@ -249,7 +250,7 @@ class ProfileBloc extends Bloc { } final parts = withoutExtraSpaces.split(' '); if (parts.length < 2) return 'Full name must contain first and last names'; - if (parts.length > 2) return 'Full name can at most contain 3 parts'; + if (parts.length > 2) return 'Full name can at most contain 2 parts'; if (parts.any((part) => part.length < 2 || part.length > 30)) { return 'Full name parts must be between 2 and 30 characters long'; }