Issue
I'm new to flutter. I'm accessing a property-"startingProduct" in a State Class. The variable was defined in A StatefulWidget Class. But I get "startingProduct is not defined". How do I fix the code?
final String startingProduct; // `StatefulWidget` class
ProductManager(this.startingProduct); // `StatefulWidget` class
_products.add(widget.startingProduct); // `State` class
Error: The getter 'startingProduct' isn't defined for the class 'StatefulWidget'.
Solution
In this case, you most likely forgot to specify the type of the State
class.
You should use the following syntax:
class _ExampleState extends State<Example> { // in this case `Example` is your StatefulWidget class
To be more clear: I mean that you need to specify the optional type argument T
as your StatefulWidget
class, e.g. extends State<Example>
instead of extends State
.
Answered By - creativecreatorormaybenot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.