1
votes

I am very new to flutter and have just started learning FireBase. It was working fine when I first coded the app but then after a pc restart, it stopped working.

I was making this with a tutorial and read over the tutorials code but still could not find a fault. error:

 [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>

that is the debug output; according to that the error is coming in here:

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);
    }
  }

I am really not sure what to do! Any help is much appreciated!

1
loadedProducts.add(prodData(...)) calls prodData as a function, but it's a Map. You presumably meant loadedProducts.add(prodData[...]) (that is, square brackets instead of parentheses). - jamesdlin
I appreciate the help, doing that renders all the id, title, etc as undefined. - Jardine

1 Answers

0
votes

Problem solved, the issue was with loadedProducts.add(prodData( should be loadedProducts.add(ProductData( as in the class I created further up