我正在尝试让ListView构建器在CustomScrollView中的SliverList中包含大约500个条目。
Scaffold(
appBar: AppBar(
title: Text(
'Test',
style: TextStyle(fontFamily: 'Diogenes', fontSize: 30),
),
actions: [
// IconButton(icon: Icon(Icons.list)),
],
),
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(...),
SliverToBoxAdapter(...),
SliverList(
delegate: SliverChildBuilderDelegate((context, index) =>
getHistoricalFixtures(pythiePerformance)))
],
),
);
Widget getHistoricalFixtures(data) {
return Padding(
padding: EdgeInsets.fromLTRB(10, 0, 10, 10),
child: Container(
height: 2000,
child: _buildFixtures(data),
),
);
}
Widget _buildFixtures(data) {
return new ListView.builder(
itemCount: data.historicalFixtures.length,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Container(...)
});
}
当ListView嵌入到一个固定大小的容器中时,它工作得很好。但是,很明显,我不能看到列表中的所有项目。
我试图将ListView放入一个扩展的小部件中,但得到了这个错误:
任何帮助都将不胜感激。
谢谢。
发布于 2021-07-02 16:30:24
您必须使用SliverList (关于在CustomScrollView中添加列表视图)或使用SliverGrid (关于在CustomScrollView中添加网格视图),如下所示:
SliverList(
delegate: SliverChildListDelegate(
[
BodyWidget(Colors.blue),
BodyWidget(Colors.red),
BodyWidget(Colors.green),
BodyWidget(Colors.orange),
BodyWidget(Colors.blue),
BodyWidget(Colors.red),
],
),
),
或
SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
delegate: SliverChildListDelegate(
[
BodyWidget(Colors.blue),
BodyWidget(Colors.green),
BodyWidget(Colors.yellow),
BodyWidget(Colors.orange),
BodyWidget(Colors.blue),
BodyWidget(Colors.red),
],
),
),
我希望这个链接是有用的:)
https://medium.com/codechai/flutter-listview-gridview-inside-scrollview-68b722ae89d4
https://stackoverflow.com/questions/65833363
复制