From e39526b5ebef81d61c70bf34cc9cc125c134b295 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 9 Aug 2023 11:41:48 +0300 Subject: [PATCH] Updates & fixes --- lib/app_state/app_state.dart | 2 +- lib/classes/notifications.dart | 5 +- lib/extensions/int_extensions.dart | 2 - lib/ui/login/login_screen.dart | 1 + lib/widgets/location/Location.dart | 9 -- lib/widgets/mark_attendance_widget.dart | 174 ++++++++++++++++-------- pubspec.yaml | 29 ++-- 7 files changed, 135 insertions(+), 87 deletions(-) diff --git a/lib/app_state/app_state.dart b/lib/app_state/app_state.dart index f59994c..b0c93ee 100644 --- a/lib/app_state/app_state.dart +++ b/lib/app_state/app_state.dart @@ -90,7 +90,7 @@ class AppState { String get getHuaweiPushToken => _huaweiPushToken; - final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 4.9, mobileType: Platform.isAndroid ? "android" : "ios"); + final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 5.0, mobileType: Platform.isAndroid ? "android" : "ios"); void setPostParamsInitConfig() { isAuthenticated = false; diff --git a/lib/classes/notifications.dart b/lib/classes/notifications.dart index 47d4acd..8f432d7 100644 --- a/lib/classes/notifications.dart +++ b/lib/classes/notifications.dart @@ -109,7 +109,10 @@ class AppNotifications { debugPrint("HUAWEI PUSH TOKEN: $_huaweiToken"); } - void _onTokenError(Object error) {} + void _onTokenError(Object error) { + debugPrint("HUAWEI PUSH TOKEN ERROR: $error"); + Utils.hideLoading(context); + } Future initTokenStream(Function loginCallback) async { huawei_push.Push.getTokenStream.listen(_onTokenEvent, onError: _onTokenError).onData((data) { diff --git a/lib/extensions/int_extensions.dart b/lib/extensions/int_extensions.dart index 16bdd29..f46d5bb 100644 --- a/lib/extensions/int_extensions.dart +++ b/lib/extensions/int_extensions.dart @@ -10,6 +10,4 @@ extension IntExtensions on int { Widget get divider => Divider(height: toDouble(), thickness: toDouble(), color: MyColors.lightGreyEFColor); Widget get makeItSquare => SizedBox(width: toDouble(), height: toDouble()); - - } diff --git a/lib/ui/login/login_screen.dart b/lib/ui/login/login_screen.dart index 3293e43..5d83fe9 100644 --- a/lib/ui/login/login_screen.dart +++ b/lib/ui/login/login_screen.dart @@ -103,6 +103,7 @@ class _LoginScreenState extends State { try { if (!(await Utils.isGoogleServicesAvailable())) { print("HUAWEI APPPP GALLERYYYY!!!!"); + AppNotifications().init(firebaseToken, context); AppState().setIsHuawei = true; AppNotifications().initHuaweiPush(checkLoginInfo); } else { diff --git a/lib/widgets/location/Location.dart b/lib/widgets/location/Location.dart index e324618..67d3cdd 100644 --- a/lib/widgets/location/Location.dart +++ b/lib/widgets/location/Location.dart @@ -47,15 +47,6 @@ class Location { Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((value) { done(value); }); - // Geolocator.getLastKnownPosition(forceAndroidLocationManager: true).then((value) { - // if (value == null) { - // Geolocator.getCurrentPosition().then((value) { - // done(value); - // }); - // } else { - // done(value); - // } - // }); } else { // AppPermissions } diff --git a/lib/widgets/mark_attendance_widget.dart b/lib/widgets/mark_attendance_widget.dart index dfb4357..982e316 100644 --- a/lib/widgets/mark_attendance_widget.dart +++ b/lib/widgets/mark_attendance_widget.dart @@ -1,13 +1,11 @@ +import 'dart:async'; import 'dart:io'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:geolocator/geolocator.dart'; -import 'package:huawei_location/location/fused_location_provider_client.dart'; -import 'package:huawei_location/location/location_request.dart'; -import 'package:huawei_location/location/location_settings_request.dart'; -import 'package:huawei_location/permission/permission_handler.dart'; +import 'package:huawei_location/huawei_location.dart'; import 'package:mohem_flutter_app/api/dashboard_api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; @@ -21,7 +19,7 @@ import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart'; import 'package:mohem_flutter_app/ui/dialogs/success_dialog.dart'; import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart'; import 'package:mohem_flutter_app/widgets/dialogs/dialogs.dart'; -import 'package:mohem_flutter_app/widgets/location/Location.dart'; +import 'package:mohem_flutter_app/widgets/location/Location.dart' as location; import 'package:mohem_flutter_app/widgets/nfc/nfc_reader_sheet.dart'; import 'package:mohem_flutter_app/widgets/qr_scanner_dialog.dart'; import 'package:nfc_manager/nfc_manager.dart'; @@ -75,26 +73,61 @@ class _MarkAttendanceWidgetState extends State { } void checkHuaweiLocationPermission(String attendanceType) async { - PermissionHandler permissionHandler = PermissionHandler(); - - if (await permissionHandler.hasLocationPermission()) { - getHuaweiCurrentLocation(attendanceType); - } else { - bool has = await requestPermissions(); - if (has) { - getHuaweiCurrentLocation(attendanceType); + // Permission_Handler permissionHandler = PermissionHandler(); + location.Location.isEnabled((bool isEnabled) async { + if (isEnabled) { + location.Location.havePermission((bool permission) async { + if (permission) { + getHuaweiCurrentLocation(attendanceType); + } else { + bool has = await requestPermissions(); + if (has) { + getHuaweiCurrentLocation(attendanceType); + } else { + showDialog( + context: context, + builder: (BuildContext cxt) => ConfirmDialog( + message: "You need to give location permission to mark attendance", + onTap: () { + Navigator.pop(context); + }, + ), + ); + } + } + }); } else { showDialog( context: context, builder: (BuildContext cxt) => ConfirmDialog( - message: "You need to give location permission to mark attendance", - onTap: () { + message: "You need to enable location services to mark attendance", + onTap: () async { Navigator.pop(context); + await Geolocator.openLocationSettings(); }, ), ); } - } + }); + + // if (await permissionHandler.hasLocationPermission()) { + // getHuaweiCurrentLocation(attendanceType); + // } else { + // bool has = await requestPermissions(); + // if (has) { + // getHuaweiCurrentLocation(attendanceType); + // } else { + // showDialog( + // context: context, + // builder: (BuildContext cxt) => ConfirmDialog( + // message: "You need to give location permission to mark attendance", + // onTap: () { + // Navigator.pop(context); + // }, + // ), + // ); + // } + // } } Future requestPermissions() async { @@ -134,11 +167,11 @@ class _MarkAttendanceWidgetState extends State { if (AppState().getIsHuawei) { checkHuaweiLocationPermission("NFC"); } else { - Location.isEnabled((bool isEnabled) { + location.Location.isEnabled((bool isEnabled) { if (isEnabled) { - Location.havePermission((bool permission) { + location.Location.havePermission((bool permission) { if (permission) { - Location.getCurrentLocation( + location.Location.getCurrentLocation( (Position position, bool isMocked) { if (isMocked) { markFakeAttendance("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); @@ -181,11 +214,11 @@ class _MarkAttendanceWidgetState extends State { if (AppState().getIsHuawei) { checkHuaweiLocationPermission("WIFI"); } else { - Location.isEnabled((bool isEnabled) { + location.Location.isEnabled((bool isEnabled) { if (isEnabled) { - Location.havePermission((bool permission) { + location.Location.havePermission((bool permission) { if (permission) { - Location.getCurrentLocation( + location.Location.getCurrentLocation( (Position position, bool isMocked) { if (isMocked) { markFakeAttendance("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); @@ -228,11 +261,11 @@ class _MarkAttendanceWidgetState extends State { if (AppState().getIsHuawei) { checkHuaweiLocationPermission("QR"); } else { - Location.isEnabled((bool isEnabled) { + location.Location.isEnabled((bool isEnabled) { if (isEnabled) { - Location.havePermission((bool permission) { + location.Location.havePermission((bool permission) { if (permission) { - Location.getCurrentLocation( + location.Location.getCurrentLocation( (Position position, bool isMocked) { if (isMocked) { markFakeAttendance("QR", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); @@ -277,49 +310,70 @@ class _MarkAttendanceWidgetState extends State { ); } - void getHuaweiCurrentLocation(String attendanceType) { + void getHuaweiCurrentLocation(String attendanceType) async { try { + Utils.showLoading(context); FusedLocationProviderClient locationService = FusedLocationProviderClient(); LocationRequest locationRequest = LocationRequest(); locationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; - locationRequest.interval = 1000; + locationRequest.interval = 500; List locationRequestList = [locationRequest]; LocationSettingsRequest locationSettingsRequest = LocationSettingsRequest(requests: locationRequestList); - locationService.checkLocationSettings(locationSettingsRequest).then((settings) async { - await locationService.getLastLocation().then((value) { - if (value.latitude == null || value.longitude == null) { - showDialog( - context: context, - builder: (BuildContext cxt) => ConfirmDialog( - message: "Unable to get your location, Please check your location settings & try again.", - onTap: () { - Navigator.pop(context); - }, - ), - ); - } else { - if (attendanceType == "QR") { - performQrCodeAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? ""); - } - if (attendanceType == "WIFI") { - performWifiAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? ""); - } - if (attendanceType == "NFC") { - performNfcAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? ""); - } + late StreamSubscription _streamSubscription; + int requestCode = (await (locationService.requestLocationUpdates(locationRequest)))!; + + _streamSubscription = locationService.onLocationData!.listen( + (Location location) async { + Utils.hideLoading(context); + await locationService.removeLocationUpdates(requestCode); + if (attendanceType == "QR") { + performQrCodeAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? ""); } - }).catchError((error) { - print("HUAWEI LOCATION getLastLocation ERROR!!!!!"); - print(error); - }); - }).catchError((error) { - print("HUAWEI LOCATION checkLocationSettings ERROR!!!!!"); - print(error); - if (error.code == "LOCATION_SETTINGS_NOT_AVAILABLE") { - // Location service not enabled. - } - }); + if (attendanceType == "WIFI") { + performWifiAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? ""); + } + if (attendanceType == "NFC") { + performNfcAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? ""); + } + requestCode = 0; + }, + ); + + // locationService.checkLocationSettings(locationSettingsRequest).then((settings) async { + // await locationService.getLastLocation().then((value) { + // if (value.latitude == null || value.longitude == null) { + // showDialog( + // context: context, + // builder: (BuildContext cxt) => ConfirmDialog( + // message: "Unable to get your location, Please check your location settings & try again.", + // onTap: () { + // Navigator.pop(context); + // }, + // ), + // ); + // } else { + // if (attendanceType == "QR") { + // performQrCodeAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? ""); + // } + // if (attendanceType == "WIFI") { + // performWifiAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? ""); + // } + // if (attendanceType == "NFC") { + // performNfcAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? ""); + // } + // } + // }).catchError((error) { + // print("HUAWEI LOCATION getLastLocation ERROR!!!!!"); + // print(error); + // }); + // }).catchError((error) { + // print("HUAWEI LOCATION checkLocationSettings ERROR!!!!!"); + // print(error); + // if (error.code == "LOCATION_SETTINGS_NOT_AVAILABLE") { + // // Location service not enabled. + // } + // }); } catch (error) { print("HUAWEI LOCATION ERROR!!!!!"); print(error); diff --git a/pubspec.yaml b/pubspec.yaml index bc70be9..d154f9f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 3.2.93+300032 +version: 3.2.991+300039 environment: sdk: ">=2.16.0 <3.0.0" @@ -46,7 +46,7 @@ dependencies: local_auth: ^1.1.9 fluttertoast: ^8.0.8 syncfusion_flutter_calendar: ^19.4.48 -# flutter_calendar_carousel: ^2.1.0 + # flutter_calendar_carousel: ^2.1.0 pie_chart: ^5.1.0 shared_preferences: ^2.0.12 firebase_messaging: ^13.0.4 @@ -54,9 +54,9 @@ dependencies: logger: ^1.1.0 flutter_countdown_timer: ^4.1.0 nfc_manager: ^3.2.0 -# uuid: ^3.0.6 -# device_info_plus: ^4.0.0 -# android_id: ^0.1.3+1 + # uuid: ^3.0.6 + # device_info_plus: ^4.0.0 + # android_id: ^0.1.3+1 platform_device_id: ^1.0.1 image_picker: ^0.8.5+3 file_picker: ^4.6.1 @@ -66,21 +66,21 @@ dependencies: open_file: ^3.2.1 wifi_iot: ^0.3.18 flutter_html: ^3.0.0-alpha.6 -# flutter_barcode_scanner: ^2.0.0 + # flutter_barcode_scanner: ^2.0.0 qr_code_scanner: ^1.0.1 -# qr_flutter: ^4.0.0 + # qr_flutter: ^4.0.0 url_launcher: ^6.0.15 share: 2.0.4 flutter_rating_bar: ^4.0.1 auto_size_text: ^3.0.0 pull_to_refresh: ^2.0.0 -# lottie json animations + # lottie json animations lottie: any -# Marathon Card Swipe + # Marathon Card Swipe appinio_swiper: ^1.1.1 expandable: ^5.0.1 -# networkImage + # networkImage cached_network_image: ^3.2.2 #Chat @@ -101,12 +101,13 @@ dependencies: video_player: ^2.5.1 just_audio: ^0.9.30 -# safe_device: ^1.1.2 + # safe_device: ^1.1.2 flutter_layout_grid: ^2.0.1 #Huawei Dependencies -# huawei_hmsavailability: ^6.6.0+300 - huawei_location: 6.0.0+302 + # huawei_hmsavailability: ^6.6.0+300 +# huawei_location: 6.0.0+302 + huawei_location: ^6.11.0+301 huawei_push: ^6.7.0+300 firebase_crashlytics: ^2.9.0 @@ -114,7 +115,7 @@ dependencies: carousel_slider: ^4.2.1 #Huawei Specified -# store_checker: ^1.1.0 + # store_checker: ^1.1.0 google_api_availability: ^3.0.1