@@ -8,6 +8,7 @@ import 'dart:convert';
8
8
import 'package:flutter_downloader/flutter_downloader.dart' ;
9
9
import 'package:path_provider/path_provider.dart' ;
10
10
import 'package:permission_handler/permission_handler.dart' ;
11
+ import 'package:open_file/open_file.dart' ;
11
12
12
13
class UpdatePage extends StatefulWidget {
13
14
@override
@@ -19,25 +20,41 @@ class _UpdatePageState extends State<UpdatePage> {
19
20
void initState () {
20
21
super .initState ();
21
22
FlutterDownloader .registerCallback ((id, status, progress) async {
23
+ setState (() {
24
+ _currProgress = progress;
25
+ });
22
26
print (
23
27
"id:${id }===== status=======:${status }=====progress======:${progress }" );
24
28
// 当下载完成时,调用安装
25
29
if (status == DownloadTaskStatus .complete) {
30
+
31
+ OpenFile .open (_localPath);
26
32
FlutterDownloader .open (taskId: id);
33
+
27
34
}
28
35
});
29
- _permissisonReady= false ;
36
+ _permissisonReady = false ;
30
37
_prepare ();
31
38
}
32
39
33
40
bool _isLoading;
34
41
bool _permissisonReady;
35
42
String _localPath;
43
+ int _currProgress = 0 ;
36
44
37
45
@override
38
46
Widget build (BuildContext context) {
39
47
return Column (
40
48
children: < Widget > [
49
+ Container (
50
+ margin: EdgeInsets .only (top: 20 ),
51
+ width: double .infinity,
52
+ height: 10.0 ,
53
+ child: new LinearProgressIndicator (
54
+ value: _currProgress / 100 ,
55
+ backgroundColor: Colors .red,
56
+ ),
57
+ ),
41
58
Center (
42
59
child: Text ("现在是1.0.0" ,
43
60
textAlign: TextAlign .center, style: TextStyle (fontSize: 20 )),
@@ -48,7 +65,7 @@ class _UpdatePageState extends State<UpdatePage> {
48
65
print ("点击${_permissisonReady }" );
49
66
if (_permissisonReady) {
50
67
_requestDownload ();
51
- }else {
68
+ } else {
52
69
_checkPermission ().then ((hasGranted) {
53
70
setState (() {
54
71
_permissisonReady = hasGranted;
@@ -62,14 +79,13 @@ class _UpdatePageState extends State<UpdatePage> {
62
79
),
63
80
color: Colors .red[800 ],
64
81
),
65
- )
82
+ ),
66
83
],
67
84
);
68
85
}
69
86
70
87
Future <Null > _prepare () async {
71
88
_permissisonReady = await _checkPermission ();
72
- _localPath = (await _findLocalPath ()) + '/Download' ;
73
89
}
74
90
75
91
//检查权限
@@ -115,6 +131,7 @@ class _UpdatePageState extends State<UpdatePage> {
115
131
// 获取安装地址
116
132
Future <String > get _apkLocalPath async {
117
133
final directory = await getExternalStorageDirectory ();
118
- return directory.path.toString ();
134
+ _localPath = directory.path.toString ();
135
+ return _localPath;
119
136
}
120
137
}
0 commit comments