Created
March 31, 2021 07:23
-
-
Save suragch/2b28048756de667a834eacf06b85802d to your computer and use it in GitHub Desktop.
Services: counter UI
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'; | |
class CounterScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return ViewModelBuilder<CounterViewModel>.reactive( | |
viewModelBuilder: () { | |
// Load the old value the first time the page is built | |
final viewModel = CounterViewModel(); | |
viewModel.loadData(); | |
return viewModel; | |
}, | |
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}', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
model.increment(); | |
}, | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment