Last active
February 25, 2020 13:30
-
-
Save rubgithub/1de5aadf782fe2425214c625f7f6a214 to your computer and use it in GitHub Desktop.
Gerenciamento de Estado com StatelessWidget
This file contains hidden or 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'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Demo Sem Statefull-3'), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
MyHomePage({this.title}); | |
final String title; | |
@override | |
Widget build(BuildContext context) { | |
int _counter = 0; | |
return Container(child: | |
StatefulBuilder(builder: (BuildContext context, StateSetter setState) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
'You have pushed the button this many times:', | |
), | |
Text( | |
'$_counter', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
_counter++; | |
}); | |
}, | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), | |
); | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment