Created
August 11, 2020 16:10
-
-
Save begomez/18abb932ff7156e39a0826dd68870077 to your computer and use it in GitHub Desktop.
Stateful widget lifecycle
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 StatefulWidget { | |
static final String TAG = "MyApp."; | |
MyApp() : super() { | |
print("${TAG}Constructor()"); | |
} | |
@override | |
State createState() { | |
print("${TAG}createState()"); | |
return _MyAppState(); | |
} | |
} | |
class _MyAppState extends State<MyApp> { | |
final String TAG = "_MyAppState."; | |
_MyAppState() : super() { | |
print("${TAG}Constructor()"); | |
} | |
@override | |
void didChangeDependencies() { | |
super.didChangeDependencies(); | |
print("${TAG}didChangeDependencies()"); | |
this._dump(); | |
} | |
@override | |
void didUpdateWidget(MyApp old) { | |
super.didUpdateWidget(old); | |
print("${TAG}didUpdateWidget()"); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
print("${TAG}initState()"); | |
this._dump(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
print("${TAG}build()"); | |
Future.delayed( | |
Duration(seconds: 1), | |
() => {_dump()} | |
); | |
return MaterialApp( | |
debugShowCheckedModeBanner: true, | |
theme: Theme.of(context), | |
home: Scaffold( | |
appBar: AppBar(title: Text("Stateful")), | |
body: Container(color: Colors.white) | |
) | |
); | |
} | |
@override | |
void dispose() { | |
print("${TAG}dispose()"); | |
} | |
void _dump() { | |
print("\t$context"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment