Skip to content

Commit

Permalink
Add: inappwebview location
Browse files Browse the repository at this point in the history
  • Loading branch information
ybmin committed Nov 5, 2024
1 parent 8bc603c commit affb6fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
39 changes: 33 additions & 6 deletions lib/views/taxiView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ class TaxiView extends HookWidget {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

//TODO: Remove this on production
Future<void> _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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit affb6fa

Please sign in to comment.