From c5130fc061cf234f4aa755b0abd392c68420cc03 Mon Sep 17 00:00:00 2001 From: "xj.deng" Date: Tue, 14 May 2019 14:18:57 +0800 Subject: [PATCH] update version --- lib/main.dart | 19 +++++++++++------- lib/views/update_test.dart | 41 ++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 5c6a8c1f..14bf1543 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,14 +16,20 @@ SpUtil sp; var db; class MyApp extends StatelessWidget { - MyApp() { + MyApp() { final router = new Router(); Routes.configureRoutes(router); Application.router = router; } - showWelcomePage() { + + showWelcomePage(context) { + //网络请求查看版本 + + + final platform = Theme.of(context).platform; + print("platform:${platform}"); // 暂时关掉欢迎介绍 return AppPage(); // bool showWelcome = sp.getBool(SharedPreferencesKeys.showWelcome); @@ -33,6 +39,7 @@ class MyApp extends StatelessWidget { // return AppPage(); // } } + @override Widget build(BuildContext context) { return new MaterialApp( @@ -50,17 +57,15 @@ class MyApp extends StatelessWidget { size: 35.0, ), ), - home: new Scaffold( - body: showWelcomePage() - ), - debugShowCheckedModeBanner: false, + home: new Scaffold(body: showWelcomePage(context)), + //debug banner +// debugShowCheckedModeBanner: false, onGenerateRoute: Application.router.generator, navigatorObservers: [Analytics.observer], ); } } - void main() async { final provider = new Provider(); await provider.init(true); diff --git a/lib/views/update_test.dart b/lib/views/update_test.dart index 70c8d00e..ab7acea9 100644 --- a/lib/views/update_test.dart +++ b/lib/views/update_test.dart @@ -9,6 +9,7 @@ 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'; +import 'package:url_launcher/url_launcher.dart'; class UpdatePage extends StatefulWidget { @override @@ -16,6 +17,9 @@ class UpdatePage extends StatefulWidget { } class _UpdatePageState extends State { + static const currUrl = + 'https://github.com/alibaba/flutter-go/raw/master/FlutterGo.apk'; + @override void initState() { super.initState(); @@ -27,10 +31,8 @@ class _UpdatePageState extends State { "id:${id}===== status=======:${status}=====progress======:${progress}"); // 当下载完成时,调用安装 if (status == DownloadTaskStatus.complete) { - OpenFile.open(_localPath); FlutterDownloader.open(taskId: id); - } }); _permissisonReady = false; @@ -80,10 +82,31 @@ class _UpdatePageState extends State { color: Colors.red[800], ), ), + Center( + child: FlatButton( + onPressed: () { + print("local===: _UpdateURL"); + _UpdateURL(); + }, + child: Text( + "更新版本", + style: TextStyle(color: Colors.white), + ), + color: Colors.red[800], + ), + ), ], ); } + _UpdateURL() async { + if (await canLaunch(currUrl)) { + await launch(currUrl); + } else { + throw 'Could not launch $currUrl'; + } + } + Future _prepare() async { _permissisonReady = await _checkPermission(); } @@ -112,7 +135,8 @@ class _UpdatePageState extends State { void _requestDownload() async { final path = await _apkLocalPath; final taskId = await FlutterDownloader.enqueue( - url: 'https://github.com/alibaba/flutter-go/raw/master/FlutterGo.apk', + url: currUrl, + fileName: "new_FlutterGo.apk", savedDir: path, showNotification: true, // show download progress in status bar (for Android) @@ -121,15 +145,12 @@ class _UpdatePageState extends State { ); } - Future _findLocalPath() async { - final directory = Theme.of(context).platform == TargetPlatform.android - ? await getExternalStorageDirectory() - : await getApplicationDocumentsDirectory(); - return directory.path; - } - // 获取安装地址 Future get _apkLocalPath async { +// final directory = widget.platform == TargetPlatform.android +// ? await getExternalStorageDirectory() +// : await getApplicationDocumentsDirectory(); + final directory = await getExternalStorageDirectory(); _localPath = directory.path.toString(); return _localPath;