以下是我的代码

 InkWell(
                        onTap: () {
                          Navigator.pop(context);
                        },
                        child: Align(
                          alignment: Alignment(1,-1),
                          child: CircleAvatar(
                            maxRadius: 20,
                            backgroundColor: Colors.transparent,
                            child: Image.asset('assets/cancel.png',height: 30,),
                          ),
                        ),
                      ),

我拿到这个了

enter image description here

我想要这样的

enter image description here

推荐答案

如果您使用的是AlertDialog,那么您可以使用iconiconPadding来保持close图像的右上角.

  Future<void> _showMyDialog() async {
    return showDialog<void>(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return AlertDialog(
          iconPadding: const EdgeInsets.all(0),
          icon: Align(
            alignment: Alignment.topRight,
            child: InkWell(
              onTap: () {
                Navigator.pop(context);
              },
              child: Icon(Icons.close),
              // child: Image.asset(
              //   'assets/cancel.png',
              //   height: 30,
              // ),
            ),
          ),
          content: const SingleChildScrollView(
            child: ListBody(
              children: <Widget>[
                Text('This is a demo alert dialog.'),
                Text('Would you like to approve of this message?'),
              ],
            ),
          ),
          actions: <Widget>[
            TextButton(
              child: const Text('Approve'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }

我删除了CircleAvatar,因为它用于用户Profile Image.此小工具将提供额外的填充,而我无法删除填充. 请判断此解决方案是否有效.

Flutter相关问答推荐

创建多个具有适当填充和对齐的按钮的最佳方法

Flutter:如何从Bottom Navigator中删除此内容

如何从模型列表中生成DropdownButtonFormField?

如何组合匹配器

CMakeLists.txt处的CMake错误:3(项目)找不到指定的Visual Studio实例

设置Flutter 中的ListView.Builder()的最小高度

框中的Flutter 适配图像

带有命名参数的回调函数不起作用

有没有办法在 google_map 上移动标记(向左或向右移动一些像素)?

显示图像的放大部分

splash_screen 没有被推送到登录页面

通过在父窗口小部件功能上设置状态来浏览屏幕

输入处于活动状态时如何设置文本字段标签的样式?

我可以定义一次 sharedPreferences 并在需要数据显示到 flutter 应用程序时调用它吗?

如何在 flutter 的 onChanged(更改字符)处更改 TextField 边框 colored颜色 ?

函数中的变量在 Dart 中应该有什么关键字?

Flutter :RangeError(索引):无效值:不在包含范围内0..3:4使用IndexedListView.builder

我收到这个错误我无法解决

Flutter MQTT - 发布到主题 1 并收听主题 2

Flutter GetX:Get.put 在 Widget 中的什么位置?