Dart 如何在SliverGrid中使用itemCount?

Dart 如何在SliverGrid中使用itemCount?,dart,flutter,flutter-sliver,sliver-grid,Dart,Flutter,Flutter Sliver,Sliver Grid,很可能我完全错误地理解了我的SliverGrid的概念 我想做的是,在UI方面,我想要一个可折叠的SliverAppBar,它已经在Flitter中提供了。我的主要内容是一组来自API响应的图像,它们已经被解析并加载到列表变量中 下面是我的代码: body: CustomScrollView( slivers: <Widget>[ SliverAppBar(expandedHeight: 150.0, backgroundColor: Co

很可能我完全错误地理解了我的SliverGrid的概念

我想做的是,在UI方面,我想要一个可折叠的SliverAppBar,它已经在Flitter中提供了。我的主要内容是一组来自API响应的图像,它们已经被解析并加载到列表变量中

下面是我的代码:

body: CustomScrollView(
          slivers: <Widget>[
            SliverAppBar(expandedHeight: 150.0, backgroundColor: Colors.green),
            SliverGrid(
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 3
              ),
              delegate: SliverChildBuilderDelegate((BuildContext context, int index){
                return Padding(
                  padding: EdgeInsets.symmetric(horizontal: 2.0, vertical: 2.0),
                  child: InkWell(
                    child: Card(
                      elevation: 8.0,
                      child: FadeInImage.memoryNetwork(fit: BoxFit.cover,image: myimagelist[index].thumbnail, placeholder:kTransparentImage,fadeInCurve: Curves.bounceIn,),
                    ),
                  )
                );
              }),
            ),
          ],
        ),
body:CustomScrollView(
条子:[
滑动条(扩展高度:150.0,背景颜色:Colors.green),
银栅(
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
交叉轴计数:3
),
委托:SliverChildBuilderDelegate((BuildContext上下文,int索引){
返回填充(
填充:边缘设置。对称(水平:2.0,垂直:2.0),
孩子:InkWell(
孩子:卡片(
标高:8.0,
子项:FadeInImage.memoryNetwork(拟合:BoxFit.cover,图像:myimagelist[index]。缩略图,占位符:KT透明图像,fadeInCurve:Curves.bounceIn,),
),
)
);
}),
),
],
),

我想这可能是因为我不能告诉小部件我的数据有多长。对于GridView.builder
itemCount
参数存在,但SliverGrid没有这样的选项。你在这里做什么?

SliverGrid小部件没有名为
itemCount
的属性。但是,如果您阅读,您将看到它的委托属性采用SliverChildBuilderDelegate,它有一个名为
childCount
的属性。可以使用此属性设置slivergrid中所需的子对象数

delegate: SliverChildBuilderDelegate((BuildContext context, int index){
  return Padding(
    padding: EdgeInsets.symmetric(horizontal: 2.0, vertical: 2.0),
    child: InkWell(
      child: Card(
        elevation: 8.0,
        child: FadeInImage.memoryNetwork(fit: BoxFit.cover,image: myimagelist[index].thumbnail, placeholder:kTransparentImage,fadeInCurve: Curves.bounceIn,),
         ),
      )
    );
  },
  childCount: 3, // Your desired amount of children here 
),