Created
December 4, 2019 16:17
-
-
Save r3dm1ke/5e6150a9255863fe299f0aa9df469e2d to your computer and use it in GitHub Desktop.
Using Stateful component in Flutter
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
| // The sole reason we keep this extra component is | |
| // because runApp will only take a StatelessWidget as its argument | |
| class TODOApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return TODO(); | |
| } | |
| } | |
| // Here we are defining a StatefulWidget | |
| class TODO extends StatefulWidget { | |
| // Every stateful widget must override createState | |
| @override | |
| State<StatefulWidget> createState() { | |
| return TODOState(); | |
| } | |
| } | |
| // This is the state for then TODO widget | |
| class TODOState extends State<TODO> { | |
| // We define the properties for the widget in its state | |
| final List<Task> tasks = [ | |
| Task('Do homework'), | |
| Task('Laundry'), | |
| Task('Finish this tutorial') | |
| ]; | |
| // Now state is responsible for building the widget | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'TODO app', | |
| initialRoute: '/', | |
| routes: { | |
| '/': (context) => TODOList(tasks: tasks), | |
| '/create': (context) => TODOCreate(), | |
| }, | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment