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
9b564e9a
Unverified
Commit
9b564e9a
authored
Nov 04, 2020
by
xubaolin
Committed by
GitHub
Nov 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make TabBar indicator color automatic adjustment optional (#68171)
parent
5034d575
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+13
-1
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+11
-1
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
9b564e9a
...
...
@@ -597,6 +597,7 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
this
.
controller
,
this
.
isScrollable
=
false
,
this
.
indicatorColor
,
this
.
automaticIndicatorColorAdjustment
=
true
,
this
.
indicatorWeight
=
2.0
,
this
.
indicatorPadding
=
EdgeInsets
.
zero
,
this
.
indicator
,
...
...
@@ -685,6 +686,13 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
/// the tab widget itself.
final
Decoration
?
indicator
;
/// Whether this tab bar should automatically adjust the [indicatorColor].
///
/// If [automaticIndicatorColorAdjustment] is true,
/// then the [indicatorColor] will be automatically adjusted to [Colors.white]
/// when the [indicatorColor] is same as [Material.color] of the [Material] parent widget.
final
bool
automaticIndicatorColorAdjustment
;
/// Defines how the selected tab indicator's size is computed.
///
/// The size of the selected tab indicator is defined relative to the
...
...
@@ -814,7 +822,11 @@ class _TabBarState extends State<TabBar> {
//
// The material's color might be null (if it's a transparency). In that case
// there's no good way for us to find out what the color is so we don't.
if
(
color
.
value
==
Material
.
of
(
context
)?.
color
?.
value
)
//
// TODO(xu-baolin): Remove automatic adjustment to white color indicator
// with a better long-term solution.
// https://github.com/flutter/flutter/pull/68171#pullrequestreview-517753917
if
(
widget
.
automaticIndicatorColorAdjustment
&&
color
.
value
==
Material
.
of
(
context
)?.
color
?.
value
)
color
=
Colors
.
white
;
return
UnderlineTabIndicator
(
...
...
packages/flutter/test/material/tabs_test.dart
View file @
9b564e9a
...
...
@@ -169,7 +169,7 @@ class TabControllerFrameState extends State<TabControllerFrame> with SingleTicke
}
}
Widget
buildLeftRightApp
(
{
required
List
<
String
>
tabs
,
required
String
value
})
{
Widget
buildLeftRightApp
(
{
required
List
<
String
>
tabs
,
required
String
value
,
bool
automaticIndicatorColorAdjustment
=
true
})
{
return
MaterialApp
(
theme:
ThemeData
(
platform:
TargetPlatform
.
android
),
home:
DefaultTabController
(
...
...
@@ -180,6 +180,7 @@ Widget buildLeftRightApp({ required List<String> tabs, required String value })
title:
const
Text
(
'tabs'
),
bottom:
TabBar
(
tabs:
tabs
.
map
<
Widget
>((
String
tab
)
=>
Tab
(
text:
tab
)).
toList
(),
automaticIndicatorColorAdjustment:
automaticIndicatorColorAdjustment
,
),
),
body:
const
TabBarView
(
...
...
@@ -2213,7 +2214,16 @@ void main() {
expect
(
tabBarBox
,
paints
..
line
(
color:
Colors
.
white
,
));
});
testWidgets
(
'Tab indicator color should not be adjusted when disable [automaticIndicatorColorAdjustment]'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/68077
final
List
<
String
>
tabs
=
<
String
>[
'LEFT'
,
'RIGHT'
];
await
tester
.
pumpWidget
(
buildLeftRightApp
(
tabs:
tabs
,
value:
'LEFT'
,
automaticIndicatorColorAdjustment:
false
));
final
RenderBox
tabBarBox
=
tester
.
firstRenderObject
<
RenderBox
>(
find
.
byType
(
TabBar
));
expect
(
tabBarBox
,
paints
..
line
(
color:
const
Color
(
0xff2196f3
),
));
});
testWidgets
(
'Skipping tabs with global key does not crash'
,
(
WidgetTester
tester
)
async
{
...
...
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