'Why am I getting this error when I do have a getter in my provider
In my provider class I have this code
List<Post> get items {
return [..._items]; //spread operator to copy the list
}
And in my list widget I have this
Widget build(BuildContext context) {
final post = Provider.of<Posts>(context);
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: GestureDetector(
onTap: () {
Navigator.of(context).pushNamed(
ProductDetailScreen.routeName,
arguments: post.id,
);
},
Can someone tell me why I am getting this error..
The getter 'id' isn't defined for the type 'Posts'. Try importing the library that defines 'id', correcting the name to the name of an existing getter, or defining a getter or field named 'id'.
Solution 1:[1]
It seems like there is some kind of confusion here with the Provider. So I can see that you are getting the Posts class, is that the one you want to get? And does this class/model/entity contain an attribute id.
It feels to me like you are trying to get a Post instead of Posts. Just let me know if this helps and if not, please clarify what you want to achieve and show the other code of the Posts
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sam Smets |
