flutter - 有没有办法在 Wrap 小部件中使用 Expanded 小部件
问题描述
我正在尝试使扭曲小部件内的按钮大小动态化,她的代码如下
Wrap(
spacing: 10,
alignment: WrapAlignment.spaceBetween,
children: [
for (InterestsClass item in interests)
InterestsButton(
text: item.interestsName,
)
],
),
InterestsButton is just an elevated button that is reusable, but if I add expanded as show below its Incorrect use of ParentDataWidget, since there is no flex parent
Widget build(BuildContext context) {
return Expanded(
child: ElevatedButton(
onPressed: () {
setState(() {
_flag = !_flag;
});
},
child: Text(
widget.text,
style: TextStyle(color: _flag ? kWhite : k34, fontSize: 13),
),
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
shape: StadiumBorder(),
primary: _flag ? kBlue : Color(0xffFAFAFA)),
),
);
}
解决方案
I think u can use an alternative way Chip/ ChoiceChip. These widget is available in Flutter very useful for creating size dynamic button with change style when tap. See more here https://api.flutter.dev/flutter/material/Chip-class.html
https://medium.com/flutterdevs/chip-widgets-in-flutter-7a2d3d34597c
推荐阅读
- python - Python:使用 zipfile 库将子文件夹解压缩到主文件夹
- wordpress - 有没有办法改变 Typerocket 编辑器的配置?
- css - div传递父div的全宽
- javascript - 这是对 findOneAndUpdate 使用 $ 运算符的正确方法吗?
- python-3.x - 'DataFrame' 对象没有属性 'dt'
- plot - 树状图删除树枝末端的树标签
- android - ObjectBox 中的等效 SQL lite 查询
- javascript - 我在下面的文本框中输入文本后如何将 webapge 下载为 .html/.png 是我的代码
- python-3.x - 使用 Python 的 USGS 水文数据甘特图?
- javascript - 如何在悬停时将下拉内容放置在左侧导航的右侧