brianegan / flutter_redux

A library that connects Widgets to a Redux Store
MIT License
1.65k stars 219 forks source link

how to fix this error "another exception was thrown: NoSuchMethodError: The getter 'name' was called on null"? (flutter) #199

Closed Noorsat3 closed 3 years ago

Noorsat3 commented 3 years ago

I'm trying to call the name and the price and image url from Items_list.dart,

here is the code for calling them: ` // this is to get items list info from the Items_lists.dart final items item; _FruitsState({@required this.item});

@override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.only(bottom: 0.0), child: GridView.builder( shrinkWrap: true, itemCount: fruitsItemsList.fruitsItems.length, gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, childAspectRatio: height / width / 3, ), itemBuilder: (BuildContext context, int index) { return single_fruit( prodName: item.name, prodPrice: item.price, prodPicture: item.picture, ); }), );`

//And this is the Items_list.dart: FruitsItemsList fruitsItemsList = FruitsItemsList(fruitsItems: [ items( id: 001, name: "kiwi", picture: "assets/kiwi1.jpg", price: 7, ), items( id: 002, name: "avocado", picture: "assets/a1.jpg", price: 11, ),

]);

class FruitsItemsList { List fruitsItems; FruitsItemsList({@required this.fruitsItems}); }

class items { int id; String name; double price; String picture; int quantity;

items({ @required this.id, @required this.name, @required this.price, @required this.picture, this.quantity = 1, });

}

Error that I got: The following NoSuchMethodError was thrown building: The getter 'name' was called on null. Receiver: null Tried calling: name // and for the price and picture to not only name.