Last active
March 31, 2021 04:27
-
-
Save suragch/06c531aa12ae5196511fa9594cdada5e to your computer and use it in GitHub Desktop.
View for the Provider Architecture example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:stacked/stacked.dart'; | |
import 'counter_viewmodel.dart'; | |
// Since the state was moved to the view model, this is now a StatelessWidget. | |
class CounterScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
// ViewModelBuilder is what provides the view model to the widget tree. | |
return ViewModelBuilder<CounterViewModel>.reactive( | |
viewModelBuilder: () => CounterViewModel(), | |
builder: (context, model, child) => Scaffold( | |
appBar: AppBar( | |
title: Text('Flutter Demo Home Page'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'You have pushed the button this many times:', | |
), | |
Text( | |
'${model.counter}', // <-- view model | |
style: Theme.of(context).textTheme.headline4, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
model.increment(); // <-- view model | |
}, | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment