我有一个将来的页面主体构建器。 我实现页面的方式是FutureBuilder中的CustomScrollView。 (基于该问题How to use FutureBuilder inside SliverList的公认答案)
因此整个页面,sliver应用程序栏和主体(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,
),
),
],
);
}
}
},
),
);
}