I got this error after following a tutorial
Note: in the screenshot I tired _answersModel and answersModel but none worked.
Here is my Controller:
Then Here is my Model
How can I get rid of this error?
CodePudding user response:
Changing _answersModel to answersModel would fix your issue.
Also calling AnswersController.answersModel doesn't work because answersModel is not a static field, I think you meant call answersController.answersModel
Note: Adding an underscore to a class file is making it private field in dart/flutter which means it can't be accessed in another file.
CodePudding user response:
Make the _answersModel
in AnswersController
public by removing _
in the begging of name, like answersModel
.
Why in the tutorial it works? I may guess that in the tutorial the AnswersController
in the same file in main.dart
.