Commit d43abb8c29044813ce45030fb094e948dd3dbe09

Authored by gaiyaguang
1 parent 46f3e142

flutter2.0 版本更新

@@ -6,9 +6,6 @@ PODS: @@ -6,9 +6,6 @@ PODS:
6 - Reachability 6 - Reachability
7 - connectivity_macos (0.0.1): 7 - connectivity_macos (0.0.1):
8 - Flutter 8 - Flutter
9 - - fake_push (0.0.1):  
10 - - Flutter  
11 - - QQ_XGPush (~> 3.3.7)  
12 - Flutter (1.0.0) 9 - Flutter (1.0.0)
13 - flutter_statusbarcolor (0.0.1): 10 - flutter_statusbarcolor (0.0.1):
14 - Flutter 11 - Flutter
@@ -20,6 +17,8 @@ PODS: @@ -20,6 +17,8 @@ PODS:
20 - FMDB (2.7.5): 17 - FMDB (2.7.5):
21 - FMDB/standard (= 2.7.5) 18 - FMDB/standard (= 2.7.5)
22 - FMDB/standard (2.7.5) 19 - FMDB/standard (2.7.5)
  20 + - install_plugin (0.0.1):
  21 + - Flutter
23 - JCore (2.2.5) 22 - JCore (2.2.5)
24 - JPush (3.3.2): 23 - JPush (3.3.2):
25 - JCore (< 3.0.0, >= 2.0.0) 24 - JCore (< 3.0.0, >= 2.0.0)
@@ -32,7 +31,6 @@ PODS: @@ -32,7 +31,6 @@ PODS:
32 - Flutter 31 - Flutter
33 - permission_handler (4.4.0): 32 - permission_handler (4.4.0):
34 - Flutter 33 - Flutter
35 - - QQ_XGPush (3.3.7)  
36 - Reachability (3.2) 34 - Reachability (3.2)
37 - shared_preferences (0.0.1): 35 - shared_preferences (0.0.1):
38 - Flutter 36 - Flutter
@@ -55,11 +53,11 @@ DEPENDENCIES: @@ -55,11 +53,11 @@ DEPENDENCIES:
55 - audioplayers (from `.symlinks/plugins/audioplayers/ios`) 53 - audioplayers (from `.symlinks/plugins/audioplayers/ios`)
56 - connectivity (from `.symlinks/plugins/connectivity/ios`) 54 - connectivity (from `.symlinks/plugins/connectivity/ios`)
57 - connectivity_macos (from `.symlinks/plugins/connectivity_macos/ios`) 55 - connectivity_macos (from `.symlinks/plugins/connectivity_macos/ios`)
58 - - fake_push (from `.symlinks/plugins/fake_push/ios`)  
59 - Flutter (from `Flutter`) 56 - Flutter (from `Flutter`)
60 - flutter_statusbarcolor (from `.symlinks/plugins/flutter_statusbarcolor/ios`) 57 - flutter_statusbarcolor (from `.symlinks/plugins/flutter_statusbarcolor/ios`)
61 - fluttertoast (from `.symlinks/plugins/fluttertoast/ios`) 58 - fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
62 - fluwx (from `.symlinks/plugins/fluwx/ios`) 59 - fluwx (from `.symlinks/plugins/fluwx/ios`)
  60 + - install_plugin (from `.symlinks/plugins/install_plugin/ios`)
