mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-07-04 15:28:21 +08:00
迭代测试
This commit is contained in:
@ -35,5 +35,32 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
|
||||||
|
android:authorities="${applicationId}.flutter_downloader.provider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/provider_paths"/>
|
||||||
|
</provider>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.work.impl.WorkManagerInitializer"
|
||||||
|
android:authorities="${applicationId}.workmanager-init"
|
||||||
|
android:enabled="false"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="vn.hunghd.flutterdownloader.FlutterDownloaderInitializer"
|
||||||
|
android:authorities="${applicationId}.flutter-downloader-init"
|
||||||
|
android:exported="false">
|
||||||
|
<meta-data
|
||||||
|
android:name="vn.hunghd.flutterdownloader.MAX_CONCURRENT_TASKS"
|
||||||
|
android:value="5" />
|
||||||
|
</provider>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -10,6 +10,7 @@ import 'package:flutter/rendering.dart';
|
|||||||
import 'package:flutter_go/utils/shared_preferences.dart';
|
import 'package:flutter_go/utils/shared_preferences.dart';
|
||||||
import 'package:flutter_go/views/first_page/first_page.dart';
|
import 'package:flutter_go/views/first_page/first_page.dart';
|
||||||
import 'package:flutter_go/views/first_page/main_page.dart';
|
import 'package:flutter_go/views/first_page/main_page.dart';
|
||||||
|
import 'package:flutter_go/views/update_test.dart';
|
||||||
import 'package:flutter_go/views/widget_page/widget_page.dart';
|
import 'package:flutter_go/views/widget_page/widget_page.dart';
|
||||||
import 'package:flutter_go/views/welcome_page/fourth_page.dart';
|
import 'package:flutter_go/views/welcome_page/fourth_page.dart';
|
||||||
import 'package:flutter_go/views/collection_page/collection_page.dart';
|
import 'package:flutter_go/views/collection_page/collection_page.dart';
|
||||||
@ -24,6 +25,7 @@ import 'package:flutter_go/resources/widget_name_to_icon.dart';
|
|||||||
const int ThemeColor = 0xFFC91B3A;
|
const int ThemeColor = 0xFFC91B3A;
|
||||||
|
|
||||||
class AppPage extends StatefulWidget {
|
class AppPage extends StatefulWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() {
|
State<StatefulWidget> createState() {
|
||||||
return _MyHomePageState();
|
return _MyHomePageState();
|
||||||
@ -32,6 +34,7 @@ class AppPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _MyHomePageState extends State<AppPage>
|
class _MyHomePageState extends State<AppPage>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
|
|
||||||
SpUtil sp;
|
SpUtil sp;
|
||||||
WidgetControlModel widgetControl = new WidgetControlModel();
|
WidgetControlModel widgetControl = new WidgetControlModel();
|
||||||
SearchHistoryList searchHistoryList;
|
SearchHistoryList searchHistoryList;
|
||||||
@ -44,7 +47,7 @@ class _MyHomePageState extends State<AppPage>
|
|||||||
{'text': 'WIDGET', 'icon': Icon(Icons.extension)},
|
{'text': 'WIDGET', 'icon': Icon(Icons.extension)},
|
||||||
{'text': '组件收藏', 'icon': Icon(Icons.favorite)},
|
{'text': '组件收藏', 'icon': Icon(Icons.favorite)},
|
||||||
{'text': '关于手册', 'icon': Icon(Icons.import_contacts)},
|
{'text': '关于手册', 'icon': Icon(Icons.import_contacts)},
|
||||||
// {'text': '点击更新', 'icon': Icon(Icons.update)}
|
{'text': '点击更新', 'icon': Icon(Icons.update)}
|
||||||
];
|
];
|
||||||
|
|
||||||
List<BottomNavigationBarItem> myTabs = [];
|
List<BottomNavigationBarItem> myTabs = [];
|
||||||
@ -67,8 +70,10 @@ class _MyHomePageState extends State<AppPage>
|
|||||||
..add(MainPage())
|
..add(MainPage())
|
||||||
..add(WidgetPage(Provider.db))
|
..add(WidgetPage(Provider.db))
|
||||||
..add(CollectionPage())
|
..add(CollectionPage())
|
||||||
..add(FourthPage());
|
..add(FourthPage())
|
||||||
// ..add(FourthPage());
|
..add(UpdatePage(
|
||||||
|
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -120,9 +125,9 @@ class _MyHomePageState extends State<AppPage>
|
|||||||
}, (value) {}, () {});
|
}, (value) {}, () {});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderAppBar(BuildContext context,Widget widget,int index) {
|
renderAppBar(BuildContext context, Widget widget, int index) {
|
||||||
print('renderAppBar=====>>>>>>${index}');
|
print('renderAppBar=====>>>>>>${index}');
|
||||||
if(index == 0) {
|
if (index == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return AppBar(title: buildSearchInput(context));
|
return AppBar(title: buildSearchInput(context));
|
||||||
@ -131,7 +136,7 @@ class _MyHomePageState extends State<AppPage>
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Scaffold(
|
return new Scaffold(
|
||||||
appBar: renderAppBar(context,widget,_currentIndex),
|
appBar: renderAppBar(context, widget, _currentIndex),
|
||||||
body: list[_currentIndex],
|
body: list[_currentIndex],
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
items: myTabs,
|
items: myTabs,
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_go/blocs/bak/search_api.dart';
|
import 'package:flutter_go/blocs/bak/search_api.dart';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
class UpdatePage extends StatefulWidget {
|
class UpdatePage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@ -8,6 +15,25 @@ class UpdatePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _UpdatePageState extends State<UpdatePage> {
|
class _UpdatePageState extends State<UpdatePage> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
FlutterDownloader.registerCallback((id, status, progress) async {
|
||||||
|
print(
|
||||||
|
"id:${id}===== status=======:${status}=====progress======:${progress}");
|
||||||
|
// 当下载完成时,调用安装
|
||||||
|
if (status == DownloadTaskStatus.complete) {
|
||||||
|
FlutterDownloader.open(taskId: id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_permissisonReady=false;
|
||||||
|
_prepare();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _isLoading;
|
||||||
|
bool _permissisonReady;
|
||||||
|
String _localPath;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
@ -19,8 +45,16 @@ class _UpdatePageState extends State<UpdatePage> {
|
|||||||
Center(
|
Center(
|
||||||
child: FlatButton(
|
child: FlatButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
print("点击");
|
print("点击${_permissisonReady}");
|
||||||
_UpdatePageNet();
|
if (_permissisonReady) {
|
||||||
|
_requestDownload();
|
||||||
|
}else{
|
||||||
|
_checkPermission().then((hasGranted) {
|
||||||
|
setState(() {
|
||||||
|
_permissisonReady = hasGranted;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
"点击获取新版本",
|
"点击获取新版本",
|
||||||
@ -33,8 +67,54 @@ class _UpdatePageState extends State<UpdatePage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _UpdatePageNet() async {
|
Future<Null> _prepare() async {
|
||||||
Response response = await dio.get("https://github.com/alibaba/flutter-go/raw/master/FlutterGo.apk");
|
_permissisonReady = await _checkPermission();
|
||||||
print("=====response============="+response.data);
|
_localPath = (await _findLocalPath()) + '/Download';
|
||||||
|
}
|
||||||
|
|
||||||
|
//检查权限
|
||||||
|
Future<bool> _checkPermission() async {
|
||||||
|
if (Theme.of(context).platform == TargetPlatform.android) {
|
||||||
|
PermissionStatus permission = await PermissionHandler()
|
||||||
|
.checkPermissionStatus(PermissionGroup.storage);
|
||||||
|
if (permission != PermissionStatus.granted) {
|
||||||
|
Map<PermissionGroup, PermissionStatus> permissions =
|
||||||
|
await PermissionHandler()
|
||||||
|
.requestPermissions([PermissionGroup.storage]);
|
||||||
|
if (permissions[PermissionGroup.storage] == PermissionStatus.granted) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _requestDownload() async {
|
||||||
|
final path = await _apkLocalPath;
|
||||||
|
final taskId = await FlutterDownloader.enqueue(
|
||||||
|
url: 'https://github.com/alibaba/flutter-go/raw/master/FlutterGo.apk',
|
||||||
|
savedDir: path,
|
||||||
|
showNotification: true,
|
||||||
|
// show download progress in status bar (for Android)
|
||||||
|
openFileFromNotification:
|
||||||
|
true, // click on notification to open downloaded file (for Android)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future _findLocalPath() async {
|
||||||
|
final directory = Theme.of(context).platform == TargetPlatform.android
|
||||||
|
? await getExternalStorageDirectory()
|
||||||
|
: await getApplicationDocumentsDirectory();
|
||||||
|
return directory.path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取安装地址
|
||||||
|
Future<String> get _apkLocalPath async {
|
||||||
|
final directory = await getExternalStorageDirectory();
|
||||||
|
return directory.path.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
pubspec.lock
21
pubspec.lock
@ -118,6 +118,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.11.1"
|
version: "0.11.1"
|
||||||
|
flutter_downloader:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_downloader
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.7"
|
||||||
flutter_markdown:
|
flutter_markdown:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -193,6 +200,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.6.2"
|
version: "1.6.2"
|
||||||
|
path_provider:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: path_provider
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.0"
|
||||||
pedantic:
|
pedantic:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -200,6 +214,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.0"
|
version: "1.4.0"
|
||||||
|
permission_handler:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: permission_handler
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.0.1"
|
||||||
quiver:
|
quiver:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -38,6 +38,9 @@ dependencies:
|
|||||||
flutter_bloc: ^0.11.1
|
flutter_bloc: ^0.11.1
|
||||||
bloc: ^0.12.0
|
bloc: ^0.12.0
|
||||||
html: ^0.14.0+2
|
html: ^0.14.0+2
|
||||||
|
flutter_downloader: ^1.1.7
|
||||||
|
path_provider: ^1.1.0
|
||||||
|
permission_handler: ^3.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user