profile page fix bugs

This commit is contained in:
mohammad
2024-07-28 09:12:15 +03:00
parent b9432c3de3
commit 6c5acc3a08

View File

@ -15,7 +15,6 @@ import 'package:image_picker/image_picker.dart';
import 'package:permission_handler/permission_handler.dart';
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
bool isSaving = false;
bool editName = false;
final FocusNode focusNode = FocusNode();
@ -24,7 +23,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
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<TimeZone>? timeZoneList;
List<RegionModel>? regionList;
@ -45,7 +45,6 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
Future<void> saveName(SaveNameEvent event, Emitter<ProfileState> emit) async {
if (_validateInputs()) return;
try {
add(const ChangeNameEvent(value: false));
isSaving = true;
emit(LoadingInitialState());
@ -56,11 +55,10 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
var response = await ProfileApi.saveName(firstName: firstName, lastName: lastName);
add(InitialProfileEvent());
await HomeCubit.getInstance().fetchUserInfo();
// Navigator.of(event.context).pop(true);
CustomSnackBar.displaySnackBar('Save Successfully');
emit(SaveState());
} catch (_) {
// Handle the error
} catch (e) {
emit(FailedState(errorMessage: e.toString()));
} finally {
isSaving = false;
}
@ -133,8 +131,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
final filteredRegions = regionList?.where((region) {
return region.name.toLowerCase().contains(query);
}).toList() ?? [];
regionList = filteredRegions;// Assume this fetches the regions
regionList = filteredRegions;
emit(RegionsLoadedState(regions: filteredRegions));
}else{
regionList = await ProfileApi.fetchRegion();