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,

                                  ),

                                )),

                          ),

                        ],

                      ),

                    ),

                  ],

                ),

              ),

            ),

          ],

        )

);

  }

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容