Repository navigation
BottomNavigationBar uses the wrong theme #19653
Description
Activity
BottomNavigationBaris not added as child, but as sibling ofMaterialAppYou can use the
builderparameter to get all dialogs, pages,BottomNavigationBar, ... wrapped in the theme you want to use application-wide.return new MaterialApp( builder: (context, widget) => Theme(data: currentTheme, child: widget), title: 'Flutter Demo', theme: currentTheme, home: new MyHomePage(title: 'Flutter Demo Home Page'), );
https://docs.flutter.io/flutter/material/MaterialApp/builder.html
@HansMuller is this the correct approach?
Does it make sense to pass abuilder:this way and thethemeparameter?- addedframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/and removed
on Jul 22, 2018 @zoechi While my app might be using themes incorrectly, the actual issue is not theme related.
The issue is that changing the
backgroundColorof anBottomNavigationBarItemin aBottomNavigationBardoes not actually update its color.While I admit that might be an edge case, I still believe it should do so.
Note that I made a Pull request already, which is not related to Themes (in factBottomNavigationBardoes not really seem to useTheme.ofthat often.I didn't investigate in detail but after the change I suggested the
BottomNavigationBarwas yellow instead of the blue it was before.@zoechi intresting. I suspect that that change prevents us from building my
DashboardPagewith wrong color in the first place (if you look at the logs, I print out the theme color in thebuild()method, it prints it once with the old color)But, while I certainly am willing to change the way my custom theming works, this is still an issue without Themes. Eg: The reason I mentioned Themes in my bug report (and in hindsight that was wrong), was because I am using
Theme.of(context)to choose a background color. I could very well have chosen another arbitrary 2 colors and switched between those two without ever looking at the theme.eg lets imagine a
BottomNavigationBarItemthat changes color every second (not sure why anyone would want that, but there is no reason why it should not be possible). It will still expose the bug and keep the incorrect color. Activating another item and then back to the same item will take the correct color for 1 second, but then will be stale again.See my Pull request (#19661) which fixes the issue by keeping the
_backgroundColorin sync with the selected item (did not test with the continues updates, but should work)If you prefer, I can make another small test case which does not uses themes, but some sort of other (local) trigger to change the color
Here's a simplified version of the original test case that demos the problem and validates the fix in #19661: https://gist.github.com/HansMuller/968aeba7981a5e0b6996f5600ab2d1c1
- added a commit that references this issue
on Nov 7, 2018 This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Sep 2, 2021
I am trying to build an aplication that changes its theme on runtime. When changing the theme, new BottomNavigationBars follow the wrong color until next state change.
Steps to Reproduce
https://gist.github.com/nathansamson/ac5a11e8a4d8e6d4d8b19610a267c931
The button changes themes, but also changes pages
In code speak
Also observe the build() of the encolosing widget that builds the BottomNavigationBar is being run multple times (see logs).
Note: when I switch to fixed layout (instead of shifting) the correct background colors are observed immediately.
Logs
(Full logs in the gist)