Created
June 18, 2020 23:17
-
-
Save felangel/b5b9e50b233592a79940c2b8a2752b71 to your computer and use it in GitHub Desktop.
StatefulWidget demo
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( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: MyChild(), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () => setState(() {}), | |
child: Icon(Icons.refresh), | |
), | |
); | |
} | |
} | |
class MyChild extends StatefulWidget { | |
@override | |
State<MyChild> createState() => _MyChildState(); | |
} | |
class _MyChildState extends State<MyChild> { | |
var i = 0; | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: RaisedButton( | |
child: Text('$i'), | |
onPressed: () => setState(() => i++), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment