mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 02:34:59 +00:00
Merge pull request #711 from cake-tech/CW-269-research-if-we-can-avoid-re-requesting-camera-permission-on-web-view-in-buy-screen
CW-269 replace webview plugin with inappwebview plugin
This commit is contained in:
commit
5b5c5bad66
4 changed files with 59 additions and 50 deletions
|
@ -6,6 +6,7 @@
|
|||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<application
|
||||
android:name=".Application"
|
||||
|
@ -52,6 +53,15 @@
|
|||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
<provider
|
||||
android:name="com.pichillilorenzo.flutter_inappwebview.InAppWebViewFileProvider"
|
||||
android:authorities="${applicationId}.flutter_inappwebview.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
<queries>
|
||||
|
|
|
@ -9,11 +9,10 @@ import 'package:cake_wallet/src/screens/base_page.dart';
|
|||
import 'package:cake_wallet/store/dashboard/orders_store.dart';
|
||||
import 'package:cake_wallet/view_model/buy/buy_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
|
||||
class BuyWebViewPage extends BasePage {
|
||||
BuyWebViewPage({required this.buyViewModel,
|
||||
required this.ordersStore, required this.url});
|
||||
BuyWebViewPage({required this.buyViewModel, required this.ordersStore, required this.url});
|
||||
|
||||
final OrdersStore ordersStore;
|
||||
final String url;
|
||||
|
@ -46,12 +45,12 @@ class BuyWebViewPageBody extends StatefulWidget {
|
|||
|
||||
class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
|
||||
BuyWebViewPageBodyState()
|
||||
: _webViewkey = GlobalKey(),
|
||||
_isSaving = false,
|
||||
orderId = '';
|
||||
: _webViewkey = GlobalKey(),
|
||||
_isSaving = false,
|
||||
orderId = '';
|
||||
|
||||
String orderId;
|
||||
WebViewController? _webViewController;
|
||||
InAppWebViewController? _webViewController;
|
||||
GlobalKey _webViewkey;
|
||||
Timer? _timer;
|
||||
bool _isSaving;
|
||||
|
@ -63,8 +62,6 @@ class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
|
|||
_isSaving = false;
|
||||
widget.ordersStore.orderId = '';
|
||||
|
||||
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
||||
|
||||
if (widget.buyViewModel.selectedProvider is WyreBuyProvider) {
|
||||
_saveOrder(keyword: 'completed', splitSymbol: '/');
|
||||
}
|
||||
|
@ -76,31 +73,31 @@ class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WebView(
|
||||
return InAppWebView(
|
||||
key: _webViewkey,
|
||||
initialUrl: widget.url,
|
||||
javascriptMode: JavascriptMode.unrestricted,
|
||||
onWebViewCreated: (WebViewController controller) =>
|
||||
initialOptions: InAppWebViewGroupOptions(
|
||||
crossPlatform: InAppWebViewOptions(transparentBackground: true),
|
||||
),
|
||||
initialUrlRequest: URLRequest(url: Uri.tryParse(widget.url ?? '')),
|
||||
onWebViewCreated: (InAppWebViewController controller) =>
|
||||
setState(() => _webViewController = controller));
|
||||
}
|
||||
|
||||
void _saveOrder({required String keyword, required String splitSymbol}) {
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(Duration(seconds: 1), (timer) async {
|
||||
|
||||
try {
|
||||
if (_webViewController == null || _isSaving) {
|
||||
return;
|
||||
}
|
||||
|
||||
final url = await _webViewController!.currentUrl();
|
||||
|
||||
final url = (await _webViewController!.getUrl())?.toString();
|
||||
if (url == null) {
|
||||
throw Exception('_saveOrder: Url is null');
|
||||
}
|
||||
|
||||
if (url!.contains(keyword)) {
|
||||
final urlParts = url!.split(splitSymbol);
|
||||
if (url.contains(keyword)) {
|
||||
final urlParts = url.split(splitSymbol);
|
||||
orderId = urlParts.last;
|
||||
widget.ordersStore.orderId = orderId;
|
||||
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
import 'dart:io';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class OnRamperPage extends BasePage {
|
||||
OnRamperPage({
|
||||
required this.settingsStore,
|
||||
required this.wallet});
|
||||
OnRamperPage({required this.settingsStore, required this.wallet});
|
||||
|
||||
final SettingsStore settingsStore;
|
||||
final WalletBase wallet;
|
||||
|
@ -25,22 +23,20 @@ class OnRamperPage extends BasePage {
|
|||
settingsStore: settingsStore,
|
||||
wallet: wallet,
|
||||
darkMode: darkMode,
|
||||
backgroundColor: darkMode
|
||||
? backgroundDarkColor
|
||||
: backgroundLightColor,
|
||||
backgroundColor: darkMode ? backgroundDarkColor : backgroundLightColor,
|
||||
supportSell: false,
|
||||
supportSwap: false);
|
||||
}
|
||||
}
|
||||
|
||||
class OnRamperPageBody extends StatefulWidget {
|
||||
OnRamperPageBody({
|
||||
required this.settingsStore,
|
||||
required this.wallet,
|
||||
required this.darkMode,
|
||||
required this.supportSell,
|
||||
required this.supportSwap,
|
||||
required this.backgroundColor});
|
||||
OnRamperPageBody(
|
||||
{required this.settingsStore,
|
||||
required this.wallet,
|
||||
required this.darkMode,
|
||||
required this.supportSell,
|
||||
required this.supportSwap,
|
||||
required this.backgroundColor});
|
||||
|
||||
static const baseUrl = 'widget.onramper.com';
|
||||
final SettingsStore settingsStore;
|
||||
|
@ -50,18 +46,15 @@ class OnRamperPageBody extends StatefulWidget {
|
|||
final bool supportSell;
|
||||
final bool supportSwap;
|
||||
|
||||
Uri get uri
|
||||
=> Uri.https(
|
||||
baseUrl,
|
||||
'',
|
||||
<String, dynamic>{
|
||||
Uri get uri => Uri.https(baseUrl, '', <String, dynamic>{
|
||||
'apiKey': secrets.onramperApiKey,
|
||||
'defaultCrypto': wallet.currency.title,
|
||||
'defaultFiat': settingsStore.fiatCurrency.title,
|
||||
'wallets': '${wallet.currency.title}:${wallet.walletAddresses.address}',
|
||||
'darkMode': darkMode.toString(),
|
||||
'supportSell': supportSell.toString(),
|
||||
'supportSwap': supportSwap.toString()});
|
||||
'supportSwap': supportSwap.toString()
|
||||
});
|
||||
|
||||
@override
|
||||
OnRamperPageBodyState createState() => OnRamperPageBodyState();
|
||||
|
@ -70,17 +63,26 @@ class OnRamperPageBody extends StatefulWidget {
|
|||
class OnRamperPageBodyState extends State<OnRamperPageBody> {
|
||||
OnRamperPageBodyState();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WebView(
|
||||
initialUrl: widget.uri.toString(),
|
||||
backgroundColor: widget.backgroundColor,
|
||||
javascriptMode: JavascriptMode.unrestricted);
|
||||
return InAppWebView(
|
||||
initialOptions: InAppWebViewGroupOptions(
|
||||
crossPlatform: InAppWebViewOptions(transparentBackground: true),
|
||||
),
|
||||
initialUrlRequest: URLRequest(url: widget.uri),
|
||||
androidOnPermissionRequest: (_, __, resources) async {
|
||||
bool permissionGranted = await Permission.camera.status == PermissionStatus.granted;
|
||||
if (!permissionGranted) {
|
||||
permissionGranted = await Permission.camera.request().isGranted;
|
||||
}
|
||||
|
||||
return PermissionRequestResponse(
|
||||
resources: resources,
|
||||
action: permissionGranted
|
||||
? PermissionRequestResponseAction.GRANT
|
||||
: PermissionRequestResponseAction.DENY,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ dependencies:
|
|||
auto_size_text: ^3.0.0
|
||||
dotted_border: ^2.0.0+2
|
||||
smooth_page_indicator: ^1.0.0+2
|
||||
webview_flutter: ^3.0.4
|
||||
flutter_inappwebview: ^5.7.2+3
|
||||
flutter_spinkit: ^5.1.0
|
||||
uni_links: ^0.5.1
|
||||
lottie: ^1.3.0
|
||||
|
|
Loading…
Reference in a new issue