Skip to content

Instantly share code, notes, and snippets.

@jason19970210
Last active May 19, 2023 05:47
Show Gist options
  • Save jason19970210/888dc154afacf4d07893f58ed9b56a5e to your computer and use it in GitHub Desktop.
Save jason19970210/888dc154afacf4d07893f58ed9b56a5e to your computer and use it in GitHub Desktop.
Flutter App Lifecycle Test
// Date: 2023/05/19
// From anomoly user named SI from Line OpenChat Flutter-Disgussion-Group
// For Education & Learning Purpose
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
debugPrint('App初始化');
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
debugPrint('App bye');
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
switch (state) {
case AppLifecycleState.resumed:
debugPrint('AppLifecycleState.resumed:恢復');
break;
case AppLifecycleState.inactive:
debugPrint('AppLifecycleState.inactive:休息');
break;
case AppLifecycleState.paused:
debugPrint('AppLifecycleState.paused:關閉');
break;
case AppLifecycleState.detached:
debugPrint('AppLifecycleState.detached:分離');
break;
}
}
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment