State ManagementAdvanced50 XP3 min read
What is Flutter's state restoration feature?
TL;DR: State restoration allows Flutter apps to restore UI state (scroll positions, form text, navigation stack) after the OS kills the app in the background. Implemented via RestorationMixin and RestorableProperty.
Full Answer
On mobile, the OS can kill background apps. When the user returns, a well-behaved app restores exactly where they left off — this is state restoration.
- ▸RestorationMixin — add to StatefulWidget's State to register restorable properties
- ▸RestorableInt, RestorableString, RestorableBool — typed restorable primitives
- ▸restorationId — unique ID per widget for the restoration bucket
- ▸MaterialApp(restorationScopeId: 'app') — enables restoration for the whole app
- ▸NavigatorState.restorablePushNamed() — adds restoration-compatible navigation
🎯
State restoration is an advanced feature often skipped in apps. Mentioning it in interviews for roles at large companies (where OS kills apps frequently due to background resource limits) is impressive.
Code Examples
dartRestorable counter
Output
Counter value survives OS process kill and app re-open
Common Mistakes
- ✗Forgetting to dispose RestorableProperty objects — causes memory leaks
- ✗Using the same restorationId on sibling widgets — causes restoration conflicts
Interview Tip
💡
Very few Flutter developers know state restoration well. Even mentioning it with basic accuracy impresses senior interviewers.
#state-restoration#RestorationMixin#PageStorageKey#OS-kill