flutter - 如何在 flutter 对话框中添加圆形边框?

标签 flutter dart

How to add circular border for dialog box in a flutter?,我尝试了下面的代码,但无法获得所需的输出,我已经添加了圆形边框,但它不起作用,我需要对话框的圆形边框,详细请引用预期输出,请指导

我的代码: `

class CustomDialog extends StatelessWidget {                                                          
  @override
  Widget build(BuildContext context) {                                                                  
    const double padding = 1.0;                                                                                
    return Dialog(
        backgroundColor: Colors.green,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(8.0),
        ),
        child: Container(
            decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(20.0))),
            child: Column(mainAxisSize: MainAxisSize.min, children: [
              Container(
                margin: EdgeInsets.all(1),
                width: double.infinity,
                child: Text('title',
                    style: TextStyle(fontSize: 30, color: Colors.white)),
                color: Colors.green,
              ),
              Container(
                color: Colors.white,
                padding: EdgeInsets.all(10),
                child: ListView(
                  shrinkWrap: true,
                  children: [
                    Container(
                        margin: EdgeInsets.only(left: 10, bottom: 10),
                        height: 30,
                        child: Text('one',
                            style: TextStyle(
                              fontSize: 20,
                            ))),
                    Container(
                        margin: EdgeInsets.only(left: 10, bottom: 10),
                        height: 30,
                        child: Text('one',
                            style: TextStyle(
                              fontSize: 20,
                            ))),
                    Container(
                        margin: EdgeInsets.only(left: 10, bottom: 10),
                        height: 30,
                        child: Text('one',
                            style: TextStyle(
                              fontSize: 20,
                            ))),
                  ],
                ),
              ),
              Divider(
                color: Colors.white,
              ),
              Container(
                  color: Colors.white,
                  height: 50,
                  padding: EdgeInsets.all(5),
                  alignment: Alignment.centerRight,
                  child: Text(
                    'CANCEL',
                    style: TextStyle(fontSize: 20),
                  )),
            ])));
  }
}

`

我的期望:expected output

当前输出:my output

最佳答案

只需要在对话框中添加ClipBehavior

import 'package:flutter/material.dart';

class CustomDialog extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    const double padding = 1.0;
    return Dialog(
      backgroundColor: Colors.green,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20.0),
      ),
      clipBehavior: Clip.antiAlias, //  add clipBehavior 
      child: Column(mainAxisSize: MainAxisSize.min, children: [
        Container(
          margin: EdgeInsets.all(1),
          width: double.infinity,
          child: Text('title',
              style: TextStyle(fontSize: 30, color: Colors.white)),
          color: Colors.green,
        ),
        Container(
          color: Colors.white,
          padding: EdgeInsets.all(10),
          child: ListView(
            shrinkWrap: true,
            children: [
              Container(
                  margin: EdgeInsets.only(left: 10, bottom: 10),
                  height: 30,
                  child: Text('one',
                      style: TextStyle(
                        fontSize: 20,
                      ))),
              Container(
                  margin: EdgeInsets.only(left: 10, bottom: 10),
                  height: 30,
                  child: Text('one',
                      style: TextStyle(
                        fontSize: 20,
                      ))),
              Container(
                  margin: EdgeInsets.only(left: 10, bottom: 10),
                  height: 30,
                  child: Text('one',
                      style: TextStyle(
                        fontSize: 20,
                      ))),
            ],
          ),
        ),
        Divider(
          color: Colors.white,
        ),
        Container(
            color: Colors.white,
            height: 50,
            padding: EdgeInsets.all(5),
            alignment: Alignment.centerRight,
            child: Text(
              'CANCEL',
              style: TextStyle(fontSize: 20),
            )),
      ]),
    );
  }
}

enter image description here

关于flutter - 如何在 flutter 对话框中添加圆形边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63593723/

相关文章:

flutter - 如何在Flutter中实现多个倒计时进度条?

flutter - 如何在flutter上实现文本和图像的换行?

flutter - 在build-Method中分配InheritedWidget

listview - 如何使我的列在 Flutter 中可滚动?

android - 在 flutter web 中实现 admob 或其他广告

dart - 如何修复类型 'Future<dynamic>' 不是类型 'String' Flutter 的子类型

flutter - 如何在 Appbar 上制作不同对齐方式的一些图标?

dart - JetBrains的Dart插件不会重新分析在JetBrains IDE外部修改的文件

dart - 使用 VSCode 创建和运行 Dart 控制台应用程序?

dart - 可点击图像的抖动列表