location and bottomsheet keyboard bug fixes

main_production_upgrade_ios
WaseemAbbasi22 11 hours ago
parent 445e7cf091
commit 123738e333

@ -104,7 +104,7 @@ class _NfcLayoutState extends State<NfcLayout> {
setState(() { setState(() {
_reading = true; _reading = true;
mainWidget = doneNfc(); // mainWidget = doneNfc();
}); });
Future.delayed(const Duration(seconds: 1), () async { Future.delayed(const Duration(seconds: 1), () async {
@ -138,22 +138,18 @@ class _NfcLayoutState extends State<NfcLayout> {
Widget scanNfc() { Widget scanNfc() {
return Container( return Container(
color: AppColor.background(context), color: AppColor.background(context),
key: ValueKey(1), key: const ValueKey(1),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
SizedBox( const SizedBox(
height: 30, height: 30,
), ),
Text( Text(
"Ready To Scan", "Ready To Scan",
style: TextStyle( style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24, color: AppColor.headingTextColor(context)),
fontWeight: FontWeight.bold,
fontSize: 24,
color:AppColor.headingTextColor(context)
), ),
), const SizedBox(
SizedBox(
height: 30, height: 30,
), ),
Image.asset( Image.asset(
@ -196,7 +192,7 @@ class _NfcLayoutState extends State<NfcLayout> {
child: const Text("CANCEL"), child: const Text("CANCEL"),
), ),
), ),
SizedBox( const SizedBox(
height: 30, height: 30,
), ),
], ],
@ -211,18 +207,14 @@ class _NfcLayoutState extends State<NfcLayout> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
SizedBox( const SizedBox(
height: 30, height: 30,
), ),
Text( Text(
"Successfully Scanned", "Successfully Scanned",
style: TextStyle( style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24, color: AppColor.headingTextColor(context)),
fontWeight: FontWeight.bold,
fontSize: 24,
color:AppColor.headingTextColor(context)
),
), ),
SizedBox( const SizedBox(
height: 30, height: 30,
), ),
Image.asset( Image.asset(
@ -232,16 +224,16 @@ class _NfcLayoutState extends State<NfcLayout> {
width: double.infinity, width: double.infinity,
color: AppColor.iconColor(context), color: AppColor.iconColor(context),
), ),
SizedBox( const SizedBox(
height: 30, height: 30,
), ),
Text( const Text(
"Approach an NFC Tag", "Approach an NFC Tag",
style: TextStyle( style: TextStyle(
fontSize: 18, fontSize: 18,
), ),
), ),
SizedBox( const SizedBox(
height: 30, height: 30,
), ),
ButtonTheme( ButtonTheme(
@ -259,10 +251,13 @@ class _NfcLayoutState extends State<NfcLayout> {
// }, // },
onPressed: null, onPressed: null,
// elevation: 0, // 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, height: 30,
), ),
], ],

@ -20,6 +20,21 @@ class LocationUtilities {
Geolocator.isLocationServiceEnabled().then((value) => callback(value)); Geolocator.isLocationServiceEnabled().then((value) => callback(value));
} }
static Future<bool> isEnabledAsync() async {
return await Geolocator.isLocationServiceEnabled();
}
static Future<bool> 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 bool _listeningSettingChange = true;
static void listenGPS({bool change = true, Function(bool)? onChange}) async { static void listenGPS({bool change = true, Function(bool)? onChange}) async {
@ -44,42 +59,59 @@ class LocationUtilities {
completion(isGranted); completion(isGranted);
}); });
} }
static Future<void> 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) { try {
Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { final position = await Geolocator.getCurrentPosition(
bool isMocked = position.isMocked; desiredAccuracy: LocationAccuracy.high,
callback(position, isMocked); timeLimit: const Duration(seconds: 10),
}).catchError((err) { );
errorCallBack(); debugPrint("✅ Location: ${position.latitude}, ${position.longitude}");
});
// return; callback(position, position.isMocked);
// Permission.location.isGranted.then((isGranted) { } catch (e) {
// if (!isGranted) { debugPrint("❌ Primary location failed: $e");
// Permission.location.request().then((granted) { try {
// print("granted:$granted"); final lastPosition = await Geolocator.getLastKnownPosition();
// if (granted == PermissionStatus.granted) { if (lastPosition != null) {
// Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) { debugPrint("⚠️ Using last known location");
// bool isMocked = position.isMocked; callback(lastPosition, lastPosition.isMocked);
// callback(position, isMocked); return;
// }).catchError((err) { }
// print("getCurrentPositionError:$err"); } catch (fallbackError) {
// errorCallBack(); debugPrint("❌ Fallback failed: $fallbackError");
// }); }
// } else { String message = "Unable to determine your location";
// errorCallBack(); final error = e.toString().toLowerCase();
// } if (error.contains("timeout")) {
// }); message = "Location request timed out. Please try again.";
// } else { } 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) { // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) {
// bool isMocked = position.isMocked; // bool isMocked = position.isMocked;
// callback(position, isMocked); // callback(position, isMocked);
// }).catchError((err) { // }).catchError((err) {
// print("getCurrentPositionError:$err");
// errorCallBack(); // 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) { // // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) {
// // bool isMocked = position.isMocked; // // bool isMocked = position.isMocked;
// // callback(position, isMocked); // // callback(position, isMocked);
@ -87,18 +119,40 @@ class LocationUtilities {
// // print("getCurrentPositionError:$err"); // // print("getCurrentPositionError:$err");
// // errorCallBack(); // // errorCallBack();
// // }); // // });
// // // } else {
// // locationFun((granted) { // // errorCallBack();
// // if (granted) { // // }
// // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((value) { // // });
// // done(value); // // } else {
// // Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((position) {
// // bool isMocked = position.isMocked;
// // callback(position, isMocked);
// // }).catchError((err) { // // }).catchError((err) {
// // print("getCurrentPositionError:$err"); // // print("getCurrentPositionError:$err");
// // errorCallBack(); // // errorCallBack();
// // }); // // });
// // } else {
// // // AppPermissions
// // } // // }
// // }, context); // // });
} // //
// // // 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);
// }
} }

