D
Flutter CoreEasy20 XP3 min read

What are Flutter's AppLifecycleState values and when do they trigger?

TL;DR: AppLifecycleState has four values: resumed (visible and active), inactive (visible but not focused, e.g., phone call), paused (in background, not visible), and detached (engine running, no view).

Full Answer

AspectStateMeaning
resumedApp is visible and responding to user inputNormal active state
inactiveApp is visible but not focused (iOS: Spotlight, phone call)Pause heavy work
pausedApp in background, not visibleSave state, stop updates
detachedEngine running without a viewDuring app termination flow
🎯

Use WidgetsBindingObserver mixin and override didChangeAppLifecycleState to respond to lifecycle changes. Common use case: pause video playback when paused, resume when resumed.

Code Examples

dartObserving app lifecycle changes
Output
Console prints appropriate message when app changes lifecycle state.

Interview Tip

💡

Always remove the observer in dispose() to avoid memory leaks. The observer pattern here mirrors Android's onResume/onPause lifecycle methods.

#lifecycle#applifecyclestate#resumed#paused#inactive