From 123738e3339d529554fd39dba88188c0c34a0438 Mon Sep 17 00:00:00 2001 From: WaseemAbbasi22 <50428976+WaseemAbbasi22@users.noreply.github.com> Date: Wed, 25 Mar 2026 14:57:03 +0300 Subject: [PATCH] location and bottomsheet keyboard bug fixes --- .../dialoge/nfc_reader_sheet.dart | 125 ++++----- .../swipe_module/utils/location_utils.dart | 164 +++++++---- .../utils/swipe_general_utils.dart | 258 ++++++++++++------ .../update_user_contact_info_bottomsheet.dart | 161 ++++++----- 4 files changed, 421 insertions(+), 287 deletions(-) diff --git a/lib/new_views/swipe_module/dialoge/nfc_reader_sheet.dart b/lib/new_views/swipe_module/dialoge/nfc_reader_sheet.dart index ffab4991..c6e167c5 100644 --- a/lib/new_views/swipe_module/dialoge/nfc_reader_sheet.dart +++ b/lib/new_views/swipe_module/dialoge/nfc_reader_sheet.dart @@ -66,59 +66,59 @@ class _NfcLayoutState extends State { NfcManager.instance.startSession( onDiscovered: (NfcTag tag) async { - String? identifier; + String? identifier; - try { - if (Platform.isAndroid) { - // Try NfcA first (most common) - final nfcA = NfcAAndroid.from(tag); - if (nfcA != null) { - identifier = nfcA.tag.id.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } else { - // Fallback to NfcB - final nfcB = NfcBAndroid.from(tag); - if (nfcB != null) { - identifier = nfcB.tag.id.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + try { + if (Platform.isAndroid) { + // Try NfcA first (most common) + final nfcA = NfcAAndroid.from(tag); + if (nfcA != null) { + identifier = nfcA.tag.id.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + } else { + // Fallback to NfcB + final nfcB = NfcBAndroid.from(tag); + if (nfcB != null) { + identifier = nfcB.tag.id.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + } } - } - } else { - // For iOS, try MiFare first - final mifare = MiFareIos.from(tag); - if (mifare != null) { - identifier = mifare.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); } else { - // Fallback to Iso15693 for iOS - final iso15693 = Iso15693Ios.from(tag); - if (iso15693 != null) { - identifier = iso15693.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + // For iOS, try MiFare first + final mifare = MiFareIos.from(tag); + if (mifare != null) { + identifier = mifare.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + } else { + // Fallback to Iso15693 for iOS + final iso15693 = Iso15693Ios.from(tag); + if (iso15693 != null) { + identifier = iso15693.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + } } } + } catch (e) { + print('Error reading NFC tag: $e'); } - } catch (e) { - print('Error reading NFC tag: $e'); - } - nfcId = identifier; + nfcId = identifier; - if (!mounted) return; + if (!mounted) return; - setState(() { - _reading = true; - mainWidget = doneNfc(); - }); + setState(() { + _reading = true; + // mainWidget = doneNfc(); + }); - Future.delayed(const Duration(seconds: 1), () async { - try { - await NfcManager.instance.stopSession(); - } catch (e) { - print('Error stopping session: $e'); - } - if (mounted) { - Navigator.pop(context); - widget.onNcfScan!(nfcId!); - } - }); - }, + Future.delayed(const Duration(seconds: 1), () async { + try { + await NfcManager.instance.stopSession(); + } catch (e) { + print('Error stopping session: $e'); + } + if (mounted) { + Navigator.pop(context); + widget.onNcfScan!(nfcId!); + } + }); + }, pollingOptions: {NfcPollingOption.iso14443}, ).catchError((err) { print('NFC session error: $err'); @@ -138,22 +138,18 @@ class _NfcLayoutState extends State { Widget scanNfc() { return Container( color: AppColor.background(context), - key: ValueKey(1), + key: const ValueKey(1), child: Column( mainAxisSize: MainAxisSize.min, children: [ - SizedBox( + const SizedBox( height: 30, ), - Text( + Text( "Ready To Scan", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 24, - color:AppColor.headingTextColor(context) - ), + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24, color: AppColor.headingTextColor(context)), ), - SizedBox( + const SizedBox( height: 30, ), Image.asset( @@ -196,7 +192,7 @@ class _NfcLayoutState extends State { child: const Text("CANCEL"), ), ), - SizedBox( + const SizedBox( height: 30, ), ], @@ -211,18 +207,14 @@ class _NfcLayoutState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - SizedBox( + const SizedBox( height: 30, ), Text( "Successfully Scanned", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 24, - color:AppColor.headingTextColor(context) - ), + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24, color: AppColor.headingTextColor(context)), ), - SizedBox( + const SizedBox( height: 30, ), Image.asset( @@ -232,16 +224,16 @@ class _NfcLayoutState extends State { width: double.infinity, color: AppColor.iconColor(context), ), - SizedBox( + const SizedBox( height: 30, ), - Text( + const Text( "Approach an NFC Tag", style: TextStyle( fontSize: 18, ), ), - SizedBox( + const SizedBox( height: 30, ), ButtonTheme( @@ -259,10 +251,13 @@ class _NfcLayoutState extends State { // }, onPressed: null, // elevation: 0, - child: Text("DONE",style: TextStyle(color: context.isDark?AppColor.primary10:null),), + child: Text( + "DONE", + style: TextStyle(color: context.isDark ? AppColor.primary10 : null), + ), ), ), - SizedBox( + const SizedBox( height: 30, ), ], diff --git a/lib/new_views/swipe_module/utils/location_utils.dart b/lib/new_views/swipe_module/utils/location_utils.dart index b3627cc3..82650174 100644 --- a/lib/new_views/swipe_module/utils/location_utils.dart +++ b/lib/new_views/swipe_module/utils/location_utils.dart @@ -20,6 +20,21 @@ class LocationUtilities { Geolocator.isLocationServiceEnabled().then((value) => callback(value)); } + static Future isEnabledAsync() async { + return await Geolocator.isLocationServiceEnabled(); + } + + static Future havePermissionAsync() async { + LocationPermission permission = await Geolocator.checkPermission(); + + if (permission == LocationPermission.denied) { + permission = await Geolocator.requestPermission(); + } + + return permission == LocationPermission.always || + permission == LocationPermission.whileInUse; + } + static bool _listeningSettingChange = true; static void listenGPS({bool change = true, Function(bool)? onChange}) async { @@ -44,61 +59,100 @@ class LocationUtilities { completion(isGranted); }); } + static Future getCurrentLocation( + Function(Position position, bool isMocked) callback, + Function(String error) errorCallBack, + BuildContext context, + ) async { + debugPrint("📍 Fetching current location..."); - static void getCurrentLocation(Function(Position position, bool isMocked) callback, Function errorCallBack, BuildContext context) { - Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { - bool isMocked = position.isMocked; - callback(position, isMocked); - }).catchError((err) { - errorCallBack(); - }); - // return; - // Permission.location.isGranted.then((isGranted) { - // if (!isGranted) { - // Permission.location.request().then((granted) { - // print("granted:$granted"); - // if (granted == PermissionStatus.granted) { - // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { - // bool isMocked = position.isMocked; - // callback(position, isMocked); - // }).catchError((err) { - // print("getCurrentPositionError:$err"); - // errorCallBack(); - // }); - // } else { - // errorCallBack(); - // } - // }); - // } else { - // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { - // bool isMocked = position.isMocked; - // callback(position, isMocked); - // }).catchError((err) { - // print("getCurrentPositionError:$err"); - // errorCallBack(); - // }); - // } - // }); - // - // // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { - // // bool isMocked = position.isMocked; - // // callback(position, isMocked); - // // }).catchError((err) { - // // print("getCurrentPositionError:$err"); - // // errorCallBack(); - // // }); - // - // // locationFun((granted) { - // // if (granted) { - // // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((value) { - // // done(value); - // // }).catchError((err) { - // // print("getCurrentPositionError:$err"); - // // errorCallBack(); - // // }); - // // } else { - // // // AppPermissions - // // } - // // }, context); + try { + final position = await Geolocator.getCurrentPosition( + desiredAccuracy: LocationAccuracy.high, + timeLimit: const Duration(seconds: 10), + ); + debugPrint("✅ Location: ${position.latitude}, ${position.longitude}"); + + callback(position, position.isMocked); + } catch (e) { + debugPrint("❌ Primary location failed: $e"); + try { + final lastPosition = await Geolocator.getLastKnownPosition(); + if (lastPosition != null) { + debugPrint("⚠️ Using last known location"); + callback(lastPosition, lastPosition.isMocked); + return; + } + } catch (fallbackError) { + debugPrint("❌ Fallback failed: $fallbackError"); + } + String message = "Unable to determine your location"; + final error = e.toString().toLowerCase(); + if (error.contains("timeout")) { + message = "Location request timed out. Please try again."; + } else if (error.contains("denied")) { + message = "Location permission denied."; + } else if (error.contains("disabled")) { + message = "Location services are disabled."; + } + errorCallBack(message); + } } + + // static void getCurrentLocation(Function(Position position, bool isMocked) callback, Function errorCallBack, BuildContext context) { + // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { + // bool isMocked = position.isMocked; + // callback(position, isMocked); + // }).catchError((err) { + // errorCallBack(); + // }); + // // return; + // // Permission.location.isGranted.then((isGranted) { + // // if (!isGranted) { + // // Permission.location.request().then((granted) { + // // print("granted:$granted"); + // // if (granted == PermissionStatus.granted) { + // // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { + // // bool isMocked = position.isMocked; + // // callback(position, isMocked); + // // }).catchError((err) { + // // print("getCurrentPositionError:$err"); + // // errorCallBack(); + // // }); + // // } else { + // // errorCallBack(); + // // } + // // }); + // // } else { + // // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { + // // bool isMocked = position.isMocked; + // // callback(position, isMocked); + // // }).catchError((err) { + // // print("getCurrentPositionError:$err"); + // // errorCallBack(); + // // }); + // // } + // // }); + // // + // // // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { + // // // bool isMocked = position.isMocked; + // // // callback(position, isMocked); + // // // }).catchError((err) { + // // // print("getCurrentPositionError:$err"); + // // // errorCallBack(); + // // // }); + // // + // // // locationFun((granted) { + // // // if (granted) { + // // // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((value) { + // // // done(value); + // // // }).catchError((err) { + // // // print("getCurrentPositionError:$err"); + // // // errorCallBack(); + // // // }); + // // // } else { + // // // // AppPermissions + // // // } + // // // }, context); + // } } diff --git a/lib/new_views/swipe_module/utils/swipe_general_utils.dart b/lib/new_views/swipe_module/utils/swipe_general_utils.dart index 14bd3a40..fb66a0b7 100644 --- a/lib/new_views/swipe_module/utils/swipe_general_utils.dart +++ b/lib/new_views/swipe_module/utils/swipe_general_utils.dart @@ -40,7 +40,7 @@ class SwipeGeneralUtils { static bool get isLoading => _isLoadingVisible; - void markFakeAttendance(dynamic sourceName, String lat, String long, @required BuildContext context) async { + void markFakeAttendance(dynamic sourceName, String lat, String long, {required BuildContext context}) async { showLoading(context); try { hideLoading(navigatorKey.currentState!.overlay!.context); @@ -114,20 +114,33 @@ class SwipeGeneralUtils { } Widget attendanceTypeCard(String title, String icon, bool isEnabled, VoidCallback onPress, BuildContext context) { - return Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( - color: isEnabled ?context.isDark ? AppColor.neutral60 : Colors.white : AppColor.background(context), + color: isEnabled + ? context.isDark + ? AppColor.neutral60 + : Colors.white + : AppColor.background(context), borderRadius: BorderRadius.circular(18), - border: Border.all(color:context.isDark ? AppColor.neutral60 : Colors.white70 , width: 2), + border: Border.all(color: context.isDark ? AppColor.neutral60 : Colors.white70, width: 2), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - icon.toSvgAsset(color: isEnabled ?context.isDark ? AppColor.neutral30 : AppColor.neutral50 : Colors.grey.withOpacity(0.5)), - title.heading5(context).custom(color: isEnabled ?context.isDark ? AppColor.neutral30 : AppColor.neutral50 : Colors.grey.withOpacity(0.5)), + icon.toSvgAsset( + color: isEnabled + ? context.isDark + ? AppColor.neutral30 + : AppColor.neutral50 + : Colors.grey.withOpacity(0.5)), + title.heading5(context).custom( + color: isEnabled + ? context.isDark + ? AppColor.neutral30 + : AppColor.neutral50 + : Colors.grey.withOpacity(0.5)), ], ), ).onPress( @@ -336,50 +349,128 @@ class SwipeGeneralUtils { } } - void handleSwipe({required SwipeTypeEnum swipeType, required bool isEnable, required BuildContext context}) async { - if (Platform.isAndroid && !(await isGoogleServicesAvailable())) { - checkHuaweiLocationPermission(attendanceType: swipeType, context: context); - } else { - LocationUtilities.isEnabled((bool isEnabled) { - if (isEnabled) { - LocationUtilities.havePermission((bool permission) { - if (permission) { - showLoading(context); - LocationUtilities.getCurrentLocation( - (Position position, bool isMocked) { - if (isMocked) { - hideLoading(context); - markFakeAttendance(swipeType.name, position.latitude.toString() ?? "", position.longitude.toString() ?? "", context); - } else { - hideLoading(context); - handleSwipeOperation(swipeType: swipeType, lat: position.latitude, long: position.longitude, context: context); - } - }, - () { - hideLoading(context); - confirmDialog(context, "Unable to determine your location, Please make sure that your location services are turned on & working."); - }, - context, - ); - } else { - showInfoDialog( - message: "You need to give location permission to mark attendance", - onTap: () async { - await Geolocator.openAppSettings(); - }); - } - }); - } else { - showInfoDialog( - message: "You need to enable location services to mark attendance", - onTap: () async { - await Geolocator.openLocationSettings(); - }); - } - }); + Future handleSwipe({ + required SwipeTypeEnum swipeType, + required bool isEnable, + required BuildContext context, + }) async { + try { + if (Platform.isAndroid && !(await isGoogleServicesAvailable())) { + checkHuaweiLocationPermission( + attendanceType: swipeType, + context: context, + ); + return; + } + // Check if location is enabled + final isEnabled = await LocationUtilities.isEnabledAsync(); + if (!isEnabled) { + showInfoDialog( + message: "You need to enable location services to mark attendance", + onTap: () async => await Geolocator.openLocationSettings(), + ); + return; + } + + // Check permission + final hasPermission = await LocationUtilities.havePermissionAsync(); + if (!hasPermission) { + showInfoDialog( + message: "You need to give location permission to mark attendance", + onTap: () async => await Geolocator.openAppSettings(), + ); + return; + } + + // Show loader + showLoading(context); + + // Get location + await LocationUtilities.getCurrentLocation( + (Position position, bool isMocked) { + hideLoading(context); + + if (isMocked) { + markFakeAttendance( + swipeType.name, + position.latitude.toString(), + position.longitude.toString(), + context: context, + ); + } else { + handleSwipeOperation( + swipeType: swipeType, + lat: position.latitude, + long: position.longitude, + context: context, + ); + } + }, + (String error) { + hideLoading(context); + + confirmDialog( + context, + error.isNotEmpty ? error : "Unable to determine your location. Please try again.", + ); + }, + context, + ); + } catch (e) { + hideLoading(context); + confirmDialog( + context, + "Something went wrong. Please try again.", + ); + debugPrint("❌ handleSwipe error: $e"); } } +//older code.. + // void handleSwipe({required SwipeTypeEnum swipeType, required bool isEnable, required BuildContext context}) async { + // if (Platform.isAndroid && !(await isGoogleServicesAvailable())) { + // checkHuaweiLocationPermission(attendanceType: swipeType, context: context); + // } else { + // LocationUtilities.isEnabled((bool isEnabled) { + // if (isEnabled) { + // LocationUtilities.havePermission((bool permission) { + // if (permission) { + // showLoading(context); + // LocationUtilities.getCurrentLocation( + // (Position position, bool isMocked) { + // if (isMocked) { + // hideLoading(context); + // markFakeAttendance(swipeType.name, position.latitude.toString() ?? "", position.longitude.toString() ?? "", context); + // } else { + // hideLoading(context); + // handleSwipeOperation(swipeType: swipeType, lat: position.latitude, long: position.longitude, context: context); + // } + // }, + // () { + // hideLoading(context); + // confirmDialog(context, "Unable to determine your location, Please make sure that your location services are turned on & working."); + // }, + // context, + // ); + // } else { + // showInfoDialog( + // message: "You need to give location permission to mark attendance", + // onTap: () async { + // await Geolocator.openAppSettings(); + // }); + // } + // }); + // } else { + // showInfoDialog( + // message: "You need to enable location services to mark attendance", + // onTap: () async { + // await Geolocator.openLocationSettings(); + // }); + // } + // }); + // } + // } + void showInfoDialog({required String message, VoidCallback? onTap}) { showDialog( context: navigatorKey.currentState!.overlay!.context, @@ -434,16 +525,15 @@ class SwipeGeneralUtils { ), backgroundColor: Theme.of(context).scaffoldBackgroundColor, clipBehavior: Clip.antiAliasWithSaveLayer, - builder: (BuildContext context) =>Padding( + builder: (BuildContext context) => Padding( padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom + - MediaQuery.of(context).padding.bottom, + bottom: MediaQuery.of(context).viewInsets.bottom + MediaQuery.of(context).padding.bottom, ), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - context.translation.markAttendance.heading4(context).custom(color:context.isDark?AppColor.white50: AppColor.white936), + context.translation.markAttendance.heading4(context).custom(color: context.isDark ? AppColor.white50 : AppColor.white936), 8.height, context.translation.selectMethodToMarkAttendance.bodyText2(context).custom(color: AppColor.neutral120), 12.height, @@ -469,45 +559,45 @@ class SwipeGeneralUtils { NfcManager.instance.startSession( onDiscovered: (NfcTag tag) async { - String identifier = ''; - - try { - if (Platform.isAndroid) { - // Try NfcA first (most common) - final nfcA = NfcAAndroid.from(tag); - if (nfcA != null) { - identifier = nfcA.tag.id.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } else { - // Fallback to NfcB - final nfcB = NfcBAndroid.from(tag); - if (nfcB != null) { - identifier = nfcB.tag.id.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + String identifier = ''; + + try { + if (Platform.isAndroid) { + // Try NfcA first (most common) + final nfcA = NfcAAndroid.from(tag); + if (nfcA != null) { + identifier = nfcA.tag.id.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + } else { + // Fallback to NfcB + final nfcB = NfcBAndroid.from(tag); + if (nfcB != null) { + identifier = nfcB.tag.id.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + } } - } - } else { - // For iOS, try MiFare first - final mifare = MiFareIos.from(tag); - if (mifare != null) { - identifier = mifare.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); } else { - // Fallback to Iso15693 for iOS - final iso15693 = Iso15693Ios.from(tag); - if (iso15693 != null) { - identifier = iso15693.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + // For iOS, try MiFare first + final mifare = MiFareIos.from(tag); + if (mifare != null) { + identifier = mifare.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + } else { + // Fallback to Iso15693 for iOS + final iso15693 = Iso15693Ios.from(tag); + if (iso15693 != null) { + identifier = iso15693.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + } } } + } catch (e) { + print('Error reading NFC: $e'); } - } catch (e) { - print('Error reading NFC: $e'); - } - try { - await NfcManager.instance.stopSession(); - } catch (e) { - print('Error stopping NFC session: $e'); - } - onRead!(identifier); - }, + try { + await NfcManager.instance.stopSession(); + } catch (e) { + print('Error stopping NFC session: $e'); + } + onRead!(identifier); + }, pollingOptions: {NfcPollingOption.iso14443}, ).catchError((err) { print('NFC session error: $err'); diff --git a/lib/views/pages/user/update_user_contact_info_bottomsheet.dart b/lib/views/pages/user/update_user_contact_info_bottomsheet.dart index 1a15a0f7..e2be6855 100644 --- a/lib/views/pages/user/update_user_contact_info_bottomsheet.dart +++ b/lib/views/pages/user/update_user_contact_info_bottomsheet.dart @@ -44,90 +44,85 @@ class _UpdateUserContactInfoBottomSheetState extends State const AppLazyLoading()); - bool status = await context.userProvider.updateContactInfo(widget.userID, email, phoneNo, extensionNo); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + AppTextFormField( + labelText: "Email", + backgroundColor: AppColor.fieldBgColor(context), + initialValue: widget.uEmail, + textAlign: TextAlign.center, + hintText: "email@example.com", + labelStyle: AppTextStyles.textFieldLabelStyle, + hintStyle: AppTextStyles.textFieldLabelStyle, + textInputType: TextInputType.emailAddress, + showShadow: false, + onChange: (value) { + email = value; + }, + style: Theme.of(context).textTheme.titleMedium, + ), + 12.height, + AppTextFormField( + labelText: "Phone Number", + backgroundColor: AppColor.fieldBgColor(context), + initialValue: widget.uPhoneNo, + textAlign: TextAlign.center, + hintText: "05xxxxxxxx", + labelStyle: AppTextStyles.textFieldLabelStyle, + hintStyle: AppTextStyles.textFieldLabelStyle, + textInputType: TextInputType.phone, + showShadow: false, + onChange: (value) { + phoneNo = value; + }, + style: Theme.of(context).textTheme.titleMedium, + ), + 12.height, + AppTextFormField( + labelText: "Extension No", + backgroundColor: AppColor.fieldBgColor(context), + initialValue: widget.uExtensionNo, + textAlign: TextAlign.center, + hintText: "1234", + labelStyle: AppTextStyles.textFieldLabelStyle, + hintStyle: AppTextStyles.textFieldLabelStyle, + textInputType: const TextInputType.numberWithOptions(decimal: true), + showShadow: false, + onChange: (value) { + extensionNo = value; + }, + style: Theme.of(context).textTheme.titleMedium, + ), + 12.height, + AppFilledButton( + label: "Update", + buttonColor: context.isDark ? AppColor.primary10 : AppColor.neutral50, + onPressed: () async { + FocusManager.instance.primaryFocus!.unfocus(); + if (email.isEmpty || !Validator.isEmail(email)) { + "Please enter valid email".showToast; + return; + } + if (phoneNo.isEmpty || phoneNo.length != 10) { + "Please enter valid phone number".showToast; + return; + } + if (extensionNo.isEmpty) { + "Please enter extension".showToast; + return; + } + showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); + bool status = await context.userProvider.updateContactInfo(widget.userID, email, phoneNo, extensionNo); + Navigator.pop(context); + if (status) { Navigator.pop(context); - if (status) { - Navigator.pop(context); - widget.onUpdate(email, phoneNo, extensionNo); - } - }, - ), - ], - ), + widget.onUpdate(email, phoneNo, extensionNo); + } + }, + ), + ], ); } }