Understanding Application States in Flutter

By | June 3, 2019

This example is all about understanding Application States in flutter. Although it seems simple, it’s very important.

If you are an Android or iOS Developer, you may be familier with these concepts and callbacks.

Andrid has onResume, onPause etc callbacks, iOS has viewWillDisappear,viewDidAppear, didFinishLaunchingWithOptions etc callback functions to acheive this.

These funtions are useful most of the times when we want to save something when Application goes to background or is coming to ForeGround.

Watch Video Tutorial

So Let’s Start…

Flutter acheives similar functionality with the help of a class called WidgetsBindingObserver. Then we can override the method ‘didChangeAppLifecycleState’ to get the Application States. Make sure you add the observer and remove the observer when it is not needed.

The simple code below explains all these.

Complete Source Code

import 'package:flutter/material.dart';

class AppStateDemo extends StatefulWidget {
  AppStateDemo() : super();

  final String title = "AppState Demo";

  AppStateDemoState createState() => AppStateDemoState();

class AppStateDemoState extends State<AppStateDemo>
    with WidgetsBindingObserver {
  void initState() {

  void dispose() {

  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.inactive:
        print("App Inactive");
      case AppLifecycleState.paused:
        print("App Paused");
      case AppLifecycleState.resumed:
        print("App Resumed");
      case AppLifecycleState.suspending:
        print("App Suspending");

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      body: Center(
        child: Text(
          "App State Demo",
          style: TextStyle(fontSize: 25.0),

When your application goes to background, the ‘Inactive’ is triggered. When it is
completely minimised, ‘Paused’ will be triggered. and when it comes to ForeGround, the ‘Resumed’ will be triggered. Suspended will be triggered when the OS actually suspends the application.

Watch the youtube tutorial to see it in action.

Thanks for reading.
Subscribe to my youtube channel for more videos.


Leave a Reply

Your email address will not be published. Required fields are marked *