1

IconButton 在屏幕边缘占用了太多空间。我是这样做的:

return Scaffold(
  body: Column(
    children: [
      Container(
        margin: EdgeInsets.all(20),
        child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [ 
          Row(
             children: <Widget>[
               Expanded(child: Input()),
               IconButton(
                icon: const Icon(Icons.cancel),
                onPressed: () {},
               ),
             ],
        ), ...

看起来像: 在此处输入图像描述

如何修复它以使图标更靠近边缘边缘?

4

3 回答 3

1

您正在寻找的constraintsIconButton.

你可以像这样使用它。

constraints: BoxConstraints.tight(Size(24, 24))

有关如何轻松解决这些问题的信息,请查看您的IconButton.

如果您cmd + click检查IconButton并检查它的构建方法,您会看到它正在使用 aConstrainedBox根据某些因素来决定它的大小。

其中一个因素是constraints我们传递给 Widget。

于 2021-05-16T13:23:59.197 回答
1

我通常在这种情况下使用GestureDetectoror InkWell,因为如果将容器作为子容器,它们会提供更多的尺寸调整。您可以Icon作为孩子给予其中任何一个。

InkWell(
     child: const Icon(Icons.cancel),
     onTap: () {},
)

或者

InkWell(
     child: Container(child : Icon(Icons.cancel), height: 24.0, width: 24.0),
     onTap: () {},
)
于 2021-05-17T06:59:04.013 回答
0

您是否尝试将填充设置为零?

IconButton(
      padding: EdgeInsets.zero,
      ...
    );
于 2021-05-16T11:16:00.427 回答