Last active
June 18, 2020 23:13
-
-
Save felangel/43e65c4687c4c96dbf22de6bcb3dfd32 to your computer and use it in GitHub Desktop.
StatefulBuilder Demo
This file contains 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 StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
var i = 0; | |
return StatefulBuilder(builder: (context, setState) { | |
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