mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-08-06 17:48:43 +08:00
test
This commit is contained in:
@ -8,6 +8,7 @@ import 'dart:convert';
|
|||||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:open_file/open_file.dart';
|
||||||
|
|
||||||
class UpdatePage extends StatefulWidget {
|
class UpdatePage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@ -19,25 +20,41 @@ class _UpdatePageState extends State<UpdatePage> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
FlutterDownloader.registerCallback((id, status, progress) async {
|
FlutterDownloader.registerCallback((id, status, progress) async {
|
||||||
|
setState(() {
|
||||||
|
_currProgress = progress;
|
||||||
|
});
|
||||||
print(
|
print(
|
||||||
"id:${id}===== status=======:${status}=====progress======:${progress}");
|
"id:${id}===== status=======:${status}=====progress======:${progress}");
|
||||||
// 当下载完成时,调用安装
|
// 当下载完成时,调用安装
|
||||||
if (status == DownloadTaskStatus.complete) {
|
if (status == DownloadTaskStatus.complete) {
|
||||||
|
|
||||||
|
OpenFile.open(_localPath);
|
||||||
FlutterDownloader.open(taskId: id);
|
FlutterDownloader.open(taskId: id);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_permissisonReady=false;
|
_permissisonReady = false;
|
||||||
_prepare();
|
_prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isLoading;
|
bool _isLoading;
|
||||||
bool _permissisonReady;
|
bool _permissisonReady;
|
||||||
String _localPath;
|
String _localPath;
|
||||||
|
int _currProgress = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
Container(
|
||||||
|
margin: EdgeInsets.only(top: 20),
|
||||||
|
width: double.infinity,
|
||||||
|
height: 10.0,
|
||||||
|
child: new LinearProgressIndicator(
|
||||||
|
value: _currProgress / 100,
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Text("现在是1.0.0",
|
child: Text("现在是1.0.0",
|
||||||
textAlign: TextAlign.center, style: TextStyle(fontSize: 20)),
|
textAlign: TextAlign.center, style: TextStyle(fontSize: 20)),
|
||||||
@ -48,7 +65,7 @@ class _UpdatePageState extends State<UpdatePage> {
|
|||||||
print("点击${_permissisonReady}");
|
print("点击${_permissisonReady}");
|
||||||
if (_permissisonReady) {
|
if (_permissisonReady) {
|
||||||
_requestDownload();
|
_requestDownload();
|
||||||
}else{
|
} else {
|
||||||
_checkPermission().then((hasGranted) {
|
_checkPermission().then((hasGranted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_permissisonReady = hasGranted;
|
_permissisonReady = hasGranted;
|
||||||
@ -62,14 +79,13 @@ class _UpdatePageState extends State<UpdatePage> {
|
|||||||
),
|
),
|
||||||
color: Colors.red[800],
|
color: Colors.red[800],
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Null> _prepare() async {
|
Future<Null> _prepare() async {
|
||||||
_permissisonReady = await _checkPermission();
|
_permissisonReady = await _checkPermission();
|
||||||
_localPath = (await _findLocalPath()) + '/Download';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//检查权限
|
//检查权限
|
||||||
@ -115,6 +131,7 @@ class _UpdatePageState extends State<UpdatePage> {
|
|||||||
// 获取安装地址
|
// 获取安装地址
|
||||||
Future<String> get _apkLocalPath async {
|
Future<String> get _apkLocalPath async {
|
||||||
final directory = await getExternalStorageDirectory();
|
final directory = await getExternalStorageDirectory();
|
||||||
return directory.path.toString();
|
_localPath = directory.path.toString();
|
||||||
|
return _localPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,6 +193,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.6"
|
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:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -41,6 +41,7 @@ dependencies:
|
|||||||
flutter_downloader: ^1.1.7
|
flutter_downloader: ^1.1.7
|
||||||
path_provider: ^1.1.0
|
path_provider: ^1.1.0
|
||||||
permission_handler: ^3.0.0
|
permission_handler: ^3.0.0
|
||||||
|
open_file: ^2.0.1+2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user