Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
View for the Provider Architecture example
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 {
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(
children: <Widget>[
'You have pushed the button this many times:',
'${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