我有一个未来的页面主体构建器。我实现页面的方式是 FutureBuilder 中的 CustomScrollView。(基于这个问题How to use FutureBuilder inside SliverList的公认答案)
所以整个页面、sliver app bar 和 body(sliver 网格)都在等待未来。
我希望应用栏不要等待未来的构建器,并且总是出现,因为只有银色网格取决于未来。
这甚至可能吗?
final SliverAppBar sliverAppBar = SliverAppBar(
title: Text('Your offers'),
floating: true,
);
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder(
future: offers,
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
return SpinKitChasingDots(color: Colors.blueAccent);
else {
if (snapshot.hasError)
return noOffersPage(error: true, errorException: snapshot.error);
else {
if (!snapshot.data.exists) return noOffersPage(error: false);
final Map<String, dynamic> data = snapshot.data.data();
final List<String> urls = data['urls'];
return CustomScrollView(
slivers: [
sliverAppBar, // <--- unnecessarily waits on the future
SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return buildGridItem(urls[index]);
},
childCount: urls.length,
),
),
],
);
}
}
},
),
);
}