【问题标题】:Dialog with stroked round background in FlutterFlutter 中带有描边圆形背景的对话框
【发布时间】:2020-03-21 12:40:43
【问题描述】:

我想创建一个具有圆角背景的对话框,并且该背景具有 3 像素的描边,如附加图像。我在下面的代码中使用了圆角,但是如何在背景中添加笔触?

showDialog(
        context: context,
        builder: (BuildContext context) {
          return Dialog(
             backgroundColor: pinkBackground,
             shape: RoundedRectangleBorder(borderRadius: 
                BorderRadius.all(Radius.circular(10.0))),
  child: Text(
    "title",

    style: getBodyTextStyle(),
  )
);
        },
      );

【问题讨论】:

    标签: user-interface flutter widget


    【解决方案1】:

    尝试将Container 添加为您的Dialog 孩子并在其中声明BoxDecoration

     showDialog(
        context: context,
        builder: (BuildContext context) {
        return Dialog(
        backgroundColor: AppColors.colorGreen,
        shape: RoundedRectangleBorder(
        borderRadius:
        BorderRadius.all(Radius.circular(10.0))),
        child: Container(
        decoration: BoxDecoration(
        border: Border.all(color: Colors.blueAccent,width: 2),
        borderRadius:
        BorderRadius.all(Radius.circular(10.0))),
        child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Text(
         "title",
            ),
         ),
        ));
      },
    );
    

    输出

    【讨论】:

      【解决方案2】:

      本地申请:

      showDialog(
        context: context,
        builder: (context) {
          return Dialog(
            backgroundColor: Colors.grey,
            shape: const RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(10.0)),
              side: BorderSide(width: 3.0, color: Colors.black),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Text(
                "title",
                style: getBodyTextStyle(),
              ),
            ),
          );
        },
      );
      

      全球应用:

      class Application extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          final baseThemeData = ThemeData.light();
          final themeData = baseThemeData.copyWith(
            dialogTheme: baseThemeData.dialogTheme.copyWith(
              backgroundColor: Colors.grey,
              shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(10.0)),
                side: BorderSide(width: 3.0, color: Colors.black),
              ),
            ),
          );
      
          return MaterialApp(
            themeMode: ThemeMode.light,
            theme: themeData,
            ...
          );
        }
      
        void _openDialog(BuildContext context) {
          showDialog(
            context: context,
            builder: (context) {
              return Dialog(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Text(
                    "title",
                    style: getBodyTextStyle(),
                  ),
                ),
              );
            },
          );
        }
      }
      

      两种变体的结果:

      【讨论】:

        猜你喜欢
        • 2016-02-20
        • 1970-01-01
        • 2016-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-15
        相关资源
        最近更新 更多