import 'package:disco/disco.dart' ;
import 'package:flutter/material.dart' ;
abstract class Model extends ChangeNotifier {
class ModelImplementation extends Model {
int get counter => _counter;
void incrementCounter () {
final modelProvider = Provider < Model >((context) => ModelImplementation ());
class MainApp extends StatelessWidget {
const MainApp ({ super .key});
Widget build ( BuildContext context) {
primarySwatch : Colors .blue,
home : const MyHomePage (),
class MyHomePage extends StatelessWidget {
const MyHomePage ({ super .key});
Widget build ( BuildContext context) {
// Provide the modelProvider to descendants
providers : [modelProvider],
// This builder gives a descendant context, only descendants can access
final model = modelProvider. of (context);
mainAxisAlignment : MainAxisAlignment .center,
'You have pushed the button this many times:' ,
// Rebuilds this widget when the model changes
builder : (context, child) {
return Text (model.counter. toString ());
floatingActionButton : FloatingActionButton (
// increment the counter when the button is pressed
onPressed : model.incrementCounter,
child : const Icon ( Icons .add),