@@ -2,10 +2,15 @@ import 'dart:async';
22import 'dart:io' ;
33
44import 'package:dio/dio.dart' ;
5+ import 'package:fluttertoast/fluttertoast.dart' ;
6+ import 'package:get_version/get_version.dart' ;
7+ import 'package:gsy_github_app_flutter/common/config/Config.dart' ;
58import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart' ;
69import 'package:gsy_github_app_flutter/common/net/Address.dart' ;
710import 'package:gsy_github_app_flutter/common/net/Api.dart' ;
811import 'package:gsy_github_app_flutter/common/net/trending/GithubTrending.dart' ;
12+ import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart' ;
13+ import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart' ;
914import 'package:gsy_github_app_flutter/page/RepositoryFileListPage.dart' ;
1015import 'package:gsy_github_app_flutter/widget/EventItem.dart' ;
1116import 'package:gsy_github_app_flutter/widget/PushCoedItem.dart' ;
@@ -14,6 +19,7 @@ import 'package:gsy_github_app_flutter/widget/ReleaseItem.dart';
1419import 'package:gsy_github_app_flutter/widget/ReposHeaderItem.dart' ;
1520import 'package:gsy_github_app_flutter/widget/ReposItem.dart' ;
1621import 'package:gsy_github_app_flutter/widget/UserItem.dart' ;
22+ import 'package:pub_semver/pub_semver.dart' ;
1723
1824/**
1925 * Created by guoshuyu
@@ -448,4 +454,42 @@ class ReposDao {
448454 return new DataResult (null , false );
449455 }
450456 }
457+
458+ /**
459+ * 版本更新
460+ */
461+ static getNewsVersion (context, showTip) async {
462+ //ios不检查更新
463+ if (Platform .isIOS) {
464+ return ;
465+ }
466+ var res = await getRepositoryReleaseDao ("CarGuo" , 'GSYGithubAppFlutter' , 1 , needHtml: false );
467+ if (res != null && res.result && res.data.length > 0 ) {
468+ //github只能有release的versionName,没有code,囧
469+ String versionName = res.data[0 ].actionTitle;
470+ if (versionName != null ) {
471+ if (Config .DEBUG ) {
472+ print ("versionName " + versionName);
473+ }
474+ var appVersion = await GetVersion .projectVersion;
475+ if (Config .DEBUG ) {
476+ print ("appVersion " + appVersion);
477+ }
478+ Version versionNameNum = Version .parse (versionName);
479+ Version currentNum = Version .parse (appVersion);
480+ int result = versionNameNum.compareTo (currentNum);
481+ if (Config .DEBUG ) {
482+ print ("versionNameNum " + versionNameNum.toString () + " currentNum " + currentNum.toString ());
483+ }
484+ if (Config .DEBUG ) {
485+ print ("newsHad " + result.toString ());
486+ }
487+ if (result > 0 ) {
488+ CommonUtils .showUpdateDialog (context, res.data[0 ].actionTitle + ": " + res.data[0 ].body);
489+ } else {
490+ if (showTip) Fluttertoast .showToast (msg: GSYStrings .app_not_new_version);
491+ }
492+ }
493+ }
494+ }
451495}
0 commit comments