Skip to content

Commit 93876ee

Browse files
committed
test
1 parent f5921d4 commit 93876ee

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

lib/views/update_test.dart

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:convert';
88
import 'package:flutter_downloader/flutter_downloader.dart';
99
import 'package:path_provider/path_provider.dart';
1010
import 'package:permission_handler/permission_handler.dart';
11+
import 'package:open_file/open_file.dart';
1112

1213
class UpdatePage extends StatefulWidget {
1314
@override
@@ -19,25 +20,41 @@ class _UpdatePageState extends State<UpdatePage> {
1920
void initState() {
2021
super.initState();
2122
FlutterDownloader.registerCallback((id, status, progress) async {
23+
setState(() {
24+
_currProgress = progress;
25+
});
2226
print(
2327
"id:${id}===== status=======:${status}=====progress======:${progress}");
2428
// 当下载完成时,调用安装
2529
if (status == DownloadTaskStatus.complete) {
30+
31+
OpenFile.open(_localPath);
2632
FlutterDownloader.open(taskId: id);
33+
2734
}
2835
});
29-
_permissisonReady=false;
36+
_permissisonReady = false;
3037
_prepare();
3138
}
3239

3340
bool _isLoading;
3441
bool _permissisonReady;
3542
String _localPath;
43+
int _currProgress = 0;
3644

3745
@override
3846
Widget build(BuildContext context) {
3947
return Column(
4048
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+
),
4158
Center(
4259
child: Text("现在是1.0.0",
4360
textAlign: TextAlign.center, style: TextStyle(fontSize: 20)),
@@ -48,7 +65,7 @@ class _UpdatePageState extends State<UpdatePage> {
4865
print("点击${_permissisonReady}");
4966
if (_permissisonReady) {
5067
_requestDownload();
51-
}else{
68+
} else {
5269
_checkPermission().then((hasGranted) {
5370
setState(() {
5471
_permissisonReady = hasGranted;
@@ -62,14 +79,13 @@ class _UpdatePageState extends State<UpdatePage> {
6279
),
6380
color: Colors.red[800],
6481
),
65-
)
82+
),
6683
],
6784
);
6885
}
6986

7087
Future<Null> _prepare() async {
7188
_permissisonReady = await _checkPermission();
72-
_localPath = (await _findLocalPath()) + '/Download';
7389
}
7490

7591
//检查权限
@@ -115,6 +131,7 @@ class _UpdatePageState extends State<UpdatePage> {
115131
// 获取安装地址
116132
Future<String> get _apkLocalPath async {
117133
final directory = await getExternalStorageDirectory();
118-
return directory.path.toString();
134+
_localPath = directory.path.toString();
135+
return _localPath;
119136
}
120137
}

pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ packages:
193193
url: "https://pub.dartlang.org"
194194
source: hosted
195195
version: "1.1.6"
196+
open_file:
197+
dependency: "direct main"
198+
description:
199+
name: open_file
200+
url: "https://pub.dartlang.org"
201+
source: hosted
202+
version: "2.0.1+2"
196203
path:
197204
dependency: transitive
198205
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies:
4141
flutter_downloader: ^1.1.7
4242
path_provider: ^1.1.0
4343
permission_handler: ^3.0.0
44+
open_file: ^2.0.1+2
4445

4546
dev_dependencies:
4647
flutter_test:

0 commit comments

Comments
 (0)