未处理的异常:NoSuchMethodError:类 '_InternalLinkedHashMap<String, dynamic>' 没有实例方法 'call'

时间:2021-01-15 07:12:02

标签: firebase flutter dart

我对 Flutter 很陌生,刚刚开始学习 FireBase。当我第一次编写应用程序时,它运行良好,但在电脑重启后,它停止工作。

我是用教程制作的,并阅读了教程代码,但仍然找不到错误。 错误:

 [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'call'.
E/flutter (15666): Receiver: _LinkedHashMap len:5
E/flutter (15666): Tried calling: call(description: "Cat with blue eyes and white coat", id: "-MR06yNSd50YEtbjKMRN", imageUrl: "https://cdn.pixabay.com/photo/2020/11/10/01/34/pet-5728249__340.jpg", isFavorite: false, 
price: 100.0, title: "Cat ")
E/flutter (15666): #0      ProductsProvider.fetchAndSetProducts (package:shopapp/providers/products_provider.dart:90:7)
E/flutter (15666): <asynchronous suspension>

那是调试输出;据此错误出现在这里:

Future<void> fetchAndSetProducts() async {
    const url =
        'https://shopapptutorial-6ecf7-default-rtdb.firebaseio.com/products.json';
    try {
      final response = await http.get(url);
      final extractedData = json.decode(response.body) as Map<String, dynamic>;
      final List<ProductData> loadedProducts = [];
      extractedData.forEach((prodId, prodData) {
        loadedProducts.add(prodData(
          id: prodId,
          description: prodData['description'],
          imageUrl: prodData['imageUrl'],
          isFavorite: prodData['isFavorite'],
          price: prodData['price'],
          title: prodData['title'],
        ));
      });
      _items = loadedProducts;
      notifyListeners();
    } catch (error) {
      throw (error);
    }
  }

我真的不知道该怎么办!非常感谢任何帮助!

0 个答案:

没有答案