android - Flutter,IconButton 在使用对齐或边距或填充时不起作用

标签 android flutter padding

 appBar: new AppBar(
      leading: Stack(
        children: <Widget>[
          IconButton(
            icon: const Icon(Icons.arrow_forward),
            onPressed: () {
              _nextPage(1);
            },
            tooltip: 'Next',
            padding: EdgeInsets.only(left: 360.0),
          ),
          IconButton(
            icon: const Icon(Icons.arrow_back),
            onPressed: () {
              _nextPage(-1);
            },
            tooltip: 'Previous',
          ),
        ],
      ),
     ),

block 引用

The two IconButtons , the first one doesn't work but the second does , when you remove the padding it works fine , How should i do this ? , and using Containers wouldn't help as much because they take space too , so what to do ?

最佳答案

那里有很多错误。

首先 您正在使用 Stack , stack 会将你的小部件放在另一个上面,所以你必须使用 Positioned 指定位置或 Align .

第二 如果你查看源代码,你会发现 leading 有宽度限制。小工具。

if (leading != null) {
  leading = new ConstrainedBox(
    constraints: const BoxConstraints.tightFor(width: _kLeadingWidth),
    child: leading,
  );
}

where _kLeadingWidth = 56

第一个解决方案

替换你的 Stack小部件 Row小部件,如果你这样做,你会得到一个溢出异常,因为你的两个 IconButtons 的大小超过宽度 > 56。

最终解决方案(您可以找到更多)

删除您的 IconButton并使用 Icon由 InkWell 包裹(以便接收水龙头)

      return Scaffold(
        appBar: new AppBar(
          leading: Row(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              InkWell(
                  onTap: () => print("1"),
                  child: Padding(
                      padding: EdgeInsets.all(2.0),
                      child: const Icon(Icons.arrow_forward))),
              InkWell(
                  onTap: () => print("2"),
                  child: Padding(
                      padding: EdgeInsets.all(2.0),
                      child: const Icon(Icons.arrow_back))),
            ],
          ),
        ),
      );

关于android - Flutter,IconButton 在使用对齐或边距或填充时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51584388/

相关文章:

java - Android:自定义对话框的大小不准确

android - AutoCompleteTextView 结果出现然后消失

android - 如何使 sweepGradient 开始在 flutter 中从圆的顶部开始应用?

flutter - 如何在 flutter 出的CircleAvatar小部件内的图像上添加Onclick事件?

android - 在小部件上动态更改 TextView 填充

html - 垂直菜单奇怪的填充

html - 一些html+css代码让所有页面都移位

android - SHA 证书 firebase 调试/发布

android - 通过蓝牙调试安卓设备

image_picker : compressing is not supported for type (null). 返回原始质量的图像