flutter自定义对话框

先上样式:


效果图

代码:

class CommonDialogextends Dialog {

final title;

  final content;

  final rightButtonText;

  final leftButtonText;

  final VoidCallbackonPressLeftButton;

  final VoidCallbackonPressRightButton;

  final boolbarrierDismissible;//true点击外部区域关闭对话框

  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: (){///点击的对话框外部区域

              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(舞台外) 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,

                                  ),

                                )),

                          ),

                        ],

                      ),

                    ),

                  ],

                ),

              ),

            ),

          ],

        )

);

  }

}

你可能感兴趣的:(flutter自定义对话框)