Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- class HomeScreen extends StatefulWidget {
- const HomeScreen({Key? key}) : super(key: key);
- @override
- State<HomeScreen> createState() => _HomeScreenState();
- }
- class _HomeScreenState extends State<HomeScreen> with WidgetsBindingObserver {
- @override
- void initState() {
- WidgetsBinding.instance!.addObserver(this);
- super.initState();
- }
- @override
- void dispose() {
- WidgetsBinding.instance!.removeObserver(this);
- super.dispose();
- }
- @override
- void didChangeAppLifecycleState(AppLifecycleState state) {
- super.didChangeAppLifecycleState(state);
- if (state == AppLifecycleState.resumed) {
- print("it is in resume state");
- }
- if (state == AppLifecycleState.inactive) {
- print("it is in inactive state");
- }
- if (state == AppLifecycleState.detached) {
- print("it is in detached state");
- }
- if (state == AppLifecycleState.paused) {
- print("it is in paused state");
- }
- // print("didChangeAppLifecycleState " + state.index.toString());
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(
- "App States",
- ),
- centerTitle: true,
- ),
- body: Center(
- child: Text(
- "I\nLove\nšØāš»š©āš»",
- textAlign: TextAlign.center,
- style: TextStyle(fontSize: 80),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement