Skip to content

Instantly share code, notes, and snippets.

@leohmoraes
Last active February 12, 2020 00:45
Show Gist options
  • Save leohmoraes/078f00a6e5d75c252eaa9a4177c1aa05 to your computer and use it in GitHub Desktop.
Save leohmoraes/078f00a6e5d75c252eaa9a4177c1aa05 to your computer and use it in GitHub Desktop.
42. Stateless e Stateful - Daniel Ciolfi - Curso Flutter
/*
Rode na web
https://dartpad.dev/078f00a6e5d75c252eaa9a4177c1aa05
*/
import 'package:flutter/material.dart';
/* 001
void main() {
runApp(MaterialApp(
title: "Contador de Pessoas",
home: Container(
color: Colors.white,
)
)); //MyApp()
}
*/
//002 - Layout, StateLess -> StateFull
void main() {
runApp(MaterialApp(title: "Contador de Pessoas", home: Home())); //MyApp()
}
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
int _people = 0;
String _infoText = "Pode Entrar!";
void _changePeople(int delta) {
setState(() {
_people += delta;
if(_people < 0)
_infoText = "Mundo Invertido";
else if(_people <= 10)
_infoText = "Pode Entrar";
else
_infoText = "Lotado!";
});
}
@override
Widget build(BuildContext context) {
return Stack(children: <Widget>[
Container(color: Colors.grey), //troquei para Container pois não sei neste momento importar uma imagem da web
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Pessoas: $_people",
style:
TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
Padding(
padding: EdgeInsets.all(10.0),
child: FlatButton(
child: Text("+1",
style: TextStyle(color: Colors.white, fontSize: 40)),
onPressed: () {
debugPrint("+1");
_changePeople(1);
},
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: FlatButton(
child: Text("-1",
style: TextStyle(color: Colors.white, fontSize: 40)),
onPressed: () {
_changePeople(-1);
},
),
)
]),
Text("$_infoText",
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.italic,
fontSize: 30)),
],
)
]);
}
}
/*
Padrao dartpad.dev
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text('Hello, World!', style: Theme.of(context).textTheme.display1);
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment