From affb6fa1a3d4f60334fe53b7f3c8af9ff042e873 Mon Sep 17 00:00:00 2001 From: ybmin Date: Tue, 5 Nov 2024 23:42:09 +0900 Subject: [PATCH] Add: inappwebview location --- lib/views/taxiView.dart | 39 +++++++++++++++++++++++++++++++++------ pubspec.yaml | 1 + 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/views/taxiView.dart b/lib/views/taxiView.dart index 265cf5c..47af588 100644 --- a/lib/views/taxiView.dart +++ b/lib/views/taxiView.dart @@ -35,6 +35,17 @@ class TaxiView extends HookWidget { FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); + //TODO: Remove this on production + Future _requestLocationPermission() async { + var status = await Permission.locationWhenInUse.status; + if (status.isDenied) { + status = await Permission.locationWhenInUse.request(); + } + if (!status.isGranted) { + Fluttertoast.showToast(msg: "위치 권한이 거부되었습니다."); + } + } + @override Widget build(BuildContext context) { String address = RemoteConfigController().frontUrl; @@ -70,6 +81,12 @@ class TaxiView extends HookWidget { devicePixelRatio = MediaQuery.of(context).devicePixelRatio; + //TODO: Remove this on production + useEffect(() { + _requestLocationPermission(); + return; + }, []); + useEffect(() { if (isTimerUp.value) { FcmToken().init().then((value) { @@ -619,6 +636,22 @@ class TaxiView extends HookWidget { } }); + _controller.value?.addJavaScriptHandler( + handlerName: "try_location", + callback: (args) async { + if (await Permission.locationWhenInUse.isGranted) { + return true; + } else { + openAppSettings(); + Fluttertoast.showToast( + msg: "위치 권한을 허용해주세요.", + toastLength: Toast.LENGTH_SHORT, + textColor: toastTextColor, + backgroundColor: toastBackgroundColor); + return false; + } + }); + _controller.value?.addJavaScriptHandler( handlerName: "clipboard_copy", callback: (args) async { @@ -830,12 +863,6 @@ class TaxiView extends HookWidget { }, androidOnPermissionRequest: (controller, origin, resources) async { - if (resources.contains("location")) { - var status = await Permission.location.request(); - if (!status.isGranted) { - openAppSettings(); - } - } return PermissionRequestResponse( resources: resources, action: PermissionRequestResponseAction.GRANT); diff --git a/pubspec.yaml b/pubspec.yaml index 224e604..5fe8549 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -59,6 +59,7 @@ dependencies: http: ^1.1.0 swipeable_tile: ^2.0.0+3 linear_timer: ^2.0.0 + geolocator: ^13.0.1 dev_dependencies: flutter_test: sdk: flutter