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