Skip to content

Instantly share code, notes, and snippets.

@suragch
Created March 31, 2021 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suragch/2b28048756de667a834eacf06b85802d to your computer and use it in GitHub Desktop.
Save suragch/2b28048756de667a834eacf06b85802d to your computer and use it in GitHub Desktop.
Services: counter UI
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