diff --git a/lib/views/update_test.dart b/lib/views/update_test.dart index 39122954..70c8d00e 100644 --- a/lib/views/update_test.dart +++ b/lib/views/update_test.dart @@ -8,6 +8,7 @@ import 'dart:convert'; import 'package:flutter_downloader/flutter_downloader.dart'; import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:open_file/open_file.dart'; class UpdatePage extends StatefulWidget { @override @@ -19,25 +20,41 @@ class _UpdatePageState extends State { void initState() { super.initState(); FlutterDownloader.registerCallback((id, status, progress) async { + setState(() { + _currProgress = progress; + }); print( "id:${id}===== status=======:${status}=====progress======:${progress}"); // 当下载完成时,调用安装 if (status == DownloadTaskStatus.complete) { + + OpenFile.open(_localPath); FlutterDownloader.open(taskId: id); + } }); - _permissisonReady=false; + _permissisonReady = false; _prepare(); } bool _isLoading; bool _permissisonReady; String _localPath; + int _currProgress = 0; @override Widget build(BuildContext context) { return Column( children: [ + Container( + margin: EdgeInsets.only(top: 20), + width: double.infinity, + height: 10.0, + child: new LinearProgressIndicator( + value: _currProgress / 100, + backgroundColor: Colors.red, + ), + ), Center( child: Text("现在是1.0.0", textAlign: TextAlign.center, style: TextStyle(fontSize: 20)), @@ -48,7 +65,7 @@ class _UpdatePageState extends State { print("点击${_permissisonReady}"); if (_permissisonReady) { _requestDownload(); - }else{ + } else { _checkPermission().then((hasGranted) { setState(() { _permissisonReady = hasGranted; @@ -62,14 +79,13 @@ class _UpdatePageState extends State { ), color: Colors.red[800], ), - ) + ), ], ); } Future _prepare() async { _permissisonReady = await _checkPermission(); - _localPath = (await _findLocalPath()) + '/Download'; } //检查权限 @@ -115,6 +131,7 @@ class _UpdatePageState extends State { // 获取安装地址 Future get _apkLocalPath async { final directory = await getExternalStorageDirectory(); - return directory.path.toString(); + _localPath = directory.path.toString(); + return _localPath; } } diff --git a/pubspec.lock b/pubspec.lock index ad4fe102..6da18c8d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -193,6 +193,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" + open_file: + dependency: "direct main" + description: + name: open_file + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1+2" path: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index cdbdb94d..c88d0d46 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,6 +41,7 @@ dependencies: flutter_downloader: ^1.1.7 path_provider: ^1.1.0 permission_handler: ^3.0.0 + open_file: ^2.0.1+2 dev_dependencies: flutter_test: