nested-navigation-demo-flutter
nested-navigation-demo-flutter copied to clipboard
Issue: Changing one tab triggers the build method of other tabs.
I notice that changing 1 tab will trigger the build method of other tabs which is very bad for performance I think. For example, In ColorsListPage
class, I added the log line in the build method, and when I change the tab I can see the build method of other tabs are called:
@override
Widget build(BuildContext context) {
log('Rebuild: $title.');
return Scaffold(
appBar: AppBar(
title: Text(
title,
),
backgroundColor: color,
),
body: Container(
color: Colors.white,
child: _buildList(),
));
}
Hello, yes also to me it seems that there are too many rebuilds, all TabNavigators and all Views are rebuilt as well. See here my custom log:
Restarted application in 2,156ms.
I/flutter (29343): 15:59:51.589 [AppState] build
I/flutter (29343): 15:59:51.831 [TabNavigator] build
I/flutter (29343): 15:59:51.838 [TabNavigator] tabItem:[TabItem.shop] routeSettings.name:[/]
I/flutter (29343): 15:59:51.896 [ViewCategories] build
I/flutter (29343): 15:59:52.262 [TabNavigator] build
I/flutter (29343): 15:59:52.264 [TabNavigator] tabItem:[TabItem.search] routeSettings.name:[/]
I/flutter (29343): 15:59:52.306 [ViewSearch] build
I/flutter (29343): 15:59:52.351 [TabNavigator] build
I/flutter (29343): 15:59:52.354 [TabNavigator] tabItem:[TabItem.cart] routeSettings.name:[/]
I/flutter (29343): 15:59:52.387 [ViewCart] build
I/flutter (29343): 15:59:52.441 [TabNavigator] build
I/flutter (29343): 15:59:52.445 [TabNavigator] tabItem:[TabItem.profile] routeSettings.name:[/]
I/flutter (29343): 15:59:52.478 [ViewProfile] build
I/flutter (29343): 16:00:09.336 [AppState] _selectTab:[TabItem.search]
I/flutter (29343): 16:00:09.358 [AppState] build
I/flutter (29343): 16:00:09.378 [TabNavigator] build
I/flutter (29343): 16:00:09.391 [TabNavigator] build
I/flutter (29343): 16:00:09.393 [TabNavigator] build
I/flutter (29343): 16:00:09.394 [TabNavigator] build
I/flutter (29343): 16:00:09.437 [ViewCategories] build
I/flutter (29343): 16:00:09.449 [ViewSearch] build
I/flutter (29343): 16:00:09.454 [ViewCart] build
I/flutter (29343): 16:00:09.461 [ViewProfile] build
Got any solution for that?
@shikharLogic yes. I got this excellent approach: https://stackoverflow.com/a/66404760/2328861