flutter - Flutter:设置按钮高度以填充容器
问题描述
但是从上图可以看出,左边的按钮(红色)显然没有填满整个容器(绿色)。我可以通过向 MaterialButton 添加高度来解决这个问题,但恕我直言,这不是最好的解决方案,因为设备的高度可能会有所不同。你能帮我解决这个问题吗?谢谢。
这是我的代码:
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.green,
child: MaterialButton(
color: Colors.red,
child: Text("Button A"),
onPressed: () {},
),
),
),
Expanded(
child: MaterialButton(
color: Colors.blue,
child: Text("Button B"),
onPressed: () {},
),
),
],
),
解决方案
只需添加 -materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
在MaterialButton
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.green,
child: MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, // Add this
color: Colors.red,
child: Text("Button A"),
onPressed: () {},
),
),
),
Expanded(
child: MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, // Add this
color: Colors.blue,
child: Text("Button B"),
onPressed: () {},
),
),
],
),
推荐阅读
- c - 将整数指针传递给函数时出现分段错误
- qt - 在 Qt::ToolButtonIconOnly 和 Qt::ToolButtonTextBesideIcon 之间切换时垂直 QToolbar 中图标的位置
- python - 跨文件访问私有属性 - 理解错误,Python 3.8.2
- python-3.x - how to compare to two json files and return a un matched key and value in object
- angular - How to wait until app is loaded after nativescript firebus push notification received
- python - Create TFLite file with InceptionV3 and Food101
- haskell - Is implementing the words function possible without a postprocessing step after folding?
- javascript - Firebase verify and reset password without sending separate mails
- midi - 如何在 MIDI 中查找音符的长度
- powershell - powershell:获取txt文件的最后一个块(模式)及以下