mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
replace webview plugin with inappwebview plugin to check camera permission once in app
This commit is contained in:
parent
f2ea86a713
commit
b8293ac0ae
4 changed files with 26 additions and 20 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"
|
||||
|
@ -43,6 +44,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>
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
@ -44,7 +45,7 @@ final rootKey = GlobalKey<RootState>();
|
|||
Future<void> main() async {
|
||||
try {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await Permission.camera.request();
|
||||
final appDir = await getApplicationDocumentsDirectory();
|
||||
await Hive.close();
|
||||
Hive.init(appDir.path);
|
||||
|
|
|
@ -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,29 @@ 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) =>
|
||||
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();
|
||||
final urlString = url.toString();
|
||||
if (url == null) {
|
||||
throw Exception('_saveOrder: Url is null');
|
||||
}
|
||||
|
||||
if (url!.contains(keyword)) {
|
||||
final urlParts = url!.split(splitSymbol);
|
||||
if (urlString.toString().contains(keyword)) {
|
||||
final urlParts = urlString.split(splitSymbol);
|
||||
orderId = urlParts.last;
|
||||
widget.ordersStore.orderId = orderId;
|
||||
|
||||
|
|
|
@ -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