gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:00:34 24 4
gpt4 key购买 nike

 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com