版本更新

master
王亚玲 2 years ago
parent 520f2693aa
commit 926f20200a

@ -31,7 +31,6 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- 互联网权限-->
<uses-permission android:name="android.permission.SEND_SMS"/>

Binary file not shown.

@ -58,7 +58,7 @@ class _App {
///
String get updateSelect =>'/app/update/select';
///ban
///
String get updateAdd => '/manage/update/add';
}

@ -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<String, dynamic> 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<Object?> get props => [
updateStatus,
versionCode,
versionName,
modifyContent,
downloadUrl,
apkSize,
apkMd5,
];
}

@ -0,0 +1,17 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'update_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
UpdateModel _$UpdateModelFromJson(Map<String, dynamic> 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,
);

@ -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<HomePage> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
initXUpdate();
getUpdate();
// initXUpdate();
//
WidgetsBinding.instance.addObserver(this);
_listenForPermissionStatus();
@ -54,45 +56,63 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
setState(() {});
}
///
void initXUpdate() {
FlutterXUpdate.init(
///
debug: true,
///使post
isPost: false,
///postjson
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<String, dynamic> 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<HomePage> 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(

@ -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';
@ -16,4 +17,21 @@ class UserInfoFunc {
return false;
}
}
static Future<UpdateModel> 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: '');
}
}
}

@ -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"

@ -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

Loading…
Cancel
Save