【问题标题】:NoSuchMethodError (NoSuchMethodError: Class 'bool' has no instance method '[]'. Receiver: true Tried calling: []("title"))NoSuchMethodError(NoSuchMethodError:类 \'bool\' 没有实例方法 \'[]\'。接收方:true 已尝试调用:[](\"title\"))
【发布时间】:2022-12-03 16:43:55
【问题描述】:
 Future<void> fetchAndsetProduct() async {
    final url =Uri.parse( \'https://shoppingapp-ef04b-default-rtdb.firebaseio.com/product.json\');
    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);
    }
  }

Unhandled Exception: NoSuchMethodError: Class \'bool\' has no instance method \'[]\'.

i was trying to solve this problem , but iam unable to do that

    标签: flutter dart dart-null-safety


    【解决方案1】:
    猜你喜欢
    • 2022-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 2021-10-02
    相关资源
    最近更新 更多