@ -40,7 +40,7 @@ class SwipeGeneralUtils {
static bool get isLoading => _isLoadingVisible; 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); showLoading(context);
try { try {
hideLoading(navigatorKey.currentState!.overlay!.context); hideLoading(navigatorKey.currentState!.overlay!.context);
@ -114,11 +114,14 @@ class SwipeGeneralUtils {
} }
Widget attendanceTypeCard(String title, String icon, bool isEnabled, VoidCallback onPress, BuildContext context) { Widget attendanceTypeCard(String title, String icon, bool isEnabled, VoidCallback onPress, BuildContext context) {
return Container( return Container(
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),
decoration: BoxDecoration( 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), 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),
), ),
@ -126,8 +129,18 @@ class SwipeGeneralUtils {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
icon.toSvgAsset(color: isEnabled ?context.isDark ? AppColor.neutral30 : AppColor.neutral50 : Colors.grey.withOpacity(0.5)), icon.toSvgAsset(
title.heading5(context).custom(color: isEnabled ?context.isDark ? AppColor.neutral30 : AppColor.neutral50 : Colors.grey.withOpacity(0.5)), 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( ).onPress(
@ -336,50 +349,128 @@ class SwipeGeneralUtils {
} }
} }
void handleSwipe({required SwipeTypeEnum swipeType, required bool isEnable, required BuildContext context}) async { Future<void> handleSwipe({
required SwipeTypeEnum swipeType,
required bool isEnable,
required BuildContext context,
}) async {
try {
if (Platform.isAndroid && !(await isGoogleServicesAvailable())) { if (Platform.isAndroid && !(await isGoogleServicesAvailable())) {
checkHuaweiLocationPermission(attendanceType: swipeType, context: context); checkHuaweiLocationPermission(
} else { attendanceType: swipeType,
LocationUtilities.isEnabled((bool isEnabled) { context: context,
if (isEnabled) { );
LocationUtilities.havePermission((bool permission) { return;
if (permission) { }
// 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); showLoading(context);
LocationUtilities.getCurrentLocation(
// Get location
await LocationUtilities.getCurrentLocation(
(Position position, bool isMocked) { (Position position, bool isMocked) {
if (isMocked) {
hideLoading(context); hideLoading(context);
markFakeAttendance(swipeType.name, position.latitude.toString() ?? "", position.longitude.toString() ?? "", context);
if (isMocked) {
markFakeAttendance(
swipeType.name,
position.latitude.toString(),
position.longitude.toString(),
context: context,
);
} else { } else {
hideLoading(context); handleSwipeOperation(
handleSwipeOperation(swipeType: swipeType, lat: position.latitude, long: position.longitude, context: context); swipeType: swipeType,
lat: position.latitude,
long: position.longitude,
context: context,
);
} }
}, },
() { (String error) {
hideLoading(context); hideLoading(context);
confirmDialog(context, "Unable to determine your location, Please make sure that your location services are turned on & working.");
confirmDialog(
context,
error.isNotEmpty ? error : "Unable to determine your location. Please try again.",
);
}, },
context, context,
); );
} else { } catch (e) {
showInfoDialog( hideLoading(context);
message: "You need to give location permission to mark attendance", confirmDialog(
onTap: () async { context,
await Geolocator.openAppSettings(); "Something went wrong. Please try again.",
}); );
} debugPrint("❌ handleSwipe error: $e");
});
} else {
showInfoDialog(
message: "You need to enable location services to mark attendance",
onTap: () async {
await Geolocator.openLocationSettings();
});
}
});
} }
} }
//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}) { void showInfoDialog({required String message, VoidCallback? onTap}) {
showDialog( showDialog(
context: navigatorKey.currentState!.overlay!.context, context: navigatorKey.currentState!.overlay!.context,
@ -436,8 +527,7 @@ class SwipeGeneralUtils {
clipBehavior: Clip.antiAliasWithSaveLayer, clipBehavior: Clip.antiAliasWithSaveLayer,
builder: (BuildContext context) => Padding( builder: (BuildContext context) => Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom + bottom: MediaQuery.of(context).viewInsets.bottom + MediaQuery.of(context).padding.bottom,
MediaQuery.of(context).padding.bottom,
), ),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,

@ -44,11 +44,7 @@ class _UpdateUserContactInfoBottomSheetState extends State<UpdateUserContactInfo
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Column(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom + MediaQuery.of(context).padding.bottom,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@ -127,7 +123,6 @@ class _UpdateUserContactInfoBottomSheetState extends State<UpdateUserContactInfo
}, },
), ),
], ],
),
); );
} }
} }

Loading…
Cancel
Save