我希望创建以下内容:当到达内部 Listview 的顶部或底部时,我想继续在顶部 Listview 中滚动。见 GIF:
一个选项是在到达底部时将内部 Listview 的物理设置为 NeverScrollablePhysics(使用控制器的侦听器),但是如果您想再次向上滚动,这将不起作用。
请参阅下面的代码,在此先感谢!
class TestAppHomePage extends StatefulWidget {
@override
TestAppHomePageState createState() => new TestAppHomePageState();
}
class TestAppHomePageState extends State<TestAppHomePage> {
ScrollController _scrollController = ScrollController();
@override
void initState() {
print('set up');
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: Container(
color: Colors.green,
child: ListView(
primary: false,
// controller: _scrollController,
children: <Widget>[topWidget(), topWidget(), topWidget(), topWidget()],
),
),
);
}
Widget topWidget() {
return Card(
color: Colors.purple,
margin: EdgeInsets.all(16),
child: Container(
height: 400,
child: Column(
children: <Widget>[
Container(height: 100, color: Colors.white),
Expanded(
child: ListView(
controller: _scrollController,
children: List.generate(
40,
(index) {
return someText(index);
},
).toList()))
],
),
));
}
Widget someText(int i) {
return Text('text no $i');
}
}