|
|
|
// import 'dart:async';
|
|
|
|
|
|
|
|
// import 'package:device_info/device_info.dart';
|
|
|
|
// import 'package:dio/dio.dart';
|
|
|
|
// import 'package:flutter/material.dart';
|
|
|
|
// import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
|
|
// import 'package:one_key/net/dio_util.dart';
|
|
|
|
// import 'package:one_key/res/colors.dart';
|
|
|
|
// import 'package:one_key/utils/event_bus.dart';
|
|
|
|
// import 'package:one_key/utils/utils.dart';
|
|
|
|
// import 'package:one_key/widgets/system_app_bar.dart';
|
|
|
|
// import 'package:path_provider/path_provider.dart';
|
|
|
|
// import 'package:permission_handler/permission_handler.dart';
|
|
|
|
// import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
|
|
// import 'dart:async';
|
|
|
|
// import 'dart:convert';
|
|
|
|
// import 'dart:io';
|
|
|
|
|
|
|
|
// import 'package:flutter/material.dart';
|
|
|
|
// import 'package:one_key/utils/event_bus.dart';
|
|
|
|
// import 'package:one_key/widgets/app_bar.dart';
|
|
|
|
// import 'package:one_key/widgets/system_app_bar.dart';
|
|
|
|
// import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
|
|
// // import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
|
|
// import 'package:url_launcher/url_launcher.dart';
|
|
|
|
// import 'dart:collection';
|
|
|
|
// // import 'package:open_file/open_file.dart';
|
|
|
|
// // import 'package:flutter_downloader/flutter_downloader.dart';
|
|
|
|
|
|
|
|
// class WebPage extends StatefulWidget {
|
|
|
|
// final String title;
|
|
|
|
// final String url;
|
|
|
|
// final bool need;
|
|
|
|
|
|
|
|
// const WebPage({Key key, this.title, this.url, this.need = false})
|
|
|
|
// : super(key: key);
|
|
|
|
// @override
|
|
|
|
// _WebPageState createState() => _WebPageState();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// class _WebPageState extends State<WebPage> {
|
|
|
|
// final GlobalKey webViewKey = GlobalKey();
|
|
|
|
|
|
|
|
// InAppWebViewController webViewController;
|
|
|
|
// InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
|
|
|
|
// crossPlatform: InAppWebViewOptions(
|
|
|
|
// useShouldOverrideUrlLoading: true,
|
|
|
|
// useOnDownloadStart: true,
|
|
|
|
// mediaPlaybackRequiresUserGesture: false,
|
|
|
|
// ),
|
|
|
|
// android: AndroidInAppWebViewOptions(
|
|
|
|
// useHybridComposition: true,
|
|
|
|
// ),
|
|
|
|
// ios: IOSInAppWebViewOptions(
|
|
|
|
// allowsInlineMediaPlayback: true,
|
|
|
|
// ));
|
|
|
|
|
|
|
|
// PullToRefreshController pullToRefreshController;
|
|
|
|
// ContextMenu contextMenu;
|
|
|
|
// String url = "";
|
|
|
|
// double progress = 0;
|
|
|
|
// final urlController = TextEditingController();
|
|
|
|
// // Future<void> openFile(filePath) async {
|
|
|
|
// // final _result = await OpenFile.open(filePath);
|
|
|
|
// // print(_result.message);
|
|
|
|
|
|
|
|
// // // setState(() {
|
|
|
|
// // // _openResult = "type=${_result.type} message=${_result.message}";
|
|
|
|
// // // });
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// @override
|
|
|
|
// void initState() {
|
|
|
|
// super.initState();
|
|
|
|
|
|
|
|
// // Enable hybrid composition.
|
|
|
|
// _init();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @override
|
|
|
|
// void dispose() {
|
|
|
|
// if (widget.need) {
|
|
|
|
// Utils.changeStatusColor(color: MyColours.color_199095);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// super.dispose();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Future<bool> _checkPermission() async {
|
|
|
|
// DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
|
|
// AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
|
|
|
// if (Platform.isAndroid && androidInfo.version.sdkInt <= 28) {
|
|
|
|
// final status = await Permission.storage.status;
|
|
|
|
// if (status != PermissionStatus.granted) {
|
|
|
|
// final result = await Permission.storage.request();
|
|
|
|
// if (result == PermissionStatus.granted) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Future<bool> checkPermissionStorage() async {
|
|
|
|
// var status = await Permission.storage.status;
|
|
|
|
// if (!status.isGranted) {
|
|
|
|
// status = await Permission.storage.request();
|
|
|
|
// if (status.isGranted) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// _init() async {
|
|
|
|
// // WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// // await FlutterDownloader.initialize(debug: true);
|
|
|
|
// if (Platform.isAndroid) {
|
|
|
|
// await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
|
|
|
|
|
|
|
|
// var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
|
|
|
|
// AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE);
|
|
|
|
// var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported(
|
|
|
|
// AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST);
|
|
|
|
|
|
|
|
// if (swAvailable && swInterceptAvailable) {
|
|
|
|
// AndroidServiceWorkerController serviceWorkerController =
|
|
|
|
// AndroidServiceWorkerController.instance();
|
|
|
|
|
|
|
|
// serviceWorkerController.serviceWorkerClient =
|
|
|
|
// AndroidServiceWorkerClient(
|
|
|
|
// shouldInterceptRequest: (request) async {
|
|
|
|
// print(request);
|
|
|
|
// return null;
|
|
|
|
// },
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// // await FlutterDownloader.initialize(
|
|
|
|
// // debug: true // optional: set false to disable printing logs to console
|
|
|
|
// // );
|
|
|
|
// // await Permission.storage.request();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @override
|
|
|
|
// Widget build(BuildContext context) {
|
|
|
|
// return Scaffold(
|
|
|
|
// // We're using a Builder here so we have a context that is below the Scaffold
|
|
|
|
// // to allow calling Scaffold.of(context) so we can show a snackbar.
|
|
|
|
// appBar: SystemAppBar(
|
|
|
|
// widget.title,
|
|
|
|
// ),
|
|
|
|
// body: Column(
|
|
|
|
// children: [
|
|
|
|
// Expanded(
|
|
|
|
// child: InAppWebView(
|
|
|
|
// key: webViewKey,
|
|
|
|
// // contextMenu: contextMenu,
|
|
|
|
// initialUrlRequest: URLRequest(
|
|
|
|
// // url: Uri.parse("http://colorcun.com/privacy1.html")),
|
|
|
|
// url: Uri.parse("http://colorcun.com/privacy2.html")),
|
|
|
|
// //华为下载功能闪退,去掉下载功能*********http://colorcun.com/privacy2.html
|
|
|
|
// // initialFile: "assets/index.html",
|
|
|
|
// initialUserScripts: UnmodifiableListView<UserScript>([]),
|
|
|
|
// initialOptions: options,
|
|
|
|
// pullToRefreshController: pullToRefreshController,
|
|
|
|
// onWebViewCreated: (controller) {
|
|
|
|
// webViewController = controller;
|
|
|
|
// },
|
|
|
|
// onLoadStart: (controller, url) {
|
|
|
|
// setState(() {
|
|
|
|
// this.url = url.toString();
|
|
|
|
// urlController.text = this.url;
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// androidOnPermissionRequest:
|
|
|
|
// (controller, origin, resources) async {
|
|
|
|
// return PermissionRequestResponse(
|
|
|
|
// resources: resources,
|
|
|
|
// action: PermissionRequestResponseAction.GRANT);
|
|
|
|
// },
|
|
|
|
// shouldOverrideUrlLoading: (controller, navigationAction) async {
|
|
|
|
// var uri = navigationAction.request.url;
|
|
|
|
|
|
|
|
// if (![
|
|
|
|
// "http",
|
|
|
|
// "https",
|
|
|
|
// "file",
|
|
|
|
// "chrome",
|
|
|
|
// "data",
|
|
|
|
// "javascript",
|
|
|
|
// "about"
|
|
|
|
// ].contains(uri.scheme)) {
|
|
|
|
// if (await canLaunch(url)) {
|
|
|
|
// // Launch the App
|
|
|
|
// await launch(
|
|
|
|
// url,
|
|
|
|
// );
|
|
|
|
// // and cancel the request
|
|
|
|
// return NavigationActionPolicy.CANCEL;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return NavigationActionPolicy.ALLOW;
|
|
|
|
// },
|
|
|
|
// onLoadStop: (controller, url) async {
|
|
|
|
// pullToRefreshController.endRefreshing();
|
|
|
|
// setState(() {
|
|
|
|
// this.url = url.toString();
|
|
|
|
// urlController.text = this.url;
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// onLoadError: (controller, url, code, message) {
|
|
|
|
// pullToRefreshController.endRefreshing();
|
|
|
|
// },
|
|
|
|
// onProgressChanged: (controller, progress) {
|
|
|
|
// if (progress == 100) {
|
|
|
|
// pullToRefreshController.endRefreshing();
|
|
|
|
// }
|
|
|
|
// setState(() {
|
|
|
|
// this.progress = progress / 100;
|
|
|
|
// urlController.text = this.url;
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// onUpdateVisitedHistory: (controller, url, androidIsReload) {
|
|
|
|
// setState(() {
|
|
|
|
// this.url = url.toString();
|
|
|
|
// urlController.text = this.url;
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// onConsoleMessage: (controller, consoleMessage) {
|
|
|
|
// print(consoleMessage);
|
|
|
|
// },
|
|
|
|
// onDownloadStart: (controller, url) async {
|
|
|
|
// print("onDownloadStart $url");
|
|
|
|
// Utils.showToast('开始下载...');
|
|
|
|
// // final taskId = await FlutterDownloader.enqueue(
|
|
|
|
// // url: url.toString(),
|
|
|
|
// // savedDir: (await getExternalStorageDirectory()).path,
|
|
|
|
// // showNotification:
|
|
|
|
// // true, // show download progress in status bar (for Android)
|
|
|
|
// // openFileFromNotification:
|
|
|
|
// // true, // click on notification to open downloaded file (for Android)
|
|
|
|
// // );
|
|
|
|
// final dir = await getExternalStorageDirectory();
|
|
|
|
// String savePath = dir.path + "/one_key";
|
|
|
|
|
|
|
|
// Directory directory = new Directory(savePath);
|
|
|
|
// if (directory.existsSync()) {
|
|
|
|
// //删除历史apk
|
|
|
|
// final List<FileSystemEntity> files = directory.listSync();
|
|
|
|
// for (FileSystemEntity file in files) {
|
|
|
|
// file.deleteSync();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// DioUtil().download(url.toString(), savePath,
|
|
|
|
// onProgress: (received, total) {
|
|
|
|
// // if (_progress != 100) {
|
|
|
|
// // int progress = ((received / total) * 100).round();
|
|
|
|
// // _progress = progress;
|
|
|
|
// // _setState(() {});
|
|
|
|
// // }
|
|
|
|
// if (received == total) {
|
|
|
|
// print('object');
|
|
|
|
// Utils.showToast('文件已保存在${savePath}');
|
|
|
|
// // openFile(savePath);
|
|
|
|
// //下载完成
|
|
|
|
// // InstallPlugin.installApk(savePath, "com.naji.one_key");
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// // },
|
|
|
|
// // DioUtil().download(url.toString(),
|
|
|
|
// // (await getExternalStorageDirectory()).path,
|
|
|
|
// // onProgress: (received, total) {
|
|
|
|
// // // if (_progress != 100) {
|
|
|
|
// // // int progress = ((received / total) * 100).round();
|
|
|
|
// // // _progress = progress;
|
|
|
|
// // // _setState(() {});
|
|
|
|
// // // }
|
|
|
|
// // if (received == total) {
|
|
|
|
// // //下载完成
|
|
|
|
// // // InstallPlugin.installApk(savePath, "com.naji.one_key");
|
|
|
|
// // }
|
|
|
|
// // });
|
|
|
|
// },
|
|
|
|
// ))
|
|
|
|
// ],
|
|
|
|
// )
|
|
|
|
// // Builder(builder: (BuildContext context) {
|
|
|
|
// // return WebView(
|
|
|
|
// // initialUrl: "http://colorcun.com/privacy1.html",
|
|
|
|
// // javascriptMode: JavascriptMode.unrestricted,
|
|
|
|
// // onWebViewCreated: (WebViewController webViewController) {
|
|
|
|
// // _controller.complete(webViewController);
|
|
|
|
// // },
|
|
|
|
// // // TODO(iskakaushik): Remove this when collection literals makes it to stable.
|
|
|
|
// // // ignore: prefer_collection_literals
|
|
|
|
// // javascriptChannels: <JavascriptChannel>[
|
|
|
|
// // _toasterJavascriptChannel(context),
|
|
|
|
// // ].toSet(),
|
|
|
|
// // navigationDelegate: (NavigationRequest request) {
|
|
|
|
// // if (request.url.startsWith('https://www.youtube.com/')) {
|
|
|
|
// // print('blocking navigation to $request}');
|
|
|
|
// // return NavigationDecision.prevent;
|
|
|
|
// // }
|
|
|
|
// // print('allowing navigation to $request');
|
|
|
|
// // return NavigationDecision.navigate;
|
|
|
|
// // },
|
|
|
|
// // onPageStarted: (String url) {
|
|
|
|
// // print('Page started loading: $url');
|
|
|
|
// // },
|
|
|
|
// // onPageFinished: (String url) async {
|
|
|
|
// // print('Page finished loading: $url');
|
|
|
|
// // // showDownloadProgress(context);
|
|
|
|
// // final dir = await getExternalStorageDirectory();
|
|
|
|
// // String savePath = dir.path + "/one_key";
|
|
|
|
// // DioUtil().download(url, savePath,
|
|
|
|
// // onProgress: (received, total) {
|
|
|
|
// // // if (_progress != 100) {
|
|
|
|
// // // int progress = ((received / total) * 100).round();
|
|
|
|
// // // _progress = progress;
|
|
|
|
// // // _setState(() {});
|
|
|
|
// // // }
|
|
|
|
// // if (received == total) {
|
|
|
|
// // print('object');
|
|
|
|
// // //下载完成
|
|
|
|
// // // InstallPlugin.installApk(savePath, "com.naji.one_key");
|
|
|
|
// // }
|
|
|
|
// // });
|
|
|
|
// // },
|
|
|
|
// // gestureNavigationEnabled: true,
|
|
|
|
// // );
|
|
|
|
// // }),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // JavascriptChannel _toasterJavascriptChannel(BuildContext context) {
|
|
|
|
// // return JavascriptChannel(
|
|
|
|
// // name: 'Toaster',
|
|
|
|
// // onMessageReceived: (JavascriptMessage message) {
|
|
|
|
// // Scaffold.of(context).showSnackBar(
|
|
|
|
// // SnackBar(content: Text(message.message)),
|
|
|
|
// // );
|
|
|
|
// // });
|
|
|
|
// // }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // class WebPage extends StatelessWidget {
|
|
|
|
// // final String title;
|
|
|
|
// // final String url;
|
|
|
|
// // final bool need;
|
|
|
|
|
|
|
|
// // const WebPage({Key key, this.title, this.url, this.need = false})
|
|
|
|
// // : super(key: key);
|
|
|
|
// // @override
|
|
|
|
// // Widget build(BuildContext context) {
|
|
|
|
// // final Completer<WebViewController> _controller =
|
|
|
|
// // Completer<WebViewController>();
|
|
|
|
// // return Scaffold(
|
|
|
|
// // appBar: SystemAppBar(title, onTap: () {
|
|
|
|
// // if (need) {
|
|
|
|
// // Utils.changeStatusColor(color: MyColours.color_199095);
|
|
|
|
// // }
|
|
|
|
// // Navigator.of(context).pop();
|
|
|
|
// // }),
|
|
|
|
// // body: WillPopScope(
|
|
|
|
// // onWillPop: () async {
|
|
|
|
// // if (need) {
|
|
|
|
// // Utils.changeStatusColor(color: MyColours.color_199095);
|
|
|
|
// // }
|
|
|
|
// // return true;
|
|
|
|
// // },
|
|
|
|
// // child: WebView(
|
|
|
|
// // initialUrl: "http://colorcun.com/privacy1.html",
|
|
|
|
// // javascriptMode: JavascriptMode.unrestricted,
|
|
|
|
// // onWebViewCreated: (WebViewController webViewController) {
|
|
|
|
// // // Loading.showLoading(context);
|
|
|
|
// // _controller.complete(webViewController);
|
|
|
|
// // },
|
|
|
|
// // javascriptChannels: <JavascriptChannel>[
|
|
|
|
// // _toasterJavascriptChannel(context),
|
|
|
|
// // ].toSet(),
|
|
|
|
// // navigationDelegate: (NavigationRequest request) {
|
|
|
|
// // if (request.url.startsWith('https://www.youtube.com/')) {
|
|
|
|
// // return NavigationDecision.prevent;
|
|
|
|
// // }
|
|
|
|
// // return NavigationDecision.navigate;
|
|
|
|
// // },
|
|
|
|
// // onPageStarted: (String url) {},
|
|
|
|
// // onPageFinished: (String url) {
|
|
|
|
// // // Loading.hideLoading(context);
|
|
|
|
// // },
|
|
|
|
// // gestureNavigationEnabled: true,
|
|
|
|
// // )),
|
|
|
|
// // );
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// // JavascriptChannel _toasterJavascriptChannel(BuildContext context) {
|
|
|
|
// // return JavascriptChannel(
|
|
|
|
// // name: 'Toaster',
|
|
|
|
// // onMessageReceived: (JavascriptMessage message) {
|
|
|
|
// // Scaffold.of(context).showSnackBar(
|
|
|
|
// // SnackBar(content: Text(message.message)),
|
|
|
|
// // );
|
|
|
|
// // });
|
|
|
|
// // }
|
|
|
|
// // } |