Flutter | How to pause / unpause a widget and all its descendants?

Viewed 38

In my Flutter app, I have a tabbar. Each tap is its own widget with lots of descendants widgets (see diagram).

In the Scaffold building the tabbar, the children are located in a IndexedStack widget - this is super cool, since it allows the user to change tabs without losing state.

Problem: Since we use IndexedStack, the entire widget tree for inactive (i.e in background) tabs are preserved, and all animations/servercalls are executed regardless.

Question: Is it possible to pause a widget + all the widgets descendants?

Expected result: Widgets gets paused/unpaused if they are in foreground or background, preserving resources but still not losing state.

enter image description here

Example:

Scaffold(
body: IndexedStack(index: i, children: [TabA(), TabB(), TabC()], // <- How to pause/unpause TabA, TabB, TabC?
bottomNavigationBar: // Tabbar widget here
)
0 Answers
Related