尝试使用 firebase 获取我的颤振应用程序的获取请求并出现错误

Posted

技术标签:

【中文标题】尝试使用 firebase 获取我的颤振应用程序的获取请求并出现错误【英文标题】:Trying to use firebase for a get request for my flutter app and getting error 【发布时间】:2020-06-18 20:52:44 【问题描述】:

enter image description here[这是前面的屏幕,它是一个 gridTile 并从 firebase 获取数据

<!-- this is the method which the grid time is using to fetch data from firebase-->

 Future<void> fetchAndSetProducts() async 
    const url ='MY flutter url';
    try 
      final response = await http.get(url);
      final extractedData = json.decode(response.body) as Map<String, dynamic>;
      final List<Product> loadedProducts = [];
      extractedData.forEach((prodId, prodData) 
        loadedProducts.add(Product(
          id: prodId,
          title: prodData['title'],
          description: prodData['description'],
          price: prodData['price'],
          isFavorite: prodData['isFavorite'],
          imageUrl: prodData['imageUrl'],
        ));
      );
      _items = loadedProducts;
      notifyListeners();
     catch (error) 
      throw (error);
    
  

]2

enter image description here

【问题讨论】:

附加显示此详细信息的小部件。 【参考方案1】:

这是你的 json:


   "-M1We9LYxWhijvoECbpY":
      "description":"Abe Kya be saale",
      "imageURL":"https://cdn.wallpapersafari.com/89/2/Lnxobm.jpg",
      "isFavorite":false,
      "price":747.0,
      "title":"test"
   ,
   "-M1WlRlzv8rYwhGklkyc":
      "description":"Abe sale nikal na",
      "imageURL":"https://cdn.wallpapersafari.com/89/2/Lnxobm.jpg",
      "isFavorite":false,
      "price":43.0,
      "title":"fdddfff"
   ,
   "-M1XmbG11YGDgSdJyfvm":
      "description":"dfvdfvfdvfvfdb",
      "imageURL":"https://cdn-products.eneba.com/resized-products/qoA2QojrFaqg8VtfKSEJm1jsXU-9UEJJSNf2WTvMBjE_390x400_2x-0.jpeg",
      "isFavorite":false,
      "price":74.0,
      "title":"new"
   ,
   "-M1axCdqSDIIijYYSXDX":
      "description":"gctdcgchvhgvggh",
      "imageURL":"https://cdn.pixabay.com/photo/2016/10/02/22/17/red-t-shirt-1710578_1280.jpg",
      "isFavorite":false,
      "price":411.0,
      "title":"bhbn"
   ,
   "-M1i_KbskfnTLxfFRIiu":
      "description":"dzvfvbvfbvggfbvxfgb gfvb ",
      "imageUrl":"https://5.imimg.com/data5/IJ/JK/MY-11744895/playing-football-500x500.jpg",
      "isFavorite":false,
      "price":65.0,
      "title":"fbvfbvc cv"
   

所有节点都包含属性imageURL,除了一个节点包含属性imageUrl。因此,首先您需要更改 json,以便所有节点都包含 imageURL(大写 URL),然后在您的代码中执行以下操作:

  extractedData.forEach((prodId, prodData) 
        loadedProducts.add(Product(
          id: prodId,
          title: prodData['title'],
          description: prodData['description'],
          price: prodData['price'],
          isFavorite: prodData['isFavorite'],
          imageUrl: prodData['imageURL'],
        ));
      );

【讨论】:

以上是关于尝试使用 firebase 获取我的颤振应用程序的获取请求并出现错误的主要内容,如果未能解决你的问题,请参考以下文章

将 Firebase 添加到颤振项目,破坏项目

颤振不再接受 firebase 用户命令了吗? [复制]

如何从 Firebase Firestore 获取数据并将其存储在列表中以在颤振小部件中使用?

将私有 api 密钥存储在颤振中

使用颤振 firebase_messaging 插件发送通知声音

无法更改下拉按钮值颤振