Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Changing one tab triggers the build method of other tabs. #15

Open
tuanbs opened this issue Apr 29, 2021 · 3 comments
Open

Issue: Changing one tab triggers the build method of other tabs. #15

tuanbs opened this issue Apr 29, 2021 · 3 comments

Comments

@tuanbs
Copy link

tuanbs commented Apr 29, 2021

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(),
        ));
  }
@camillo777
Copy link

camillo777 commented May 21, 2021

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

@shikharLogic
Copy link

Got any solution for that?

@tuanbs
Copy link
Author

tuanbs commented Jul 30, 2021

@shikharLogic yes. I got this excellent approach: https://stackoverflow.com/a/66404760/2328861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants