mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-05-21 06:46:23 +08:00
add update version
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:core';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluro/fluro.dart';
|
||||
@ -37,15 +38,16 @@ class MyApp extends StatefulWidget {
|
||||
class _MyAppState extends State<MyApp> {
|
||||
bool _hasLogin = false;
|
||||
bool _isLoading = true;
|
||||
String localVersion;
|
||||
String currVersion;
|
||||
|
||||
@override
|
||||
Future initState() {
|
||||
super.initState();
|
||||
|
||||
var platformAandroid =
|
||||
(Theme.of(context).platform == TargetPlatform.android);
|
||||
DataUtils.checkVersion({'name': 'FlutterGo'}).then((bool) {
|
||||
if (bool) {
|
||||
print("返回值back ${bool}");
|
||||
if (platformAandroid && bool) {
|
||||
setState(() {});
|
||||
_UpdateURL();
|
||||
}
|
||||
}).catchError((onError) {
|
||||
@ -66,6 +68,16 @@ class _MyAppState extends State<MyApp> {
|
||||
});
|
||||
}
|
||||
|
||||
_UpdateURL() async {
|
||||
const currUrl =
|
||||
'https://github.com/alibaba/flutter-go/raw/master/FlutterGo.apk';
|
||||
if (await canLaunch(currUrl)) {
|
||||
await launch(currUrl);
|
||||
} else {
|
||||
throw 'Could not launch $currUrl';
|
||||
}
|
||||
}
|
||||
|
||||
showWelcomePage() {
|
||||
if (_isLoading) {
|
||||
return Container(
|
||||
@ -84,16 +96,6 @@ class _MyAppState extends State<MyApp> {
|
||||
}
|
||||
}
|
||||
|
||||
_UpdateURL() async {
|
||||
const currUrl =
|
||||
'https://github.com/alibaba/flutter-go/raw/master/FlutterGo.apk';
|
||||
if (await canLaunch(currUrl)) {
|
||||
await launch(currUrl);
|
||||
} else {
|
||||
throw 'Could not launch $currUrl';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new MaterialApp(
|
||||
|
@ -2,6 +2,7 @@ import 'dart:async' show Future;
|
||||
|
||||
import 'package:flutter_go/model/version.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import './net_utils.dart';
|
||||
import '../model/user_info.dart';
|
||||
@ -38,18 +39,15 @@ class DataUtils {
|
||||
var response = await NetUtils.get(Api.VERSION, params);
|
||||
Version version = Version.formJson(response);
|
||||
var currVersion = version.data.version;
|
||||
PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
var localVersion = packageInfo.version;
|
||||
//0:相同、1:大于、-1:小于
|
||||
//currVersion: 1.0.6 // localVersion:0.0.2 //packbuildNumber 1 true
|
||||
//currVersion: 1.0.6 // localVersion:2.0.2 //packbuildNumber -1 false
|
||||
//相同=0、大于=1、小于=-1
|
||||
// localVersion = '0.0.2';
|
||||
// currVersion = '1.0.6';
|
||||
if (currVersion.compareTo(localVersion) == 1) {
|
||||
print('currVersion: true');
|
||||
return true;
|
||||
} else {
|
||||
print('currVersion: flase');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
|
||||
"name": "FlutterGo",
|
||||
|
||||
"version": "1.0.3"
|
||||
|
||||
}
|
Reference in New Issue
Block a user