Skip to content

Instantly share code, notes, and snippets.

@jacobaraujo7
Created June 27, 2020 02:04
Show Gist options
  • Save jacobaraujo7/5523f4c756d44c258476188fdcdddbd2 to your computer and use it in GitHub Desktop.
Save jacobaraujo7/5523f4c756d44c258476188fdcdddbd2 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
final CounterModel counterModel = CounterModel();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: AnimatedBuilder(
animation: counterModel,
builder: (context, _) {
return Text(
'Counter ChangeNotifier - ${counterModel.value}',
);
}),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
AnimatedBuilder(
animation: counterModel,
builder: (context, _) {
return Text(
'${counterModel.value}',
style: Theme.of(context).textTheme.bodyText1,
);
}),
],
),
),
floatingActionButton: Container(
width: 100.0,
height: 100.0,
child: FloatingActionButton(
onPressed: counterModel.increment
,
tooltip: 'Increment',
child: Icon(Icons.add),
),
),
);
}
}
class CounterModel extends ChangeNotifier {
var value = 0;
void increment() {
value++;
//executa todas as funções!
notifyListeners();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment