Skip to content

Instantly share code, notes, and snippets.

@KickedDroid
Created January 8, 2019 01:03
Show Gist options
  • Save KickedDroid/55d8ed73b035313a458f266cef626c04 to your computer and use it in GitHub Desktop.
Save KickedDroid/55d8ed73b035313a458f266cef626c04 to your computer and use it in GitHub Desktop.
// Create our App, which will provide the `UserModel` to
// all children that require it!
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// First, create a `ScopedModel` widget. This will provide
// the `model` to the children that request it.
return new ScopedModel<UserModel>(
model: new UserModel(),
child: new Column(children: [
// Create a ScopedModelDescendant. This widget will get the
// UserModel from the nearest ScopedModel<UserModel>.
// It will hand that model to our builder method, and rebuild
// any time the UserModel changes (i.e. after we
// `notifyListeners` in the Model).
new ScopedModelDescendant<UserModel>(
// This text widget will display the value of userName and update when the value changes
builder: (context, child, model) => new Text('${model.userName}'),
),
])
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment