版本更新

This commit is contained in:
YangYuhao 2023-07-21 10:06:08 +08:00
parent 20d1a38988
commit c6389adc2f
5 changed files with 102 additions and 68 deletions

View File

@ -17,28 +17,41 @@ import 'package:package_info_plus/package_info_plus.dart';
class AboutappLogic extends GetxController {
final AboutappState state = AboutappState();
String version = "";
UpdateInfo? _updateInfo;
bool isUpdate = false;
String currentVersion = "";
@override
void onInit() {
void onInit() async{
super.onInit();
getVersion();
var data = await DioManager.instance.get(url: Api.APP_VERSION);
var bean = BaseResponse<UpdateInfo>.fromJson(
data, (data) => UpdateInfo.fromJson(data));
if (bean.isSuccess()) {
isUpdate = bean.data.update == 1;
_updateInfo = bean.data;
version = bean.data.version;
update();
// showReportDialog(Get.context!, bean.data.constraint == 0, bean.data);
}
//getVersion();
// getAppVersion();
}
getVersion() async {
final info = await PackageInfo.fromPlatform();
version = info.version;
currentVersion = "V:${info.version}";
//version = info.version;
update();
return version;
}
getUpVersion() async {
var data = await DioManager.instance.get(url: Api.APP_VERSION);
var bean = BaseResponse<UpdateInfo>.fromJson(
data, (data) => UpdateInfo.fromJson(data));
if (bean.isSuccess() && bean.data.update == 1) {
showReportDialog(Get.context!, bean.data.constraint == 0, bean.data);
if(isUpdate){
showReportDialog(Get.context!, _updateInfo!.constraint == 0, _updateInfo!);
}
}
void showReportDialog(

View File

@ -1,11 +1,11 @@
import 'package:circle_app/util/util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../components/my_app_bar.dart';
import '../../network/dio_manager.dart';
import '../dialog/UpdateDialog.dart';
import 'logic.dart';
@ -52,6 +52,14 @@ class AboutappPage extends StatelessWidget {
) ,)
,
SizedBox(height: 20.sp),
Text(
logic.currentVersion,
style: TextStyle(
color: const Color(0xFFF7FAFA),
fontSize: 12.sp,
),
),
SizedBox(height: 10.sp),
Text(
'圈子',
style: TextStyle(
@ -123,15 +131,14 @@ class AboutappPage extends StatelessWidget {
behavior: HitTestBehavior.opaque,
onTap: (){
navigateToPrivacyPolicy();
},
child: Row(
children: [
const Text(
Text(
'隐私政策',
style: TextStyle(
color: Color(0xFFF7FAFA),
fontSize: 16,
color: const Color(0xFFF7FAFA),
fontSize: 16.sp,
),
),
const Spacer(),
@ -160,7 +167,7 @@ class AboutappPage extends StatelessWidget {
),
),
const Spacer(),
Container(
logic.isUpdate? Container(
width: 6.sp,
height: 5.sp,
margin: EdgeInsets.only(top: 1.sp, right: 8.sp),
@ -168,7 +175,7 @@ class AboutappPage extends StatelessWidget {
color: Colors.red,
borderRadius: BorderRadius.circular(3.sp),
),
),
):Container(),
Text(
logic.version,
style: TextStyle(

View File

@ -19,15 +19,12 @@ class UpdateDialog extends StatefulWidget {
_CustomDialogState createState() => _CustomDialogState();
}
double myProgress = 0;
class _CustomDialogState extends State<UpdateDialog> {
double progress = 0;
bool isDownload = false;
void incrementCounter() {
setState(() {
progress = progress + 0.1;
});
}
void incrementCounter() {}
void setDownloadUi() {
setState(() {
@ -90,37 +87,34 @@ class _CustomDialogState extends State<UpdateDialog> {
height: 70.sp,
),
),
Container(
margin: EdgeInsets.only(
top: 12.sp, left: 14.sp, right: 14.sp),
alignment: Alignment.center,
child: Text(
widget.updateInfo.updateInfo,
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xCCF7FAFA), fontSize: 16.sp),
SizedBox(
height: 65.sp,
child: ListView(
children: [
Container(
margin: EdgeInsets.only(
top: 12.sp, left: 14.sp, right: 14.sp),
alignment: Alignment.center,
child: Text(
widget.updateInfo.updateInfo,
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xCCF7FAFA),
fontSize: 16.sp),
),
)
],
),
),
isDownload
? GestureDetector(
onTap: () async {
if (Platform.isIOS) {
final String appStoreUrl = 'https://apps.apple.com/app/id$iOSAPPid'; // App Store链接示例
if (await canLaunch(appStoreUrl)) {
await launch(appStoreUrl);
} else {
throw 'Could not open App Store.';
}
} else {
updataApk(widget.updateInfo.downloadUrl);
}
//incrementCounter();
},
child: Container(
margin: EdgeInsets.only(top: 24.sp),
child: CircularProgressIndicator(
value: progress,
value: myProgress,
backgroundColor: Colors.grey,
valueColor: const AlwaysStoppedAnimation<Color>(
Colors.blue),
@ -130,8 +124,19 @@ class _CustomDialogState extends State<UpdateDialog> {
)
: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
setDownloadUi();
onTap: () async {
if (Platform.isIOS) {
final String appStoreUrl =
'https://apps.apple.com/app/id$IOS_APP_ID'; // App Store链接示例
if (await canLaunch(appStoreUrl)) {
await launch(appStoreUrl);
} else {
throw 'Could not open App Store.';
}
} else {
updataApk(widget.updateInfo.downloadUrl);
setDownloadUi();
}
//Navigator.pop(context);
// logic.setBlock();
@ -168,32 +173,42 @@ class _CustomDialogState extends State<UpdateDialog> {
)
],
),
)
),
Positioned(
right: 8.sp,
top: 8.sp,
child: widget.isDismiss? GestureDetector(
onTap: (){
Navigator.pop(context);
},
child: Icon(Icons.close,color: Colors.white,size: 24.sp,)):Container())
],
),
),
),
);
}
}
updataApk(String downloadUrl) async {
//SmartDialog.showLoading();
var filePath = await getApplicationSupportDirectoryPath();
filePath = filePath + "kuayou.apk";
var data = await DioManager.instance
.download(
"https://xidi-official-website.oss-cn-shenzhen.aliyuncs.com/%E8%B7%A8%E5%8F%8B_2.3.4.apk",
filePath, (received, total) {
double progress = received / total * 100;
print('Download progress: $progress%');
})
.then((value) => print(value))
.catchError((error) {
// SmartDialog.dismiss();
print(error);
});
//await AppInstaller.installApk(filePath, actionRequired: false);
updataApk(String downloadUrl) async {
//SmartDialog.showLoading();
var filePath = await getApplicationSupportDirectoryPath();
filePath = filePath + "leyuan.apk";
var data = await DioManager.instance
.download(downloadUrl, filePath, (received, total) {
double progress = received / total * 100;
setState(() {
myProgress = received / total;
});
print('Download progress: $progress%');
})
.then((value) => {print(value)})
.catchError((error) {
// SmartDialog.dismiss();
print(error);
});
// await AppInstaller.installApk(filePath, actionRequired: false);
}
}
class UpdateInfo {

View File

@ -6,7 +6,6 @@ import 'package:circle_app/network/dio_manager.dart';
import 'package:circle_app/util/util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../circle/view.dart';

View File

@ -25,9 +25,9 @@ void main() {
runApp(const MyApp());
}
int IMsdkAppID = 1400799631;
int IM_SDK_APP_ID = 1400799631;
String iOSAPPid = "";
String IOS_APP_ID = "";
@ -216,7 +216,7 @@ class _MyAppState extends State<MyApp> {
initIM() {
coreInstance.init(
sdkAppID:
IMsdkAppID, // Replace 0 with the SDKAppID of your IM application when integrating
IM_SDK_APP_ID, // Replace 0 with the SDKAppID of your IM application when integrating
// language: LanguageEnum.en, //
loglevel: LogLevelEnum.V2TIM_LOG_DEBUG,
onTUIKitCallbackListener: (TIMCallback callbackValue) {