Skip to content

Commit

Permalink
Refactor: onLoadResourceCustomScheme로 이전및 미설치시 스토어
Browse files Browse the repository at this point in the history
  • Loading branch information
ybmin committed Sep 10, 2023
1 parent 49c84ed commit 05a9750
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
1 change: 0 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<queries>
<package android:name="com.kakao.talk" />
<package android:name="com.kakaopay.app" />
<package android:name="viva.republica.toss" />
<package android:name="com.kakao.taxi" />
<package android:name="com.ubercab" />
Expand Down
82 changes: 52 additions & 30 deletions lib/views/taxiView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:taxiapp/views/taxiDialog.dart';
import 'package:app_links/app_links.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:open_store/open_store.dart';

class TaxiView extends HookWidget {
final CookieManager _cookieManager = CookieManager.instance();
Expand Down Expand Up @@ -282,41 +282,20 @@ class TaxiView extends HookWidget {
useShouldOverrideUrlLoading: true,
applicationNameForUserAgent: "taxi-app-webview/" +
(Platform.isAndroid ? "android" : "ios"),
resourceCustomSchemes: ['intent']),
resourceCustomSchemes: [
'intent',
'supertoss',
'uber',
'tmoneyonda',
'kakaotalk',
'kakaot'
]),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
overScrollMode:
AndroidOverScrollMode.OVER_SCROLL_NEVER),
ios: IOSInAppWebViewOptions(disallowOverScroll: true)),
// initialUrlRequest: URLRequest(url: Uri.parse(address)),
shouldOverrideUrlLoading: (controller, navigationAction) async {
var url = navigationAction.request.url.toString();
var uri = Uri.parse(url);
if (![
"http",
"https",
"file",
"chrome",
"data",
"javascript",
"intent",
"about"
].contains(uri.scheme)) {
if (await canLaunchUrlString(url)) {
await launchUrlString(url,
mode: LaunchMode.externalApplication);
return NavigationActionPolicy.CANCEL;
}
Fluttertoast.showToast(
msg: "앱이 설치되어 있지 않아 실행에 실패했습니다",
toastLength: Toast.LENGTH_SHORT,
textColor: Colors.black,
backgroundColor: Colors.white);
return NavigationActionPolicy.CANCEL;
}

return NavigationActionPolicy.ALLOW;
},
onWebViewCreated: (InAppWebViewController webcontroller) async {
_controller.value = webcontroller;
_controller.value?.addJavaScriptHandler(
Expand Down Expand Up @@ -419,6 +398,49 @@ class TaxiView extends HookWidget {
}
},
onLoadResourceCustomScheme: (controller, url) async {
if (!['intent'].contains(url.scheme)) {
await controller.stopLoading();
if (await canLaunchUrlString(url.toString())) {
await launchUrlString(url.toString(),
mode: LaunchMode.externalApplication);
return;
}
switch (url.scheme) {
case 'supertoss':
OpenStore.instance.open(
androidAppBundleId: "viva.republica.toss",
appStoreId: "839333328");
break;
case 'uber':
OpenStore.instance.open(
androidAppBundleId: "com.ubercab",
appStoreId: "368677368");
break;
case 'tmoneyonda':
OpenStore.instance.open(
androidAppBundleId: "kr.co.orangetaxi.passenger",
appStoreId: "1489918157");
break;
case 'kakaotalk': //카카오페이 결제시
OpenStore.instance.open(
androidAppBundleId: "com.kakao.talk",
appStoreId: "362057947");
break;
case 'kakaot':
OpenStore.instance.open(
androidAppBundleId: "com.kakao.taxi",
appStoreId: "981110422");
break;
default:
await Fluttertoast.showToast(
msg: "해당 앱을 실행할 수 없습니다.",
toastLength: Toast.LENGTH_SHORT,
textColor: Colors.black,
backgroundColor: Colors.white);
break;
}
return null;
}
if (Platform.isAndroid) {
if (url.scheme == 'intent') {
try {
Expand Down

0 comments on commit 05a9750

Please sign in to comment.