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 {
...
@@ -154,6 +154,11 @@ class BottomNavigationBar extends StatefulWidget {
/// [selectedIconTheme] and [unselectedIconTheme], and both
/// [selectedIconTheme] and [unselectedIconTheme], and both
/// [IconThemeData.color] and [IconThemeData.size] must be set.
/// [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,
/// If both [selectedLabelStyle].fontSize and [selectedFontSize] are set,
/// [selectedLabelStyle].fontSize will be used.
/// [selectedLabelStyle].fontSize will be used.
///
///
...
@@ -193,6 +198,7 @@ class BottomNavigationBar extends StatefulWidget {
...
@@ -193,6 +198,7 @@ class BottomNavigationBar extends StatefulWidget {
this
.
mouseCursor
,
this
.
mouseCursor
,
this
.
enableFeedback
,
this
.
enableFeedback
,
this
.
landscapeLayout
,
this
.
landscapeLayout
,
this
.
useLegacyColorScheme
=
true
,
})
:
assert
(
items
!=
null
),
})
:
assert
(
items
!=
null
),
assert
(
items
.
length
>=
2
),
assert
(
items
.
length
>=
2
),
assert
(
assert
(
...
@@ -381,6 +387,13 @@ class BottomNavigationBar extends StatefulWidget {
...
@@ -381,6 +387,13 @@ class BottomNavigationBar extends StatefulWidget {
/// orientation.
/// orientation.
final
BottomNavigationBarLandscapeLayout
?
landscapeLayout
;
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
@override
State
<
BottomNavigationBar
>
createState
()
=>
_BottomNavigationBarState
();
State
<
BottomNavigationBar
>
createState
()
=>
_BottomNavigationBarState
();
}
}
...
@@ -394,7 +407,8 @@ class _BottomNavigationTile extends StatelessWidget {
...
@@ -394,7 +407,8 @@ class _BottomNavigationTile extends StatelessWidget {
this
.
animation
,
this
.
animation
,
this
.
iconSize
,
{
this
.
iconSize
,
{
this
.
onTap
,
this
.
onTap
,
this
.
colorTween
,
this
.
labelColorTween
,
this
.
iconColorTween
,
this
.
flex
,
this
.
flex
,
this
.
selected
=
false
,
this
.
selected
=
false
,
required
this
.
selectedLabelStyle
,
required
this
.
selectedLabelStyle
,
...
@@ -420,7 +434,8 @@ class _BottomNavigationTile extends StatelessWidget {
...
@@ -420,7 +434,8 @@ class _BottomNavigationTile extends StatelessWidget {
final
Animation
<
double
>
animation
;
final
Animation
<
double
>
animation
;
final
double
iconSize
;
final
double
iconSize
;
final
VoidCallback
?
onTap
;
final
VoidCallback
?
onTap
;
final
ColorTween
?
colorTween
;
final
ColorTween
?
labelColorTween
;
final
ColorTween
?
iconColorTween
;
final
double
?
flex
;
final
double
?
flex
;
final
bool
selected
;
final
bool
selected
;
final
IconThemeData
?
selectedIconTheme
;
final
IconThemeData
?
selectedIconTheme
;
...
@@ -523,7 +538,7 @@ class _BottomNavigationTile extends StatelessWidget {
...
@@ -523,7 +538,7 @@ class _BottomNavigationTile extends StatelessWidget {
child:
_Tile
(
child:
_Tile
(
layout:
layout
,
layout:
layout
,
icon:
_TileIcon
(
icon:
_TileIcon
(
colorTween:
c
olorTween
!,
colorTween:
iconC
olorTween
!,
animation:
animation
,
animation:
animation
,
iconSize:
iconSize
,
iconSize:
iconSize
,
selected:
selected
,
selected:
selected
,
...
@@ -532,7 +547,7 @@ class _BottomNavigationTile extends StatelessWidget {
...
@@ -532,7 +547,7 @@ class _BottomNavigationTile extends StatelessWidget {
unselectedIconTheme:
unselectedIconTheme
,
unselectedIconTheme:
unselectedIconTheme
,
),
),
label:
_Label
(
label:
_Label
(
colorTween:
c
olorTween
!,
colorTween:
labelC
olorTween
!,
animation:
animation
,
animation:
animation
,
item:
item
,
item:
item
,
selectedLabelStyle:
selectedLabelStyle
,
selectedLabelStyle:
selectedLabelStyle
,
...
@@ -910,6 +925,15 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
...
@@ -910,6 +925,15 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
return
textStyle
.
fontSize
==
null
?
textStyle
.
copyWith
(
fontSize:
fontSize
)
:
textStyle
;
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
)
{
List
<
Widget
>
_createTiles
(
BottomNavigationBarLandscapeLayout
layout
)
{
final
MaterialLocalizations
localizations
=
MaterialLocalizations
.
of
(
context
);
final
MaterialLocalizations
localizations
=
MaterialLocalizations
.
of
(
context
);
assert
(
localizations
!=
null
);
assert
(
localizations
!=
null
);
...
@@ -917,17 +941,6 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
...
@@ -917,17 +941,6 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
final
ThemeData
themeData
=
Theme
.
of
(
context
);
final
ThemeData
themeData
=
Theme
.
of
(
context
);
final
BottomNavigationBarThemeData
bottomTheme
=
BottomNavigationBarTheme
.
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
;
final
Color
themeColor
;
switch
(
themeData
.
brightness
)
{
switch
(
themeData
.
brightness
)
{
case
Brightness
.
light
:
case
Brightness
.
light
:
...
@@ -938,6 +951,39 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
...
@@ -938,6 +951,39 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
break
;
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
;
final
ColorTween
colorTween
;
switch
(
_effectiveType
)
{
switch
(
_effectiveType
)
{
case
BottomNavigationBarType
.
fixed
:
case
BottomNavigationBarType
.
fixed
:
...
@@ -963,6 +1009,64 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
...
@@ -963,6 +1009,64 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
break
;
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
>[];
final
List
<
Widget
>
tiles
=
<
Widget
>[];
for
(
int
i
=
0
;
i
<
widget
.
items
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
widget
.
items
.
length
;
i
++)
{
final
Set
<
MaterialState
>
states
=
<
MaterialState
>{
final
Set
<
MaterialState
>
states
=
<
MaterialState
>{
...
@@ -978,15 +1082,16 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
...
@@ -978,15 +1082,16 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
widget
.
items
[
i
],
widget
.
items
[
i
],
_animations
[
i
],
_animations
[
i
],
widget
.
iconSize
,
widget
.
iconSize
,
selectedIconTheme:
widget
.
selectedIconTheme
??
bottomTheme
.
s
electedIconTheme
,
selectedIconTheme:
widget
.
useLegacyColorScheme
?
widget
.
selectedIconTheme
??
bottomTheme
.
selectedIconTheme
:
effectiveS
electedIconTheme
,
unselectedIconTheme:
widget
.
u
nselectedIconTheme
??
bottomTheme
.
u
nselectedIconTheme
,
unselectedIconTheme:
widget
.
u
seLegacyColorScheme
?
widget
.
unselectedIconTheme
??
bottomTheme
.
unselectedIconTheme
:
effectiveU
nselectedIconTheme
,
selectedLabelStyle:
effectiveSelectedLabelStyle
,
selectedLabelStyle:
effectiveSelectedLabelStyle
,
unselectedLabelStyle:
effectiveUnselectedLabelStyle
,
unselectedLabelStyle:
effectiveUnselectedLabelStyle
,
enableFeedback:
widget
.
enableFeedback
??
bottomTheme
.
enableFeedback
??
true
,
enableFeedback:
widget
.
enableFeedback
??
bottomTheme
.
enableFeedback
??
true
,
onTap:
()
{
onTap:
()
{
widget
.
onTap
?.
call
(
i
);
widget
.
onTap
?.
call
(
i
);
},
},
colorTween:
colorTween
,
labelColorTween:
widget
.
useLegacyColorScheme
?
colorTween
:
labelColorTween
,
iconColorTween:
widget
.
useLegacyColorScheme
?
colorTween
:
iconColorTween
,
flex:
_evaluateFlex
(
_animations
[
i
]),
flex:
_evaluateFlex
(
_animations
[
i
]),
selected:
i
==
widget
.
currentIndex
,
selected:
i
==
widget
.
currentIndex
,
showSelectedLabels:
widget
.
showSelectedLabels
??
bottomTheme
.
showSelectedLabels
??
true
,
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