diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 928e324..8512568 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -2,7 +2,6 @@ package="com.example.rogapp"> - isSelected = [true].obs; BuildContext? context; + List gps = ["-- stating --"].obs; + List locationPermission = [" -- starting -- "].obs; + + Map matrix = {}; final IndexController indexController = Get.find(); @@ -63,58 +67,63 @@ class DestinationController extends GetxController { checkForCheckin(double la, double ln){ for(final d in destinations){ - double lat = d.lat!; - double lon = d.lon!; - LatLng p = LatLng(lat, lon); - getDEstinationForLatLong(lat, lon).then((value){ - var distance = Distance(); - double dist = distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln)); - double rad = value!.checkin_radious ?? double.infinity; - bool auto_checkin = value.auto_checkin == 0 ? false : true; - indexController.currentDestinationFeature.add(value); - //indexController.getAction(); + if(!checking_in) + { + checking_in = true; + double lat = d.lat!; + double lon = d.lon!; + LatLng p = LatLng(lat, lon); + getDEstinationForLatLong(lat, lon).then((value){ + var distance = Distance(); + double dist = distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln)); + double rad = value!.checkin_radious ?? double.infinity; + bool auto_checkin = value.auto_checkin == 0 ? false : true; + + indexController.currentDestinationFeature.add(value); + //indexController.getAction(); - if(rad >= dist){ - if(auto_checkin){ - makeCheckin(value, true); + if(rad >= dist){ + if(auto_checkin){ + makeCheckin(value, true); + } + else{ + showModalBottomSheet(context: Get.context!, isScrollControlled: true, + builder:((context) => BottomSheetWidget()) + ).whenComplete((){ + checking_in = false; + }); + } } - else{ - showModalBottomSheet(context: Get.context!, isScrollControlled: true, - builder:((context) => BottomSheetWidget()) - ).whenComplete((){ - checking_in = false; - }); - } - } - + - // if(!checking_in){ - // checking_in = true; - // if(rad >= dist){ - // if(auto_checkin){ - // if(indexController.currentAction.isNotEmpty){ - // print(indexController.currentAction[0]); - // indexController.currentAction[0][0]["checkin"] = true; - // Map temp = Map.from(indexController.currentAction[0][0]); - // indexController.currentAction.clear(); - // print("---temp---${temp}"); - // indexController.currentAction.add([temp]); - // } - // indexController.makeAction(Get.context!); - // } - // else{ - // showModalBottomSheet(context: Get.context!, isScrollControlled: true, - // builder:((context) => BottomSheetWidget()) - // ).whenComplete((){ - // checking_in = false; - // }); - // } - // } - // } - print("----- rad is ${rad}"); - }); + // if(!checking_in){ + // checking_in = true; + // if(rad >= dist){ + // if(auto_checkin){ + // if(indexController.currentAction.isNotEmpty){ + // print(indexController.currentAction[0]); + // indexController.currentAction[0][0]["checkin"] = true; + // Map temp = Map.from(indexController.currentAction[0][0]); + // indexController.currentAction.clear(); + // print("---temp---${temp}"); + // indexController.currentAction.add([temp]); + // } + // indexController.makeAction(Get.context!); + // } + // else{ + // showModalBottomSheet(context: Get.context!, isScrollControlled: true, + // builder:((context) => BottomSheetWidget()) + // ).whenComplete((){ + // checking_in = false; + // }); + // } + // } + // } + }); + + } } } @@ -137,7 +146,7 @@ class DestinationController extends GetxController { @override void onInit() async { super.onInit(); - checkPermission(); + checkPermission(); PopulateDestinations(); @@ -147,7 +156,7 @@ class DestinationController extends GetxController { if (defaultTargetPlatform == TargetPlatform.android) { locationSettings = AndroidSettings( - accuracy: LocationAccuracy.high, + accuracy: LocationAccuracy.bestForNavigation, distanceFilter: 00, forceLocationManager: true, intervalDuration: const Duration(seconds: 1), @@ -162,7 +171,7 @@ class DestinationController extends GetxController { ); } else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) { locationSettings = AppleSettings( - accuracy: LocationAccuracy.high, + accuracy: LocationAccuracy.bestForNavigation, activityType: ActivityType.fitness, distanceFilter: 1, pauseLocationUpdatesAutomatically: false, @@ -176,22 +185,30 @@ class DestinationController extends GetxController { ); } + try { - StreamSubscription positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen( + StreamSubscription positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen( + + (Position? position) { + if(isSelected[0]){ + double czoom = indexController.rogMapController!.zoom; + indexController.rogMapController!.move(LatLng(position!.latitude, position!.longitude), czoom); + //String user_id = indexController.currentUser[0]["user"]["id"].toString(); + //TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){ + print("---- postion is ${position.latitude}, ${position.longitude}"); + gps.clear(); + gps.add("-- lat : ${position.latitude}, lon : ${position.longitude} --"); + checkForCheckin(position!.latitude, position.longitude); + //}); + + } + print(position == null ? 'Unknown' : 'current position is ${position.latitude.toString()}, ${position.longitude.toString()}'); + }); + } catch (err){ + locationPermission.clear(); + locationPermission.add(err.toString()); + } - (Position? position) { - if(isSelected[0]){ - double czoom = indexController.rogMapController!.zoom; - indexController.rogMapController!.move(LatLng(position!.latitude, position!.longitude), czoom); - //String user_id = indexController.currentUser[0]["user"]["id"].toString(); - //TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){ - print("---- postion is ${position.latitude}, ${position.longitude}"); - checkForCheckin(position!.latitude, position.longitude); - //}); - - } - print(position == null ? 'Unknown' : 'current position is ${position.latitude.toString()}, ${position.longitude.toString()}'); - }); } @@ -199,6 +216,8 @@ class DestinationController extends GetxController { LocationPermission permission = await Geolocator.checkPermission(); if (permission != LocationPermission.whileInUse || permission != LocationPermission.always) { + locationPermission.clear(); + locationPermission.add(permission.name); permission = await Geolocator.requestPermission(); } } diff --git a/lib/pages/destination_map/destination_map_page.dart b/lib/pages/destination_map/destination_map_page.dart index b7d0002..8a1864e 100644 --- a/lib/pages/destination_map/destination_map_page.dart +++ b/lib/pages/destination_map/destination_map_page.dart @@ -140,7 +140,20 @@ class _DestinationMapPageState extends State { //child: TravelMap(), child: TravelMap(), - ) + ), + Positioned( + bottom: 200, + left: 10, + child: Container( + color: Colors.white, + child: Row( + children: [ + Text(destinationController.gps[0]), + Text(destinationController.locationPermission[0]) + ], + ), + ) + ), ], ) )); diff --git a/lib/pages/permission/permission.dart b/lib/pages/permission/permission.dart new file mode 100644 index 0000000..c4b2890 --- /dev/null +++ b/lib/pages/permission/permission.dart @@ -0,0 +1,79 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:permission_handler/permission_handler.dart'; +import 'package:rogapp/routes/app_pages.dart'; + +class PermissionHandlerScreen extends StatefulWidget { + PermissionHandlerScreen({Key? key}) : super(key: key); + + @override + State createState() => _PermissionHandlerScreenState(); +} + +class _PermissionHandlerScreenState extends State { + + @override + void initState() { + // TODO: implement initState + super.initState(); + permissionServiceCall(); + } + + permissionServiceCall() async { + await permissionServices().then( + (value) { + if (value != null) { + if (value[Permission.location]!.isGranted ) { + /* ========= New Screen Added ============= */ + + Get.toNamed(AppPages.TRAVEL); + + // Navigator.pushReplacement( + // context, + // MaterialPageRoute(builder: (context) => SplashScreen()), + // ); + } + } + }, + ); + } + + + /*Permission services*/ + Future> permissionServices() async { + // You can request multiple permissions at once. + Map statuses = await [ + Permission.location, + + //add more permission to request here. + ].request(); + + if (statuses[Permission.location]!.isPermanentlyDenied) { + await openAppSettings().then( + (value) async { + if (value) { + if (await Permission.location.status.isPermanentlyDenied == true && + await Permission.location.status.isGranted == false) { + // openAppSettings(); + permissionServiceCall(); /* opens app settings until permission is granted */ + } + } + }, + ); + } else { + if (statuses[Permission.location]!.isDenied) { + permissionServiceCall(); + } + } + + /*{Permission.camera: PermissionStatus.granted, Permission.storage: PermissionStatus.granted}*/ + return statuses; + } + + + + @override + Widget build(BuildContext context) { + return Container(); + } +} \ No newline at end of file diff --git a/lib/routes/app_pages.dart b/lib/routes/app_pages.dart index 304b115..16b3828 100644 --- a/lib/routes/app_pages.dart +++ b/lib/routes/app_pages.dart @@ -10,6 +10,7 @@ import 'package:rogapp/pages/index/index_page.dart'; import 'package:rogapp/pages/landing/landing_page.dart'; import 'package:rogapp/pages/loading/loading_page.dart'; import 'package:rogapp/pages/login/login_page.dart'; +import 'package:rogapp/pages/permission/permission.dart'; import 'package:rogapp/pages/register/register_page.dart'; import 'package:rogapp/spa/spa_binding.dart'; import 'package:rogapp/spa/spa_page.dart'; @@ -30,6 +31,7 @@ class AppPages { static const LOADING = Routes.LOADING; static const DESTINATION_MAP = Routes.DESTINATION_MAP; static const HOME = Routes.HOME; + static const PERMISSION = Routes.PERMISSION; static final routes = [ // GetPage( @@ -87,5 +89,9 @@ class AppPages { page: () => HomePage(), binding: HomeBinding(), ), + GetPage( + name: Routes.PERMISSION, + page: () => PermissionHandlerScreen(), + ) ]; } \ No newline at end of file diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index 965b042..232930f 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -15,4 +15,5 @@ abstract class Routes { static const LOADING = '/loading'; static const DESTINATION_MAP = '/destination_map'; static const HOME = '/home'; + static const PERMISSION = '/permission'; } diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index 8835a64..3300bb1 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -239,31 +239,31 @@ class BottomSheetNew extends GetView { ], ), Obx(() => - (indexController.currentFeature[0].properties!["address"] as String).isNotEmpty ? + indexController.currentFeature[0].properties!["address"] != null && (indexController.currentFeature[0].properties!["address"] as String).isNotEmpty ? getDetails(context, "address".tr, indexController.currentFeature[0].properties!["address"] ?? '') : Container(width: 0.0, height: 0,), ), Obx(() => - (indexController.currentFeature[0].properties!["phone"] as String).isNotEmpty ? + indexController.currentFeature[0].properties!["phone"] != null && (indexController.currentFeature[0].properties!["phone"] as String).isNotEmpty ? getDetails(context, "telephone".tr, indexController.currentFeature[0].properties!["phone"] ?? '') : Container(width: 0.0, height: 0,), ), Obx(() => - (indexController.currentFeature[0].properties!["email"] as String).isNotEmpty ? + indexController.currentFeature[0].properties!["email"] != null && (indexController.currentFeature[0].properties!["email"] as String).isNotEmpty ? getDetails(context, "email".tr, indexController.currentFeature[0].properties!["email"] ?? '') : Container(width: 0.0, height: 0,), ), Obx(() => - (indexController.currentFeature[0].properties!["webcontents"] as String).isNotEmpty ? + indexController.currentFeature[0].properties!["webcontents"] != null && (indexController.currentFeature[0].properties!["webcontents"] as String).isNotEmpty ? getDetails(context, "web".tr, indexController.currentFeature[0].properties!["webcontents"] ?? '', isurl: true) : Container(width: 0.0, height: 0,), ), Obx(() => - (indexController.currentFeature[0].properties!["videos"] as String).isNotEmpty ? + indexController.currentFeature[0].properties!["videos"] !=null && (indexController.currentFeature[0].properties!["videos"] as String).isNotEmpty ? getDetails(context, "video".tr, indexController.currentFeature[0].properties!["videos"] ?? '', isurl: true) : Container(width: 0.0, height: 0,), diff --git a/lib/widgets/list_widget.dart b/lib/widgets/list_widget.dart index c88ff17..1451f52 100644 --- a/lib/widgets/list_widget.dart +++ b/lib/widgets/list_widget.dart @@ -52,8 +52,8 @@ class ListWidget extends StatelessWidget { ); }, leading: getImage(index), - title: Text(indexController.locations[0].collection[index].properties!['location_name'].toString()), - subtitle: Text(indexController.locations[0].collection[index].properties!['category']), + title: indexController.locations[0].collection[index].properties!['location_name'] != null ? Text(indexController.locations[0].collection[index].properties!['location_name'].toString()) : Text(""), + subtitle: indexController.locations[0].collection[index].properties!['category'] != null ? Text(indexController.locations[0].collection[index].properties!['category']) : Text(""), ), ); }, diff --git a/pubspec.lock b/pubspec.lock index 639bec0..844e8a7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -138,28 +138,28 @@ packages: name: flutter_map url: "https://pub.dartlang.org" source: hosted - version: "0.14.0" + version: "1.1.1" flutter_map_location_marker: dependency: "direct main" description: name: flutter_map_location_marker url: "https://pub.dartlang.org" source: hosted - version: "3.1.0" + version: "4.1.0" flutter_map_marker_cluster: dependency: "direct main" description: name: flutter_map_marker_cluster url: "https://pub.dartlang.org" source: hosted - version: "0.4.4" + version: "0.5.0" flutter_map_marker_popup: dependency: transitive description: name: flutter_map_marker_popup url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.2.1" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -211,7 +211,7 @@ packages: name: geolocator_android url: "https://pub.dartlang.org" source: hosted - version: "3.1.8" + version: "3.2.1" geolocator_apple: dependency: transitive description: @@ -506,6 +506,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + polylabel: + dependency: transitive + description: + name: polylabel + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" positioned_tap_detector: dependency: "direct main" description: @@ -743,5 +750,5 @@ packages: source: hosted version: "0.2.0+1" sdks: - dart: ">=2.17.0-0 <3.0.0" - flutter: ">=2.10.0" + dart: ">=2.17.0 <3.0.0" + flutter: ">=3.0.0" diff --git a/test/widget_test.dart b/test/widget_test.dart index b5f1975..5b12e0c 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:rogapp/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget( MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget);