You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

151 lines
5.0 KiB

import 'dart:io';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart';
import 'package:huixiang/retrofit/data/app_update.dart';
import 'package:huixiang/utils/bridge.dart';
import 'package:huixiang/utils/flutter_utils.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
class UpdateDialog extends StatefulWidget {
final String version;
final AppUpdate appUpdate;
UpdateDialog(this.version,this.appUpdate);
@override
State<StatefulWidget> createState() {
return _UpdateDialog();
}
}
class _UpdateDialog extends State<UpdateDialog> {
@override
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
child: Center(
child: Container(
width: MediaQuery.of(context).size.width - 80.w,
height: 180.h,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Column(
children: [
Container(
width: double.infinity,
height: 110.h,
alignment: Alignment.center,
padding: EdgeInsets.all(20),
child: Column(
children: [
Text(
"检测到新版本 v${widget.appUpdate.appLastVersion}",
style: TextStyle(
fontSize: 17.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF000000),
),
),
SizedBox(height: 12,),
Text(
"是否需要更新到最新版本?",
style: TextStyle(
fontSize: 17.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFF333333),
),
),
],
)
),
Container(
color: Color(0x1A000000),
height: 1.h,
),
Container(
height: 69.h,
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
if(!AppUtils.versionCompare(widget.version,widget.appUpdate.appLastVersionUp))
Expanded(
child: InkWell(
onTap:() {
doNotUpdate();
},
child: Container(
width: double.infinity,
height: 90.h,
alignment: Alignment.center,
child: Text(
"下次再说",
style: TextStyle(
fontSize: 17.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF8C8C8C),
),
),
),
),
flex: 1,
),
Container(
color: Color(0x1A000000),
width: 1.h,
),
Expanded(
child: InkWell(
onTap: () {
(Theme.of(context).platform == TargetPlatform.android) ?
androidUpdate():Bridge.toAppStore().then((value) {
});
// Navigator.of(context).pop();
},
child: Container(
width: double.infinity,
height: 90.h,
alignment: Alignment.center,
child: Text(
"立即更新",
style: TextStyle(
fontSize: 17.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
),
),
flex: 1,
),
],
),
),
],
),
),
),
);
}
doNotUpdate() async {
SharedPreferences value = await SharedPreferences.getInstance();
value.setString("appLastVersion", widget.appUpdate.appLastVersion);
Navigator.of(context).pop();
}
androidUpdate() async {
String url = "http://application.lotus-wallet.com/huixaing?release_id=627cadff23389f2fe6d57cb1";
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
}