📜  futurebuilder 中的自定义滚动视图 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:49.379000             🧑  作者: Mango

代码示例1
// build fixed items outside of the FutureBuilder for efficiency
final someOtherSliver = SliverToBoxAdapter(...);

return FutureBuilder>(
  future: getQuake(), // this is a code smell. Make sure that the future is NOT recreated when build is called. Create the future in initState instead.
  builder: (context, snapshot){
    Widget newsListSliver;
    if(snapshot.hasData) {
      newsListSliver = SliverList(delegate: SliverChildBuilderDelegate(...))
    } else {
      newsListSliver = SliverToBoxAdapter(child: CircularProgressIndicator(),);
    }

    return CustomScrollView(
      slivers: [
        someOtherSliver,
        newsListSliver
      ],
    );
  },
);