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_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".Application"
|
android:name=".Application"
|
||||||
|
@ -43,6 +44,15 @@
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
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>
|
</application>
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
|
|
|
@ -11,6 +11,7 @@ import 'package:flutter/services.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
@ -44,7 +45,7 @@ final rootKey = GlobalKey<RootState>();
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
await Permission.camera.request();
|
||||||
final appDir = await getApplicationDocumentsDirectory();
|
final appDir = await getApplicationDocumentsDirectory();
|
||||||
await Hive.close();
|
await Hive.close();
|
||||||
Hive.init(appDir.path);
|
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/store/dashboard/orders_store.dart';
|
||||||
import 'package:cake_wallet/view_model/buy/buy_view_model.dart';
|
import 'package:cake_wallet/view_model/buy/buy_view_model.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:webview_flutter/webview_flutter.dart';
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
|
|
||||||
class BuyWebViewPage extends BasePage {
|
class BuyWebViewPage extends BasePage {
|
||||||
BuyWebViewPage({required this.buyViewModel,
|
BuyWebViewPage({required this.buyViewModel, required this.ordersStore, required this.url});
|
||||||
required this.ordersStore, required this.url});
|
|
||||||
|
|
||||||
final OrdersStore ordersStore;
|
final OrdersStore ordersStore;
|
||||||
final String url;
|
final String url;
|
||||||
|
@ -51,7 +50,7 @@ class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
|
||||||
orderId = '';
|
orderId = '';
|
||||||
|
|
||||||
String orderId;
|
String orderId;
|
||||||
WebViewController? _webViewController;
|
InAppWebViewController? _webViewController;
|
||||||
GlobalKey _webViewkey;
|
GlobalKey _webViewkey;
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
bool _isSaving;
|
bool _isSaving;
|
||||||
|
@ -63,8 +62,6 @@ class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
|
||||||
_isSaving = false;
|
_isSaving = false;
|
||||||
widget.ordersStore.orderId = '';
|
widget.ordersStore.orderId = '';
|
||||||
|
|
||||||
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
|
||||||
|
|
||||||
if (widget.buyViewModel.selectedProvider is WyreBuyProvider) {
|
if (widget.buyViewModel.selectedProvider is WyreBuyProvider) {
|
||||||
_saveOrder(keyword: 'completed', splitSymbol: '/');
|
_saveOrder(keyword: 'completed', splitSymbol: '/');
|
||||||
}
|
}
|
||||||
|
@ -76,31 +73,29 @@ class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return WebView(
|
return InAppWebView(
|
||||||
key: _webViewkey,
|
key: _webViewkey,
|
||||||
initialUrl: widget.url,
|
initialUrlRequest: URLRequest(url: Uri.tryParse(widget.url ?? '')),
|
||||||
javascriptMode: JavascriptMode.unrestricted,
|
onWebViewCreated: (InAppWebViewController controller) =>
|
||||||
onWebViewCreated: (WebViewController controller) =>
|
|
||||||
setState(() => _webViewController = controller));
|
setState(() => _webViewController = controller));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _saveOrder({required String keyword, required String splitSymbol}) {
|
void _saveOrder({required String keyword, required String splitSymbol}) {
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
_timer = Timer.periodic(Duration(seconds: 1), (timer) async {
|
_timer = Timer.periodic(Duration(seconds: 1), (timer) async {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (_webViewController == null || _isSaving) {
|
if (_webViewController == null || _isSaving) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final url = await _webViewController!.currentUrl();
|
final url = await _webViewController!.getUrl();
|
||||||
|
final urlString = url.toString();
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
throw Exception('_saveOrder: Url is null');
|
throw Exception('_saveOrder: Url is null');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url!.contains(keyword)) {
|
if (urlString.toString().contains(keyword)) {
|
||||||
final urlParts = url!.split(splitSymbol);
|
final urlParts = urlString.split(splitSymbol);
|
||||||
orderId = urlParts.last;
|
orderId = urlParts.last;
|
||||||
widget.ordersStore.orderId = orderId;
|
widget.ordersStore.orderId = orderId;
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ dependencies:
|
||||||
auto_size_text: ^3.0.0
|
auto_size_text: ^3.0.0
|
||||||
dotted_border: ^2.0.0+2
|
dotted_border: ^2.0.0+2
|
||||||
smooth_page_indicator: ^1.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
|
flutter_spinkit: ^5.1.0
|
||||||
uni_links: ^0.5.1
|
uni_links: ^0.5.1
|
||||||
lottie: ^1.3.0
|
lottie: ^1.3.0
|
||||||
|
|
Loading…
Reference in a new issue