Flutter之自定義Dialog實(shí)現(xiàn)版本更新彈窗功能的實(shí)現(xiàn)
功能點(diǎn):
1.更新彈窗UI
2.強(qiáng)更與非強(qiáng)更且別控制
3.屏蔽物理返回鍵(因?yàn)閺?qiáng)更的時(shí)候點(diǎn)擊返回鍵,彈窗會(huì)消失)
4.點(diǎn)擊彈窗外透明區(qū)域時(shí),彈窗不消失
先看下效果圖:
Dialog實(shí)現(xiàn)代碼:
import 'package:flutter/material.dart'; import 'package:xiaopijiang/utils/assets_util.dart'; import 'package:xiaopijiang/utils/toast_util.dart'; ///created by WGH ///on 2020/7/23 ///description:版本更新提示彈窗 class UpdateDialog extends Dialog { final String upDateContent; final bool isForce; UpdateDialog({this.upDateContent, this.isForce}); @override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Container( width: 319, height: 370, child: Stack( children: <Widget>[ Image.asset( AssetsUtil.getImagePath( imageName: 'bg_update', suffix: 'png'), fit: BoxFit.cover, ), Container( width: double.infinity, child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[ Container( margin: EdgeInsets.only(top: 110), child: Text('發(fā)現(xiàn)新版本', style: TextStyle( fontSize: 20, color: Colors.white, decoration: TextDecoration.none)), ), Text(upDateContent, style: TextStyle( fontSize: 16, color: Colors.black54, decoration: TextDecoration.none)), Container( width: 250, height: 42, margin: EdgeInsets.only(bottom: 15), child: RaisedButton( color: Colors.red, shape: StadiumBorder(), child: Text( '立即更新', style: TextStyle(fontSize: 20, color: Colors.white), ), onPressed: () { ToastUtil.showTips('下載apk'); }), ) ], ), ), ], ), ), GestureDetector( onTap: () { Navigator.pop(context); }, child: Offstage( offstage: isForce, child: Container( margin: EdgeInsets.only(top: 30), child: Image.asset( AssetsUtil.getImagePath( imageName: 'ic_update_close', suffix: 'png'), width: 35, height: 35, )), ), ) ], ), ); } static showUpdateDialog( BuildContext context, String mUpdateContent, bool mIsForce) { return showDialog( barrierDismissible: false, context: context, builder: (BuildContext context) { return WillPopScope( child: UpdateDialog( upDateContent: mUpdateContent, isForce: mIsForce),onWillPop: _onWillPop); }); } static Future<bool> _onWillPop() async{ return false; } }
調(diào)用Dialog:
_checkUpdate() async{ int serviceVersionCode = 101; PackageInfo packageInfo = await PackageInfo.fromPlatform(); //獲取當(dāng)前的版本號(hào) int currentVersionCode = int.parse(packageInfo.version.replaceAll('.', '')); //如果獲取服務(wù)器的版本號(hào)比當(dāng)前應(yīng)用程序的版本號(hào)還高,那么提示升級(jí) if (serviceVersionCode > currentVersionCode) { if(Platform.isAndroid){ //Android平臺(tái)在應(yīng)用內(nèi)進(jìn)行更新 //彈出"版本更新"的對(duì)話(huà)框 UpdateDialog.showUpdateDialog(context, '1.修復(fù)已知bug\n2.優(yōu)化用戶(hù)體驗(yàn)', false); }else if(Platform.isIOS){ //iOS平臺(tái)跳轉(zhuǎn)道AppStore進(jìn)行更新 } } }
重點(diǎn)說(shuō)明:
屏蔽物理返回鍵(因?yàn)閺?qiáng)更的時(shí)候點(diǎn)擊返回鍵,彈窗會(huì)消失)
barrierDismissible: false,
4.點(diǎn)擊彈窗外透明區(qū)域時(shí),彈窗不消失
return WillPopScope( child: UpdateDialog( upDateContent: mUpdateContent, isForce: mIsForce), onWillPop: _onWillPop); static Future<bool> _onWillPop() async { return false; }
到此這篇關(guān)于Flutter之自定義Dialog實(shí)現(xiàn)版本更新彈窗功能的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Flutter自定義Dialog彈窗內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Qt qml中l(wèi)istview 列表視圖控件(下拉刷新、上拉分頁(yè)、滾動(dòng)軸)
這篇文章主要介紹了Qt qml中l(wèi)istview 列表視圖控件(下拉刷新、上拉分頁(yè)、滾動(dòng)軸) 的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07Android ViewFlipper翻轉(zhuǎn)視圖使用詳解
這篇文章主要為大家詳細(xì)介紹了Android ViewFlipper翻轉(zhuǎn)視圖的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05android ImageView 的幾點(diǎn)經(jīng)驗(yàn)總結(jié)
本篇文章是對(duì)android中ImageView的使用技巧進(jìn)行了幾點(diǎn)經(jīng)驗(yàn)總結(jié),需要的朋友參考下2013-06-06Android實(shí)現(xiàn) EditText輸入手機(jī)號(hào)空格功能
這篇文章主要介紹了Android實(shí)現(xiàn) EditText輸入手機(jī)號(hào)空格功能,實(shí)現(xiàn)思路是要重寫(xiě)TextWatcher,每次EditText內(nèi)容變化,都判斷內(nèi)容是否符合要求,具體實(shí)例代碼大家參考下本文2018-02-02Android?Xml轉(zhuǎn)換為View過(guò)程詳解
這篇文章主要為大家介紹了Android?Xml轉(zhuǎn)換為View實(shí)現(xiàn)過(guò)程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07