Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
888b141a
Unverified
Commit
888b141a
authored
Sep 20, 2022
by
Zlati Pehlivanov
Committed by
GitHub
Sep 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: bottom navigation bar colors (#107924)
parent
29943e5f
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
422 additions
and
26 deletions
+422
-26
bottom_navigation_bar.dart
packages/flutter/lib/src/material/bottom_navigation_bar.dart
+123
-18
bottom_navigation_bar_test.dart
...ges/flutter/test/material/bottom_navigation_bar_test.dart
+299
-8
No files found.
packages/flutter/lib/src/material/bottom_navigation_bar.dart
View file @
888b141a
...
...
@@ -154,6 +154,11 @@ class BottomNavigationBar extends StatefulWidget {
/// [selectedIconTheme] and [unselectedIconTheme], and both
/// [IconThemeData.color] and [IconThemeData.size] must be set.
///
/// If [useLegacyColorScheme] is set to `false`
/// [selectedIconTheme] values will be used instead of [iconSize] and [selectedItemColor] for selected icons.
/// [unselectedIconTheme] values will be used instead of [iconSize] and [unselectedItemColor] for unselected icons.
///
///
/// If both [selectedLabelStyle].fontSize and [selectedFontSize] are set,
/// [selectedLabelStyle].fontSize will be used.
///
...
...
@@ -193,6 +198,7 @@ class BottomNavigationBar extends StatefulWidget {
this
.
mouseCursor
,
this
.
enableFeedback
,
this
.
landscapeLayout
,
this
.
useLegacyColorScheme
=
true
,
})
:
assert
(
items
!=
null
),
assert
(
items
.
length
>=
2
),
assert
(
...
...
@@ -381,6 +387,13 @@ class BottomNavigationBar extends StatefulWidget {
/// orientation.
final
BottomNavigationBarLandscapeLayout
?
landscapeLayout
;
/// This flag is controlling how [BottomNavigationBar] is going to use
/// the colors provided by the [selectedIconTheme], [unselectedIconTheme],
/// [selectedItemColor], [unselectedItemColor].
/// The default value is `true` as the new theming logic is a breaking change.
/// To opt-in the new theming logic set the flag to `false`
final
bool
useLegacyColorScheme
;
@override
State
<
BottomNavigationBar
>
createState
()
=>
_BottomNavigationBarState
();
}
...
...
@@ -394,7 +407,8 @@ class _BottomNavigationTile extends StatelessWidget {
this
.
animation
,
this
.
iconSize
,
{
this
.
onTap
,
this
.
colorTween
,
this
.
labelColorTween
,
this
.
iconColorTween
,
this
.
flex
,
this
.
selected
=
false
,
required
this
.
selectedLabelStyle
,
...
...
@@ -420,7 +434,8 @@ class _BottomNavigationTile extends StatelessWidget {
final
Animation
<
double
>
animation
;
final
double
iconSize
;
final
VoidCallback
?
onTap
;
final
ColorTween
?
colorTween
;
final
ColorTween
?
labelColorTween
;
final
ColorTween
?
iconColorTween
;
final
double
?
flex
;
final
bool
selected
;
final
IconThemeData
?
selectedIconTheme
;
...
...
@@ -523,7 +538,7 @@ class _BottomNavigationTile extends StatelessWidget {
child:
_Tile
(
layout:
layout
,
icon:
_TileIcon
(
colorTween:
c
olorTween
!,
colorTween:
iconC
olorTween
!,
animation:
animation
,
iconSize:
iconSize
,
selected:
selected
,
...
...
@@ -532,7 +547,7 @@ class _BottomNavigationTile extends StatelessWidget {
unselectedIconTheme:
unselectedIconTheme
,
),
label:
_Label
(
colorTween:
c
olorTween
!,
colorTween:
labelC
olorTween
!,
animation:
animation
,
item:
item
,
selectedLabelStyle:
selectedLabelStyle
,
...
...
@@ -910,6 +925,15 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
return
textStyle
.
fontSize
==
null
?
textStyle
.
copyWith
(
fontSize:
fontSize
)
:
textStyle
;
}
// If [IconThemeData] is provided, it should be used.
// Otherwise, the [IconThemeData]'s color should be selectedItemColor
// or unselectedItemColor.
static
IconThemeData
_effectiveIconTheme
(
IconThemeData
?
iconTheme
,
Color
?
itemColor
)
{
// Prefer the iconTheme over itemColor if present.
return
iconTheme
??
IconThemeData
(
color:
itemColor
);
}
List
<
Widget
>
_createTiles
(
BottomNavigationBarLandscapeLayout
layout
)
{
final
MaterialLocalizations
localizations
=
MaterialLocalizations
.
of
(
context
);
assert
(
localizations
!=
null
);
...
...
@@ -917,17 +941,6 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
final
ThemeData
themeData
=
Theme
.
of
(
context
);
final
BottomNavigationBarThemeData
bottomTheme
=
BottomNavigationBarTheme
.
of
(
context
);
final
TextStyle
effectiveSelectedLabelStyle
=
_effectiveTextStyle
(
widget
.
selectedLabelStyle
??
bottomTheme
.
selectedLabelStyle
,
widget
.
selectedFontSize
,
);
final
TextStyle
effectiveUnselectedLabelStyle
=
_effectiveTextStyle
(
widget
.
unselectedLabelStyle
??
bottomTheme
.
unselectedLabelStyle
,
widget
.
unselectedFontSize
,
);
final
Color
themeColor
;
switch
(
themeData
.
brightness
)
{
case
Brightness
.
light
:
...
...
@@ -938,6 +951,39 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
break
;
}
final
TextStyle
effectiveSelectedLabelStyle
=
_effectiveTextStyle
(
widget
.
selectedLabelStyle
??
bottomTheme
.
selectedLabelStyle
,
widget
.
selectedFontSize
,
);
final
TextStyle
effectiveUnselectedLabelStyle
=
_effectiveTextStyle
(
widget
.
unselectedLabelStyle
??
bottomTheme
.
unselectedLabelStyle
,
widget
.
unselectedFontSize
,
);
final
IconThemeData
effectiveSelectedIconTheme
=
_effectiveIconTheme
(
widget
.
selectedIconTheme
??
bottomTheme
.
selectedIconTheme
,
widget
.
selectedItemColor
??
bottomTheme
.
selectedItemColor
??
themeColor
);
final
IconThemeData
effectiveUnselectedIconTheme
=
_effectiveIconTheme
(
widget
.
unselectedIconTheme
??
bottomTheme
.
unselectedIconTheme
,
widget
.
unselectedItemColor
??
bottomTheme
.
unselectedItemColor
??
themeData
.
unselectedWidgetColor
);
final
ColorTween
colorTween
;
switch
(
_effectiveType
)
{
case
BottomNavigationBarType
.
fixed
:
...
...
@@ -963,6 +1009,64 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
break
;
}
final
ColorTween
labelColorTween
;
switch
(
_effectiveType
)
{
case
BottomNavigationBarType
.
fixed
:
labelColorTween
=
ColorTween
(
begin:
effectiveUnselectedLabelStyle
.
color
??
widget
.
unselectedItemColor
??
bottomTheme
.
unselectedItemColor
??
themeData
.
unselectedWidgetColor
,
end:
effectiveSelectedLabelStyle
.
color
??
widget
.
selectedItemColor
??
bottomTheme
.
selectedItemColor
??
widget
.
fixedColor
??
themeColor
,
);
break
;
case
BottomNavigationBarType
.
shifting
:
labelColorTween
=
ColorTween
(
begin:
effectiveUnselectedLabelStyle
.
color
??
widget
.
unselectedItemColor
??
bottomTheme
.
unselectedItemColor
??
themeData
.
colorScheme
.
surface
,
end:
effectiveSelectedLabelStyle
.
color
??
widget
.
selectedItemColor
??
bottomTheme
.
selectedItemColor
??
themeColor
,
);
break
;
}
final
ColorTween
iconColorTween
;
switch
(
_effectiveType
)
{
case
BottomNavigationBarType
.
fixed
:
iconColorTween
=
ColorTween
(
begin:
effectiveSelectedIconTheme
.
color
??
widget
.
unselectedItemColor
??
bottomTheme
.
unselectedItemColor
??
themeData
.
unselectedWidgetColor
,
end:
effectiveUnselectedIconTheme
.
color
??
widget
.
selectedItemColor
??
bottomTheme
.
selectedItemColor
??
widget
.
fixedColor
??
themeColor
,
);
break
;
case
BottomNavigationBarType
.
shifting
:
iconColorTween
=
ColorTween
(
begin:
effectiveUnselectedIconTheme
.
color
??
widget
.
unselectedItemColor
??
bottomTheme
.
unselectedItemColor
??
themeData
.
colorScheme
.
surface
,
end:
effectiveSelectedIconTheme
.
color
??
widget
.
selectedItemColor
??
bottomTheme
.
selectedItemColor
??
themeColor
,
);
break
;
}
final
List
<
Widget
>
tiles
=
<
Widget
>[];
for
(
int
i
=
0
;
i
<
widget
.
items
.
length
;
i
++)
{
final
Set
<
MaterialState
>
states
=
<
MaterialState
>{
...
...
@@ -978,15 +1082,16 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
widget
.
items
[
i
],
_animations
[
i
],
widget
.
iconSize
,
selectedIconTheme:
widget
.
selectedIconTheme
??
bottomTheme
.
s
electedIconTheme
,
unselectedIconTheme:
widget
.
u
nselectedIconTheme
??
bottomTheme
.
u
nselectedIconTheme
,
selectedIconTheme:
widget
.
useLegacyColorScheme
?
widget
.
selectedIconTheme
??
bottomTheme
.
selectedIconTheme
:
effectiveS
electedIconTheme
,
unselectedIconTheme:
widget
.
u
seLegacyColorScheme
?
widget
.
unselectedIconTheme
??
bottomTheme
.
unselectedIconTheme
:
effectiveU
nselectedIconTheme
,
selectedLabelStyle:
effectiveSelectedLabelStyle
,
unselectedLabelStyle:
effectiveUnselectedLabelStyle
,
enableFeedback:
widget
.
enableFeedback
??
bottomTheme
.
enableFeedback
??
true
,
onTap:
()
{
widget
.
onTap
?.
call
(
i
);
},
colorTween:
colorTween
,
labelColorTween:
widget
.
useLegacyColorScheme
?
colorTween
:
labelColorTween
,
iconColorTween:
widget
.
useLegacyColorScheme
?
colorTween
:
iconColorTween
,
flex:
_evaluateFlex
(
_animations
[
i
]),
selected:
i
==
widget
.
currentIndex
,
showSelectedLabels:
widget
.
showSelectedLabels
??
bottomTheme
.
showSelectedLabels
??
true
,
...
...
packages/flutter/test/material/bottom_navigation_bar_test.dart
View file @
888b141a
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment