Advertisement
narimetisaigopi

Untitled

Jan 19th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class HomeScreen extends StatefulWidget {
  4. const HomeScreen({Key? key}) : super(key: key);
  5.  
  6. @override
  7. State<HomeScreen> createState() => _HomeScreenState();
  8. }
  9.  
  10. class _HomeScreenState extends State<HomeScreen> with WidgetsBindingObserver {
  11. @override
  12. void initState() {
  13. WidgetsBinding.instance!.addObserver(this);
  14. super.initState();
  15. }
  16.  
  17. @override
  18. void dispose() {
  19. WidgetsBinding.instance!.removeObserver(this);
  20. super.dispose();
  21. }
  22.  
  23. @override
  24. void didChangeAppLifecycleState(AppLifecycleState state) {
  25. super.didChangeAppLifecycleState(state);
  26. if (state == AppLifecycleState.resumed) {
  27. print("it is in resume state");
  28. }
  29. if (state == AppLifecycleState.inactive) {
  30. print("it is in inactive state");
  31. }
  32. if (state == AppLifecycleState.detached) {
  33. print("it is in detached state");
  34. }
  35. if (state == AppLifecycleState.paused) {
  36. print("it is in paused state");
  37. }
  38. // print("didChangeAppLifecycleState " + state.index.toString());
  39. }
  40.  
  41. @override
  42. Widget build(BuildContext context) {
  43. return Scaffold(
  44. appBar: AppBar(
  45. title: Text(
  46. "App States",
  47. ),
  48. centerTitle: true,
  49. ),
  50. body: Center(
  51. child: Text(
  52. "I\nLove\nšŸ‘Øā€šŸ’»šŸ‘©ā€šŸ’»",
  53. textAlign: TextAlign.center,
  54. style: TextStyle(fontSize: 80),
  55. ),
  56. ),
  57. );
  58. }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement