iampawan / 30DaysOfFlutter

Learn Flutter in 30 Days
413 stars 323 forks source link

The non-nullable variable 'items' must be initialized. Try adding an initializer expression. #25

Closed codersangam closed 2 years ago

codersangam commented 3 years ago

I removed the first item which is added on catalog.dart . Logically if we see, it can be null so that we fetch data from network or json files. But after removing that first item. It shows an error. class CatalogModel { static List<Item> items; } Please review it once.

maskeyp commented 2 years ago

have you found the solution yet?

codersangam commented 2 years ago

Use Null Safety:static List<Item>? items;

maskeyp commented 2 years ago

Thankyou!!1 i have another problem though in catalog.dart ---code---

factory Item.fromMap(Map<String, dynamic> map) { if (map == null) return null;

return Item(
  id: map['id'],
  name: map['name'],
  desc: map['desc'],
  price: map['price'],
  color: map['color'],
  image: map['image'],
);

}

--------A value of type 'Null' can't be returned from the constructor 'Item.fromMap' because it has a return type of 'Item'.

codersangam commented 2 years ago

checkout here: https://github.com/codersangam/thirtydays_flutter

maskeyp commented 2 years ago

Thankyou !!