flutter自定義對(duì)話框

先上樣式:


效果圖

代碼:

class CommonDialogextends Dialog {

final title;

? final content;

? final rightButtonText;

? final leftButtonText;

? final VoidCallbackonPressLeftButton;

? final VoidCallbackonPressRightButton;

? final boolbarrierDismissible;//true點(diǎn)擊外部區(qū)域關(guān)閉對(duì)話框

? CommonDialog(

{this.title ="提示",

? ? ? this.content ="",

? ? ? this.rightButtonText ="",

? ? ? this.leftButtonText ="",

? ? ? this.onPressLeftButton,

? ? ? this.onPressRightButton,

? ? ? this.barrierDismissible=true});

? @override

? Widgetbuild(BuildContext context) {

return Material(

type: MaterialType.transparency,

? ? ? ? child:Stack(

fit: StackFit.expand,

? ? ? ? ? children: [

GestureDetector(

onTap: (){///點(diǎn)擊的對(duì)話框外部區(qū)域

? ? ? ? ? ? ? if(barrierDismissible){

NavigatorUtil.last(context);

? ? ? ? ? ? ? }

},

? ? ? ? ),

? ? ? ? ? ? new Center(

child:Container(

width: Constant.WIDTH_SCALE * Util.getScreenWidth(context),

? ? ? ? ? ? ? ? decoration:ShapeDecoration(

color: Colors.white,

? ? ? ? ? ? ? ? ? ? shape:RoundedRectangleBorder(

borderRadius:BorderRadius.circular(6))),

? ? ? ? ? ? ? ? child:Column(

mainAxisSize: MainAxisSize.min,

? ? ? ? ? ? ? ? ? children: [

new Offstage(

offstage:title =="", //offstage(舞臺(tái)外) true不顯示

? ? ? ? ? ? ? ? ? ? ? child:Container(

alignment: Alignment.center,

? ? ? ? ? ? ? ? ? ? ? ? height:60,

? ? ? ? ? ? ? ? ? ? ? ? padding:const EdgeInsets.only(top:24, bottom:12),

? ? ? ? ? ? ? ? ? ? ? ? child:new Text(

title,

? ? ? ? ? ? ? ? ? ? ? ? ? style: JTextStyle.largeTextStyleBlack,

? ? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ),

//? ? ? ? ? ? ? ? new Divider(

//? ? ? ? ? ? ? ? ? height: 1,

//? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? Container(

margin:const EdgeInsets.fromLTRB(20, 0, 20, 16),

? ? ? ? ? ? ? ? ? ? ? child:new Text(

content,

? ? ? ? ? ? ? ? ? ? ? ? style: JTextStyle.smallTextStyleGray6,

? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? new Divider(

height:1,

? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? Container(

height:60,

? ? ? ? ? ? ? ? ? ? ? child:new Row(

mainAxisAlignment:

(leftButtonText !="" &&rightButtonText !="")

? MainAxisAlignment.spaceAround

? ? ? ? ? ? ? ? ? ? ? ? ? ? : MainAxisAlignment.center,

? ? ? ? ? ? ? ? ? ? ? ? children: [

new Offstage(

offstage:leftButtonText =="",

? ? ? ? ? ? ? ? ? ? ? ? ? ? child:new GestureDetector(

onTap:onPressLeftButton,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? child:new Container(

height:60,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? alignment: Alignment.center,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? padding:

const EdgeInsets.only(left:30, right:30),

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? color: Colors.white,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? child:new Text(

leftButtonText,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? style: JTextStyle.largeTextStyleBlack,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? )),

? ? ? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ? ? ? new Offstage(

offstage:rightButtonText =="",

? ? ? ? ? ? ? ? ? ? ? ? ? ? child:new GestureDetector(

onTap:onPressRightButton,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? child:new Container(

height:60,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? alignment: Alignment.center,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? padding:

const EdgeInsets.only(left:30, right:30),

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? color: Colors.white,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? child:new Text(

rightButtonText,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? style: JTextStyle.largeTextStyleBlue,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? )),

? ? ? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ? ? ],

? ? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ? ? ],

? ? ? ? ? ? ? ? ),

? ? ? ? ? ? ? ),

? ? ? ? ? ? ),

? ? ? ? ? ],

? ? ? ? )

);

? }

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容