flutter - 强制列中的小部件匹配最大的
问题描述
我在一列中有几个 RaisedButton 小部件,它们根据它们的文本具有不同的宽度。我希望它们具有相同的宽度,但我不想设置静态宽度,因为它应该能够响应语言和屏幕尺寸/形状的变化。较小的小部件应调整大小以匹配列中最大小部件的宽度。这样做的最佳方法是什么?
谢谢!
Column(
children: <Widget>[
RaisedButton(
child: Text("Btn1"),
onPressed: (){},
),
RaisedButton(
child: Text("LongerBtn2"),
color: Colors.Red,
onPressed: (){},
)
],
),
解决方案
可以这样做:
IntrinsicWidth( // <- Sizes its child's width to the child's maximum intrinsic width
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch, // <- all children will try to take as much space as possible
children: <Widget>[
RaisedButton(
child: Text("Btfffffff fsdfds dsfsa n1"),
color: Colors.green,
onPressed: () {},
),
RaisedButton(
child: Text("LongerBtn2"),
color: Colors.red,
onPressed: () {},
)
],
),
)
推荐阅读
- uipageviewcontroller - 页面视图控制器 在当前视图控制器上滑动视图控制器
- javascript - React-Redux - onClick 在每次状态更改时触发
- arrays - 用用户输入替换字符串中的单词 [RUBY]
- jquery - 使用新的 LESS 文件重新加载页面
- ruby - Ruby:错误:当我给出正确数量的参数时,参数数量错误(给定 1,预期为 0)
- swift - Swift 4 相机视图出现在 iPad 上
- azure - microsoft-graph Azure AD登录预览日志修改
- ruby-on-rails - Spring 为每次测试运行重新开始
- vaadin - Vaadin 10+:如何处理未捕获的异常?
- apache-spark - Spark RDD 以独占方式按键分区