【问题标题】:While accessing data _buildStoryPage( Map<String, dynamic> data,bool active) its showing error Map<String, dynamic> not ty 'Map<String, dynamic>'访问数据 _buildStoryPage( Map<String, dynamic> data,bool active) 时显示错误 Map<String, dynamic> not ty 'Map<String, dynamic>'
【发布时间】:2021-09-11 07:20:00
【问题描述】:

访问数据时 _buildStoryPage(Map data,bool active) 显示 错误类型 '() => Map' 不是类型 'Map' 的子类型 在 cloudfirestore 库升级其工作正常之前。
code here

 StreamBuilder(
        stream: slides,
        initialData: [],
        builder: (BuildContext context, AsyncSnapshot snap){
          List slideList=snap.data.toList();
          return PageView.builder(

              controller: ctrl,
              itemCount: slideList.length+1,
              itemBuilder:(context,int currentIndex){
                if(currentIndex==0){
                  return _buildTagPage();
                }
                else if (slideList.length>=currentIndex){
                  bool active=currentIndex==currentPage;
               
                    //error  at this line
                  return _buildStoryPage(slideList[currentIndex-1],active);
                }
                return Loader();
              }
          );
        },
      ),

 Stream  _queryDb({String tag="New"}){
    Query query=db.collection('Stories').where("tag",arrayContains: tag);
    slides =query.snapshots().map((list)=>list.docs.map((d)=>d.data));
    setState(() {
      activeTag=tag;
    });

  }

  _buildStoryPage(  Map<String, dynamic> data,bool active){
// while providing the value to _buildStoryPage(slideList[currentIndex-1],active)  its error 
//type '() => Map<String, dynamic>' is not a subtype of type 'Map<String, dynamic>'
}

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore flutter-dependencies


    【解决方案1】:

    这是一个函数:

      Map<String, dynamic> data() {
                        return slideList[currentIndex-1];
                      }
    

    在您的代码中,您通过函数名称调用它并且不运行它:

    _buildStoryPage(  Map<String, dynamic> data,bool active){
    

    您需要运行该函数以获得预期的结果:

    _buildStoryPage(  Map<String, dynamic> data(),bool active){
    

    【讨论】:

    • 嘿,感谢您的帮助。我删除了这个函数 Map data() { return slideList[currentIndex-1]; }
    • 列表 slideList=snap.data.toList();然后在幻灯片列表中我传递值 return _buildStoryPage(slideList[currentIndex-1],active);
    • 在 cloudfirestore 库更新其工作之前,我使用上述方式仍然是相同的问题类型 '() => Map' 不是类型 'Map' 的子类型很好。
    • 您能否用新代码更新您的问题。
    • 更新了我只是删除了 data() 函数。
    猜你喜欢
    • 2021-04-13
    • 2021-09-25
    • 2021-02-11
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 2020-01-10
    • 2021-03-25
    相关资源
    最近更新 更多