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 createState() { return _UpdateDialog(); } } class _UpdateDialog extends State { @override Widget build(BuildContext context) { return Material( type: MaterialType.transparency, child: Center( child: Container( width: MediaQuery.of(context).size.width - 80.w, height: 165.h, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8.r), ), 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.h,), 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: () { updateApp(); // 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(); } updateApp() async { String url = Platform.isIOS ? "itms-apps://itunes.apple.com/app/id1575124838":"http://application.lotus-wallet.com/huixaing?release_id="; if (await canLaunch(url)) { await launch(url); } else { throw 'Could not launch $url'; } } }