flutterdartflutter-animation

Flutter: Tabbarview - is it a bad idea to dispose it often


I have a Tabbarview in my app, and I have many error states, that must hide tab bars, tab content, etc - everything related to tabs. How bad is it to switch between these views constantly? Should I preserve (not dispose) Tabbarview for all costs for the sake of cpu and responsiveness?


Solution

  • Use a Stack to overlay error messages or loading indicators on top of the TabBarView. This way, the TabBarView remains in the widget tree but is visually obscured.

     Stack(
           children: [
               TabBarView(
                   // ... your tab bar view content
               ),
               if (errorState) ErrorOverlay()
           ],
       )