下面的代码表示一个项目列表,其中列表应该是全宽的,但列表中的元素可能不是。Flutter 似乎忽略了我对 的宽度限制SizedBox
并强制它完全扩展。
class ExampleBadListWidth extends StatelessWidget {
List<String> things = [
"1: This is a really really really really really really really really really really long thing",
"2: This is a really really really really really really really really really really long thing",
"3: This is a really really really really really really really really really really long thing"
];
ExampleBadListWidth();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: [
Expanded(
child: ListView.builder(
itemCount: things.length,
itemBuilder: _thingBuilder,
))
]));
}
Widget _thingBuilder(context, index) {
return SizedBox(width: 100, child: Text(things[index]));
}
}