android 类别'List< _JsonQueryDocumentSnapshot>'没有执行严修getter '长度',接收端:'_GrowableList'的执行严修(长度:3)尝试呼叫:长度

2g32fytz  于 2022-12-09  发布在  Android
关注(0)|答案(1)|浏览(113)

主页类
我是新来的,扑和搭售,提出了票务服务的申请。
现在我得到这个错误。
微件库捕获到异常
类别'List<_JsonQueryDocumentSnapshot>'没有执行严修getter '长度'。
接收方:'_GrowableList'的示例(长度:3)
已尝试呼叫:长度

body: CustomScrollView(
        slivers: [
          SliverPersistentHeader(
            pinned: true,
            delegate: TextDelegateHeaderWidget(title : "My Services"),
          ),

          //1. write Query

          // model class

          // ui design Widget

          StreamBuilder
            (
              stream: FirebaseFirestore.instance.
              collection("sellers").doc(sharedPreferences!.
              getString("uid")).collection("brands").snapshots(),
              builder: (context, AsyncSnapshot dataSnapshot)
              {
                if(dataSnapshot.hasData) // if brands has extis.
                  {
                    // display data
                  return SliverStaggeredGrid.countBuilder
                    (
                      crossAxisCount: 1,
                      staggeredTileBuilder: (c)=> const StaggeredTile.fit(1),
                      itemBuilder: (context, index)
                      {
                        Brands brandsModel = Brands.fromJson(
                          dataSnapshot.data!.docs[index].data() as Map<String, dynamic>);
                        //dataSnapshot.data!.docs[index].data()as Map<String, dynamic>);

                        return BrandsUiDesignWidget(
                         model: brandsModel,
                          context: context,

                        );
                      },
                      itemCount: dataSnapshot.data.docs.lenght,
                  );
                  }
                else // if not exists.
                  {
                    return const SliverToBoxAdapter(
                      child: Center(
                         child: Text(
                            "No Services Exists. Please Add Some" ,

                          ),
                        ),
                    );

                  }

              }

           )

        ],
      ),

品牌类别

class _BrandsUiDesignWidgetState extends State<BrandsUiDesignWidget>
{
  @override
  Widget build(BuildContext context)
  {
    return Card(
      elevation: 10,
      shadowColor: Colors.black,
        child: Padding(
          padding: const EdgeInsets.all(0),
          child: SizedBox(
            height: 270,

            width: MediaQuery.of(context).size.width,
            child: Column(
              children: [
                Image.network(
                  widget.model!.thumbnailUrl.toString(),
                  height: 220,
                  fit: BoxFit.cover,

                ),
                const SizedBox(height: 1,),

                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      widget.model!.brandTitle.toString(),
                      style: const TextStyle(
                        color: Colors.deepPurple,
                        fontWeight: FontWeight.bold,
                        fontSize: 20,
                        letterSpacing: 3,
                      ),
                    ),

                    IconButton(
                        onPressed: ()
                        {

                        } ,
                        icon: const Icon(
                          Icons.delete_sweep,
                          color: Colors.pinkAccent,

                        ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
    );
  }
}

我试图在我的服务中显示数据。但代码是给这个错误,我是新的Flutter。通过改变我的代码将是一个很大的帮助比解释。因为我是新的,不知道很多事情。

vbkedwbf

vbkedwbf1#

您的代码看起来很好,只是length属性中有错误,请替换为:

itemCount: dataSnapshot.data.docs.lenght,

与此:

itemCount: dataSnapshot.data.docs.length,

相关问题