63 - jpush_flutter (from `.symlinks/plugins/jpush_flutter/ios`) 61 - jpush_flutter (from `.symlinks/plugins/jpush_flutter/ios`)
64 - path_provider (from `.symlinks/plugins/path_provider/ios`) 62 - path_provider (from `.symlinks/plugins/path_provider/ios`)
65 - path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`) 63 - path_provider_macos (from `.symlinks/plugins/path_provider_macos/ios`)
@@ -77,7 +75,6 @@ SPEC REPOS: @@ -77,7 +75,6 @@ SPEC REPOS:
77 - FMDB 75 - FMDB
78 - JCore 76 - JCore
79 - JPush 77 - JPush
80 - - QQ_XGPush  
81 - Reachability 78 - Reachability
82 - WechatOpenSDK 79 - WechatOpenSDK
83 80
@@ -88,8 +85,6 @@ EXTERNAL SOURCES: @@ -88,8 +85,6 @@ EXTERNAL SOURCES:
88 :path: ".symlinks/plugins/connectivity/ios" 85 :path: ".symlinks/plugins/connectivity/ios"
89 connectivity_macos: 86 connectivity_macos:
90 :path: ".symlinks/plugins/connectivity_macos/ios" 87 :path: ".symlinks/plugins/connectivity_macos/ios"
91 - fake_push:  
92 - :path: ".symlinks/plugins/fake_push/ios"  
93 Flutter: 88 Flutter:
94 :path: Flutter 89 :path: Flutter
95 flutter_statusbarcolor: 90 flutter_statusbarcolor:
@@ -98,6 +93,8 @@ EXTERNAL SOURCES: @@ -98,6 +93,8 @@ EXTERNAL SOURCES:
98 :path: ".symlinks/plugins/fluttertoast/ios" 93 :path: ".symlinks/plugins/fluttertoast/ios"
99 fluwx: 94 fluwx:
100 :path: ".symlinks/plugins/fluwx/ios" 95 :path: ".symlinks/plugins/fluwx/ios"
  96 + install_plugin:
  97 + :path: ".symlinks/plugins/install_plugin/ios"
101 jpush_flutter: 98 jpush_flutter:
102 :path: ".symlinks/plugins/jpush_flutter/ios" 99 :path: ".symlinks/plugins/jpush_flutter/ios"
103 path_provider: 100 path_provider:
@@ -125,19 +122,18 @@ SPEC CHECKSUMS: @@ -125,19 +122,18 @@ SPEC CHECKSUMS:
125 audioplayers: 84f968cea3f2deab00ec4f8ff53358b3c0b3992c 122 audioplayers: 84f968cea3f2deab00ec4f8ff53358b3c0b3992c
126 connectivity: 6e94255659cc86dcbef1d452ad3e0491bb1b3e75 123 connectivity: 6e94255659cc86dcbef1d452ad3e0491bb1b3e75
127 connectivity_macos: e2e9731b6b22dda39eb1b128f6969d574460e191 124 connectivity_macos: e2e9731b6b22dda39eb1b128f6969d574460e191
128 - fake_push: 4910f18f47de46b488f01ba99c64ee92df1e8d62  
129 Flutter: 0e3d915762c693b495b44d77113d4970485de6ec 125 Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
130 flutter_statusbarcolor: 8afb1071ed8c58be929f1e32b36c629771fd2259 126 flutter_statusbarcolor: 8afb1071ed8c58be929f1e32b36c629771fd2259
131 fluttertoast: b644586ef3b16f67fae9a1f8754cef6b2d6b634b 127 fluttertoast: b644586ef3b16f67fae9a1f8754cef6b2d6b634b
132 fluwx: 03e098a7284c556d7b197e0b82984eb0b25183af 128 fluwx: 03e098a7284c556d7b197e0b82984eb0b25183af
133 FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a 129 FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
  130 + install_plugin: a13e7ddd2bab0c701b48cd359c26d0394125b6fb
134 JCore: d75c0306dc99875d323d23e5a063b3a3ef22335a 131 JCore: d75c0306dc99875d323d23e5a063b3a3ef22335a
135 JPush: 9468c84a3809dc3ac2fc1c89c6d1d6c858a91bf5 132 JPush: 9468c84a3809dc3ac2fc1c89c6d1d6c858a91bf5
136 jpush_flutter: 69133df35eaf9135e540549b154d992c44f8ee44 133 jpush_flutter: 69133df35eaf9135e540549b154d992c44f8ee44
137 path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d 134 path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d
138 path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0 135 path_provider_macos: f760a3c5b04357c380e2fddb6f9db6f3015897e0
139 permission_handler: f615215121f43c1640d2b8500d4ad749512828a8 136 permission_handler: f615215121f43c1640d2b8500d4ad749512828a8
140 - QQ_XGPush: b3b7065cd0b11490974e3b33a24bf6803e7f9392  
141 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 137 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
142 shared_preferences: 430726339841afefe5142b9c1f50cb6bd7793e01 138 shared_preferences: 430726339841afefe5142b9c1f50cb6bd7793e01
143 shared_preferences_macos: f3f29b71ccbb56bf40c9dd6396c9acf15e214087 139 shared_preferences_macos: f3f29b71ccbb56bf40c9dd6396c9acf15e214087
  1 +/**
  2 + * 更新版本
  3 + */
  4 +class Version{
  5 + String version;//更新版本号
  6 + String file_url;//安装包下载地址
  7 + String content;//更新内容
  8 +
  9 + Version();
  10 +
  11 + factory Version.fromJson(Map<String,dynamic> json)=>Version()..version=json["version"]..file_url=json["file_url"]..content=json["content"];
  12 +
  13 + Map<String,dynamic> toJson()=><String,dynamic>{"version":version,"file_url":file_url,"content":content};
  14 +}
@@ -14,6 +14,7 @@ import 'package:one_key/provider/message_dialog_model.dart'; @@ -14,6 +14,7 @@ import 'package:one_key/provider/message_dialog_model.dart';
14 import 'package:one_key/provider/message_model.dart'; 14 import 'package:one_key/provider/message_model.dart';
15 import 'package:one_key/provider/my_model.dart'; 15 import 'package:one_key/provider/my_model.dart';
16 import 'package:one_key/provider/notebook_model.dart'; 16 import 'package:one_key/provider/notebook_model.dart';
  17 +import 'package:one_key/provider/update_model.dart';
17 import 'package:one_key/provider/user_model.dart'; 18 import 'package:one_key/provider/user_model.dart';
18 import 'package:one_key/res/colors.dart'; 19 import 'package:one_key/res/colors.dart';
19 import 'package:one_key/utils/log_util.dart'; 20 import 'package:one_key/utils/log_util.dart';
@@ -78,9 +79,12 @@ class HomePageState extends State<HomePage>{ @@ -78,9 +79,12 @@ class HomePageState extends State<HomePage>{
78 WidgetsBinding.instance.addPostFrameCallback((_){ 79 WidgetsBinding.instance.addPostFrameCallback((_){
79 if(widget.initialIndex==0)return; 80 if(widget.initialIndex==0)return;
80 getUntreatedMessage(); 81 getUntreatedMessage();
  82 + UpdateModel updateModel=new UpdateModel();
  83 + updateModel.checkUpdate(context);
81 }); 84 });
82 } 85 }
83 86
  87 +
84 Future<void> initJPush() async { 88 Future<void> initJPush() async {
85 try { 89 try {
86 jpush.addEventHandler( 90 jpush.addEventHandler(
@@ -3,6 +3,7 @@ import 'package:flutter_easyrefresh/easy_refresh.dart'; @@ -3,6 +3,7 @@ import 'package:flutter_easyrefresh/easy_refresh.dart';
3 import 'package:flutter_screenutil/flutter_screenutil.dart'; 3 import 'package:flutter_screenutil/flutter_screenutil.dart';
4 import 'package:one_key/pages/notebook/notebook_item_widget.dart'; 4 import 'package:one_key/pages/notebook/notebook_item_widget.dart';
5 import 'package:one_key/provider/notebook_model.dart'; 5 import 'package:one_key/provider/notebook_model.dart';
  6 +import 'package:one_key/provider/update_model.dart';
6 import 'package:one_key/provider/user_model.dart'; 7 import 'package:one_key/provider/user_model.dart';
7 import 'package:one_key/res/colors.dart'; 8 import 'package:one_key/res/colors.dart';
8 import 'package:one_key/utils/dialog_util.dart'; 9 import 'package:one_key/utils/dialog_util.dart';
  1 +
  2 +import 'dart:io';
  3 +import 'dart:math';
  4 +
  5 +import 'package:flutter/material.dart';
  6 +import 'package:flutter_screenutil/flutter_screenutil.dart';
  7 +import 'package:install_plugin/install_plugin.dart';
  8 +import 'package:one_key/models/version.dart';
  9 +import 'package:one_key/net/dio_util.dart';
  10 +import 'package:one_key/res/colors.dart';
  11 +import 'package:path_provider/path_provider.dart';
  12 +import 'package:permission_handler/permission_handler.dart';
  13 +
  14 +class UpdateModel{
  15 +
  16 + int _progress;//下载进度
  17 + Function _setState;
  18 + //检查更新
  19 + Future<Version> checkUpdate(BuildContext context){
  20 + Future.delayed(new Duration(milliseconds: 1000),(){
  21 + if(Random().nextInt(10)>0){
  22 + Version version=Version.fromJson({
  23 + "version":"v1.0.3",
  24 + "file_url":"http://xt03.colorcun.com/uploads/20191105/67e38355c41528b24a97e9ac71a221ea.apk",
  25 + "content":"1.bug修复;\n2.功能更新;"
  26 + });
  27 + showUpdateDialog(context, version);
  28 + }
  29 + });
  30 + }
  31 +
  32 + //拒绝订单弹框
  33 + showUpdateDialog(BuildContext context,Version version){
  34 + showDialog(context: context,builder: (context){
  35 + return AlertDialog(
  36 + title: Text("版本更新${version.version}"),
  37 + titleTextStyle: TextStyle(color: MyColours.color_353535,fontSize: ScreenUtil().setSp(32)),
  38 + content: Text("${version.content}"),
  39 + contentTextStyle:TextStyle(color: MyColours.color_828282,fontSize: ScreenUtil().setSp(28)),
  40 + actions: <Widget>[
  41 + FlatButton(
  42 + child: Text("取消",style: TextStyle(fontSize: ScreenUtil().setSp(32)),),
  43 + onPressed: (){
  44 + Navigator.of(context).pop();
  45 + },
  46 + ),
  47 + FlatButton(
  48 + child: Text("去更新",style: TextStyle(fontSize: ScreenUtil().setSp(32)),),
  49 + onPressed: () async {
  50 + Navigator.of(context).pop();
  51 + if(Platform.isAndroid){
  52 + downloadApk(context,version.file_url);
  53 + }else{
  54 + InstallPlugin.gotoAppStore("itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1510697490");
  55 + }
  56 + },
  57 + )
  58 + ],
  59 + );
  60 + });
  61 + }
  62 +
  63 + //下载更新版本
  64 + Future<void> downloadApk(BuildContext context,String file_url) async {
  65 + Map<PermissionGroup, PermissionStatus> permissions =
  66 + await PermissionHandler().requestPermissions([PermissionGroup.storage]);
  67 + if(permissions[PermissionGroup.storage] == PermissionStatus.granted){
  68 + final dir=await getExternalStorageDirectory();
  69 + String savePath=dir.path+"/one_key";
  70 + DioUtil().download(file_url, savePath,onProgress: (received,total){
  71 + int progress=((received/total)*100).round();
  72 + _progress=progress;
  73 + _setState((){});
  74 + if(received==total){//下载完成
  75 + InstallPlugin.installApk(savePath,"com.naji.one_key");
  76 + }
  77 + });
  78 + }
  79 + }
  80 +
  81 + //显示下载进度条
  82 + Function showDownloadProgress(BuildContext context){
  83 + showDialog(
  84 + context: context,
  85 + barrierDismissible: false,
  86 + builder: (context) {
  87 + return AlertDialog(
  88 + content: StatefulBuilder(builder: (context, setState) {
  89 + if(_progress==100){
  90 + Navigator.of(context).pop();
  91 +
  92 + }
  93 + _setState=setState;
  94 + return Column(
  95 + mainAxisSize: MainAxisSize.min,
  96 + children: <Widget>[
  97 + CircularProgressIndicator(),
  98 + Padding(
  99 + padding: EdgeInsets.only(top: 26),
  100 + child: Text("正在下载...${_progress}%"),
  101 + )
  102 + ],
  103 + );
  104 + }));
  105 + });
  106 + return _setState;
  107 + }
  108 +}
@@ -366,6 +366,13 @@ packages: @@ -366,6 +366,13 @@ packages:
366 url: "https://pub.flutter-io.cn" 366 url: "https://pub.flutter-io.cn"
367 source: hosted 367 source: hosted
368 version: "2.1.4" 368 version: "2.1.4"
  369 + install_plugin:
  370 + dependency: "direct main"
  371 + description:
  372 + name: install_plugin
  373 + url: "https://pub.flutter-io.cn"
  374 + source: hosted
  375 + version: "2.0.1"
369 intl: 376 intl:
370 dependency: transitive 377 dependency: transitive
371 description: 378 description:
@@ -73,6 +73,8 @@ dependencies: @@ -73,6 +73,8 @@ dependencies:
73 connectivity: ^0.4.8 73 connectivity: ^0.4.8
74 # 信鸽推送 74 # 信鸽推送
75 # fake_push: ^0.5.4 75 # fake_push: ^0.5.4
  76 + # 安装apk
  77 + install_plugin: ^2.0.1
76 78
77 dev_dependencies: 79 dev_dependencies:
78 flutter_test: 80 flutter_test: