本文介绍了未处理的异常:类型为'_InternalLinkedHashMap< dynamic,dynamic>'不是'Map< String,dynamic>'类型的子类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Firebase存储将图像上传到Firebase,然后在Firestore中创建一个包含上述上传图像网址的文档。为此,我使用此功能

I'm trying to upload images to firebase through firebase storage, and then create a document in firestore containing urls of the said uploaded images. For this,i use this function

   void uploadImageAndCreatePage(List<File> imageFile) async {
    var storage = FirebaseStorage.instance;

    for(int j = 0; j<imageFile.length; j++) {
      StorageReference ref = storage.ref().child("photo"+Random().nextInt(3413555).toString()+j.toString());

      StorageUploadTask uploadTask = ref.putFile(imageFile[j]);

    var url = "";

    var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();

    url = dowurl.toString();

    downUrl.add(url);
    print("url is:" +downUrl.toString());

  }

    for(int i = 0; i<imageFile.length;i++){
      if(i == 0){
        map['ImgUrl'] = downUrl[0];
      }
     map['Img$i'] = downUrl[i+1 < downUrl.length?i+1:i];

    }

  var doc = await _reference.collection('Products').document("${titleController.text}").get();
    doc.reference.setData(map);
    doc.reference.collection('Reviews').document("DummyRev").setData({
      "name":"null",

    });

    print("done");
  }

代码工作正常,直到达到我使用数据设置部分为止documentreference.setData,它接受一个映射值。我将此地图定义为 Map< String,String> map = new Map(),但它仍然说它不是_InternalLinkedHashMap的子类型。我在哪里出错呢?我也尝试过使用 Map< dynamic,dynamic> Map< String,dynamic 都无济于事。

The code works fine until it gets to the part where i set the data using documentreference.setData, which takes in a map value. I have this map defined as Map<String,String> map = new Map() , but it still says it's not a subtype of _InternalLinkedHashMap.. where am i going wrong with this? i have also tried to use a Map<dynamic,dynamic> and Map<String,dynamic, to no avail.

推荐答案

尝试一下

doc.reference.setData(Map<String, dynamic>.from(map));

这篇关于未处理的异常:类型为'_InternalLinkedHashMap&lt; dynamic,dynamic&gt;'不是'Map&lt; String,dynamic&gt;'类型的子类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:34