diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 9620d25..b193cbd 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -31,7 +31,6 @@ - diff --git a/assets/images/cardbg1.png b/assets/images/cardbg1.png new file mode 100644 index 0000000..f7c2e76 Binary files /dev/null and b/assets/images/cardbg1.png differ diff --git a/lib/constants/api.dart b/lib/constants/api.dart index ba9eb3d..12b0692 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -58,7 +58,7 @@ class _App { ///版本更新 String get updateSelect =>'/app/update/select'; - ///ban + ///版本添加 String get updateAdd => '/manage/update/add'; } diff --git a/lib/model/update_model.dart b/lib/model/update_model.dart new file mode 100644 index 0000000..1086f93 --- /dev/null +++ b/lib/model/update_model.dart @@ -0,0 +1,40 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:equatable/equatable.dart'; + +part 'update_model.g.dart'; + +@JsonSerializable() +class UpdateModel extends Equatable { + final int updateStatus; + final int versionCode; + final String versionName; + final String modifyContent; + final String downloadUrl; + final String apkSize; + final String apkMd5; + + factory UpdateModel.fromJson(Map json) => + _$UpdateModelFromJson(json); + + + const UpdateModel({ + required this.updateStatus, + required this.versionCode, + required this.versionName, + required this.modifyContent, + required this.downloadUrl, + required this.apkSize, + required this.apkMd5, + }); + + @override + List get props => [ + updateStatus, + versionCode, + versionName, + modifyContent, + downloadUrl, + apkSize, + apkMd5, + ]; +} diff --git a/lib/model/update_model.g.dart b/lib/model/update_model.g.dart new file mode 100644 index 0000000..75caa58 --- /dev/null +++ b/lib/model/update_model.g.dart @@ -0,0 +1,17 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'update_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +UpdateModel _$UpdateModelFromJson(Map json) => UpdateModel( + updateStatus: json['updateStatus'] as int, + versionCode: json['versionCode'] as int, + versionName: json['versionName'] as String, + modifyContent: json['modifyContent'] as String, + downloadUrl: json['downloadUrl'] as String, + apkSize: json['apkSize'] as String, + apkMd5: json['apkMd5'] as String, + ); diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 3db1310..23e1441 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -1,16 +1,18 @@ import 'dart:async'; import 'package:bot_toast/bot_toast.dart'; + import 'package:flutter/material.dart'; import 'package:flutter_background_service/flutter_background_service.dart'; -import 'package:flutter_xupdate/flutter_xupdate.dart'; +import 'package:package_info/package_info.dart'; import 'package:permission_handler/permission_handler.dart'; -import 'package:project_telephony/ui/home/content_connect_page.dart'; -import 'package:project_telephony/ui/home/content_refuse_page.dart'; +import 'package:project_telephony/ui/home/set/func/user_info_func.dart'; import 'package:project_telephony/ui/home/set/phone_set_page.dart'; import 'package:project_telephony/ui/user/privacy_rights_page.dart'; import 'package:project_telephony/utils/headers.dart'; -import '../../utils/toast/cloud_toast.dart'; +import 'package:url_launcher/url_launcher.dart'; import '../user/privacy_rights_page.dart'; +import 'content_connect_page.dart'; +import 'content_refuse_page.dart'; class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @@ -23,7 +25,6 @@ bool sms = false; bool plone = false; bool addressBook = false; bool kg = false; - final service = FlutterBackgroundService(); @override @@ -31,7 +32,8 @@ class _HomePageState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); - initXUpdate(); + getUpdate(); + // initXUpdate(); //页面初始化的时候,添加一个状态的监听者 WidgetsBinding.instance.addObserver(this); _listenForPermissionStatus(); @@ -54,45 +56,63 @@ class _HomePageState extends State with WidgetsBindingObserver { setState(() {}); } - ///初始化 - void initXUpdate() { - FlutterXUpdate.init( - - ///是否输出日志 - debug: true, - - ///是否使用post请求 - isPost: false, - - ///post请求是否是上传json - isPostJson: false, - - ///请求响应超时时间 - timeout: 25000, - - ///是否开启自动模式 - isWifiOnly: false, - - ///是否开启自动模式 - isAutoMode: false, + getUpdate() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + String version = packageInfo.version; //版本号 + String buildNumber = packageInfo.buildNumber; //版本构建号 + var res = await UserInfoFunc.getUpdate(); + print("版本号$version"); + print('版本构建号$buildNumber'); + print("服务器上的${res.versionCode}"); + print("服务器上的${res.versionName}"); + if (res.versionCode > int.parse(buildNumber)) { + // CloudToast.show("是否进行版本更新"); + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text("版本更新"), + content: Text(res.modifyContent), + actions: [ + _getBox('跳转官网下载', () async { + await launchUrl(Uri.parse('https://www.dxbs.vip/dxbs.apk'), + mode: LaunchMode.externalApplication); + Navigator.of(context).pop(); + }), + _getBox('取消', () { + Navigator.of(context).pop(); + }), + ], + ); + }); + } + } - ///需要设置的公共参数 - supportSilentInstall: false, + _getBox(String text, VoidCallback ontap) { + return GestureDetector( + onTap: ontap, + // () async { + // await launchUrl(Uri.parse('https://www.dxbs.vip/dxbs.apk'), + // mode: LaunchMode.externalApplication); + // Navigator.of(context).pop(); + // }, + child: Container( - ///在下载过程中,如果点击了取消的话,是否弹出切换下载方式的重试提示弹窗 - enableRetry: false) - .then((value) { - // CloudToast.show("初始化成功: $value"); - }).catchError((error) { - print(error); - }); - // FlutterXUpdate.setErrorHandler( - // onUpdateError: (Map message) async { - // print(message); - // setState(() { - // _message = "$message"; - // }); - // }); + padding: EdgeInsets.symmetric(horizontal:24.w, vertical: 24.w), + margin: EdgeInsets.symmetric(horizontal: 20.w, vertical: 8.w), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8.w), + color: const Color(0xFF1890FF)), + child: Container( +alignment: Alignment.center, + width: 175.w, + child: Text( + text, + style: + const TextStyle(color: Colors.white, fontWeight: FontWeight.w600), + ), + )), + ); } @override @@ -289,23 +309,32 @@ class _HomePageState extends State with WidgetsBindingObserver { // void checkUpdateDefault() { // FlutterXUpdate.checkUpdate(url: 'https://gitee.com/xuexiangjys/XUpdate/raw/master/jsonapi/update_test.json'); // } + _getContainer(String title, String text, String image, Color cl1, Color cl2) { return GestureDetector( onTap: () async { - FlutterXUpdate.checkUpdate( - url:''); + // Get.to(()=>UpdatePage()); + // FlutterXUpdate.checkUpdate( + // // topImageRes:'vipbanner', + // widthRatio: 0.8, + // heightRatio: 0.8, + // themeColor:"#FF1890FF", + // // https://www.dxbs.vip/telephony.json + // // https://gitee.com/xuexiangjys/XUpdate/raw/master/jsonapi/update_test.json + // url: + // 'https://www.dxbs.vip/telephony.json',); // PackageInfo packageInfo = await PackageInfo.fromPlatform(); // String version = packageInfo.version;//版本号 // String buildNumber = packageInfo.buildNumber;//版本构建号 // print(version); - // print(buildNumber); + // print(buildNumber); supportSilentInstall: // print(title); - // if (title == "接听后") { - // Get.to(() => const ContentConnectPage()); - // } else { - // Get.to(() => const ContentRefusePage()); - // // print("未接听"); - // } + if (title == "接听后") { + Get.to(() => const ContentConnectPage()); + } else { + Get.to(() => const ContentRefusePage()); + // print("未接听"); + } }, child: Container( decoration: BoxDecoration( diff --git a/lib/ui/home/set/func/user_info_func.dart b/lib/ui/home/set/func/user_info_func.dart index 6c237dc..9fc5c98 100644 --- a/lib/ui/home/set/func/user_info_func.dart +++ b/lib/ui/home/set/func/user_info_func.dart @@ -1,5 +1,6 @@ import 'package:project_telephony/model/network/api_client.dart'; import 'package:project_telephony/model/network/base_model.dart'; +import 'package:project_telephony/model/update_model.dart'; import '../../../../constants/api.dart'; import '../../../../utils/toast/cloud_toast.dart'; @@ -8,12 +9,29 @@ class UserInfoFunc { static Future getAddVip(String code) async { BaseModel res = await apiClient.request(API.content.redeemVip, data: {"code": code}); - if(res.code==0){ + if (res.code == 0) { CloudToast.show("卡密兑换成功"); return true; - }else{ + } else { CloudToast.show(res.msg); return false; } } + + static Future getUpdate() async { + BaseModel res = await apiClient.request(API.app.updateSelect); + if (res.code == 0) { + // CloudToast.show("") + return UpdateModel.fromJson(res.data); + } else { + return const UpdateModel( + versionCode: 0, + updateStatus: 0, + versionName: '', + modifyContent: '', + apkSize: '', + apkMd5: '', + downloadUrl: ''); + } + } } diff --git a/lib/ui/home/update_page.dart b/lib/ui/home/update_page.dart new file mode 100644 index 0000000..e69de29 diff --git a/pubspec.lock b/pubspec.lock index 573522a..4eb34ff 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -763,7 +763,7 @@ packages: source: hosted version: "1.8.1" path_provider: - dependency: transitive + dependency: "direct main" description: name: path_provider url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index 6af7518..785f8c2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,7 +33,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 + cupertino_icons: ^1.0.5 telephony: git: url: https://git.oa00.com/wylyl22/telephony.git @@ -55,6 +55,7 @@ dependencies: flutter_screenutil: ^5.5.3+2 # 路由相关 get: ^4.6.5 + # 包的信息 package_info: ^2.0.0 # 本地化存储 @@ -105,6 +106,7 @@ dependencies: dio: ^4.0.6 # 版本跟新 flutter_xupdate: ^2.0.3 + path_provider: ^2.0.11 ## 生成适配器 # hive_generator: ^1.1.3 # # jdk