[英]Horizontal ListView.builder overflow width bound when scroll
我正在尝试使用 ListView.builder 在 Stack 中显示水平列表,但是如果我设置itemCount: 10
则在滚动 ListView 时会遇到这个奇怪的错误。 如果我设置itemCount: 20
ListView 滚动正常。
我已经在模拟器(Galaxy Nexus 720x1280 android 5.0)和真实设备(诺基亚 7 plus,android 9.0)上进行了测试。 我怎样才能解决这个问题?
class BugPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Stack(
children: <Widget>[
Positioned(
left: 20.0,
right: 20.0,
height: 60.0,
bottom: 70.0,
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 10, // Overflow when scroll.
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 3.0,
),
child: Container(
width: 40.0,
height: 40.0,
color: Colors.red,
child: Center(child: Text("$index")),
),
);
},
),
),
SizedBox(width: 10.0),
FloatingActionButton(
backgroundColor: Colors.blue,
onPressed: () {},
child: new Icon(
Icons.add,
color: Colors.black,
),
),
],
),
),
],
),
),
);
}
}
预期输出:
实际输出:
我试过你的代码并且用更大的 intemcount 运行也没有问题,但我有一个建议,改变
SizedBox(width: 10.0)
用于按钮周围的填充
Padding(
padding: const EdgeInsets.only(left: 10),
child: FloatingActionButton(
backgroundColor: Colors.blue,
onPressed: () {},
child: new Icon(
Icons.add,
color: Colors.black,
),
)
)
在我更新到最新版本后,这个错误似乎出现在旧的颤振版本中,一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.