0

Output Error:

The following NoSuchMethodError was thrown building ScopedModelDescendant<MainModel>(dirty, dependencies: [_InheritedModel<MainModel>]):
The getter 'sampleVariable' was called on null.
Receiver: null
Tried calling: sampleVariable

Scenario: I have multiple classes that extends Model chained to one main class (i.e. MainModel). Now, i've updated a variable within one of the classes that I have extended from the Model of "scoped model". When I tried to access that variable after navigated to another component it raises a "NoSuchMethodError" => The getter "variable" was called on null. Could that be a bug?

The one that populates the variable:

...
sampleVariable = 'NewData';
notifyListeners();
Navigator.pushNamed(context, 'newPage');

newPage component tries to get the variable "sampleVariable":

...
ScopedModelDescendant<MainModel>(
          builder: (BuildContext context, Widget child, MainModel model) {
        print(model.sampleVariable);
...
}),
...

And the wierd part is it prints the variable "sampleVariable" value when "Restart" button triggered from the vscode flutter actions.

MWA
  • 51
  • 2
  • 11

1 Answers1

0

Looks like I have a duplicate class object across the whole app. I fixed it by relying on just one class object of a single class that extends the Model of "Scoped Model".

MWA
  • 51
  • 2
  • 11