问题描述
我正在尝试显示来自sqlite的一些数据,并且一切正常,但是我无法在CustomScrollView中使用StreamBuilder,它说:
RenderViewport预期使用RenderSliver类型的子代,但接收到类型为RenderSliver的子代 RenderPositionedBox。
然后我用SliverPadding包裹了StreamBuilder(通常SliverPadding由StreamBuilder包裹),但是这次它说:
RenderSliverPadding预期为RenderSliver类型的子代,但接收到类型为RenderSliver的子代 RenderPositionedBox。
我尝试使用SliverToBoxAdapter并将其包装在StreamBuilder中,但没有解决我的问题,因此我该如何实现?
这是我的代码的最后状态:
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
centerTitle: true,floating: false,snap: false,pinned: false,expandedHeight: 0,elevation: 3,forceElevated: true,backgroundColor: Theme.of(context).scaffoldBackgroundColor,brightness: Brightness.light,title: Text(
'Your Lists',style: GoogleFonts.openSans(
fontSize: 22,fontWeight: FontWeight.bold,color: Colors.black),),SliverPadding(
padding: EdgeInsets.fromLTRB(16,16,74),sliver: StreamBuilder<List<Category>>(
stream: bloc.getAll().asStream(),builder: (context,AsyncSnapshot<List<Category>> snapshot) {
if (snapshot.hasData) {
return SliverGrid(
delegate: SliverChildBuilderDelegate(
(BuildContext context,int index) {
if (index == snapshot.data.length) {
return ListAddCard();
}
return ListCard(
category: snapshot.data[index],);
},childCount: snapshot.data.length + 1),gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,mainAxisSpacing: 16,crossAxisSpacing: 16,childAspectRatio: 1.1),);
}
return Center(child: CircularProgressIndicator());
}),)
],);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)