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
3ea4d063
Unverified
Commit
3ea4d063
authored
Feb 22, 2018
by
Hans Muller
Committed by
GitHub
Feb 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update TabBar indicator painter when tab controller changes (#14825)
parent
01b53bd0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
4 deletions
+72
-4
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+5
-4
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+67
-0
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
3ea4d063
...
@@ -752,14 +752,15 @@ class _TabBarState extends State<TabBar> {
...
@@ -752,14 +752,15 @@ class _TabBarState extends State<TabBar> {
@override
@override
void
didUpdateWidget
(
TabBar
oldWidget
)
{
void
didUpdateWidget
(
TabBar
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
super
.
didUpdateWidget
(
oldWidget
);
if
(
widget
.
controller
!=
oldWidget
.
controller
)
if
(
widget
.
controller
!=
oldWidget
.
controller
)
{
_updateTabController
();
_updateTabController
();
_initIndicatorPainter
();
if
(
widget
.
indicatorColor
!=
oldWidget
.
indicatorColor
||
}
else
if
(
widget
.
indicatorColor
!=
oldWidget
.
indicatorColor
||
widget
.
indicatorWeight
!=
oldWidget
.
indicatorWeight
||
widget
.
indicatorWeight
!=
oldWidget
.
indicatorWeight
||
widget
.
indicatorSize
!=
oldWidget
.
indicatorSize
||
widget
.
indicatorSize
!=
oldWidget
.
indicatorSize
||
widget
.
indicator
!=
oldWidget
.
indicator
)
widget
.
indicator
!=
oldWidget
.
indicator
)
{
_initIndicatorPainter
();
_initIndicatorPainter
();
}
if
(
widget
.
tabs
.
length
>
oldWidget
.
tabs
.
length
)
{
if
(
widget
.
tabs
.
length
>
oldWidget
.
tabs
.
length
)
{
final
int
delta
=
widget
.
tabs
.
length
-
oldWidget
.
tabs
.
length
;
final
int
delta
=
widget
.
tabs
.
length
-
oldWidget
.
tabs
.
length
;
...
...
packages/flutter/test/material/tabs_test.dart
View file @
3ea4d063
...
@@ -1650,4 +1650,71 @@ void main() {
...
@@ -1650,4 +1650,71 @@ void main() {
expect
(()
=>
new
Tab
(
icon:
new
Container
(),
text:
'foo'
,
child:
new
Container
()),
throwsAssertionError
);
expect
(()
=>
new
Tab
(
icon:
new
Container
(),
text:
'foo'
,
child:
new
Container
()),
throwsAssertionError
);
expect
(()
=>
new
Tab
(
text:
'foo'
,
child:
new
Container
()),
throwsAssertionError
);
expect
(()
=>
new
Tab
(
text:
'foo'
,
child:
new
Container
()),
throwsAssertionError
);
});
});
testWidgets
(
'TabController changes'
,
(
WidgetTester
tester
)
async
{
// This is a regression test for https://github.com/flutter/flutter/issues/14812
Widget
buildFrame
(
TabController
controller
)
{
return
boilerplate
(
child:
new
Container
(
alignment:
Alignment
.
topLeft
,
child:
new
TabBar
(
controller:
controller
,
tabs:
<
Tab
>[
const
Tab
(
text:
'LEFT'
),
const
Tab
(
text:
'RIGHT'
),
],
),
),
);
}
final
TabController
controller1
=
new
TabController
(
vsync:
const
TestVSync
(),
length:
2
,
initialIndex:
0
,
);
final
TabController
controller2
=
new
TabController
(
vsync:
const
TestVSync
(),
length:
2
,
initialIndex:
0
,
);
await
tester
.
pumpWidget
(
buildFrame
(
controller1
));
await
tester
.
pumpWidget
(
buildFrame
(
controller2
));
expect
(
controller1
.
index
,
0
);
expect
(
controller2
.
index
,
0
);
const
double
indicatorWeight
=
2.0
;
final
RenderBox
tabBarBox
=
tester
.
firstRenderObject
<
RenderBox
>(
find
.
byType
(
TabBar
));
expect
(
tabBarBox
.
size
.
height
,
48.0
);
// 48 = _kTabHeight(46) + indicatorWeight(2.0)
final
double
indicatorY
=
48.0
-
indicatorWeight
/
2.0
;
double
indicatorLeft
=
indicatorWeight
/
2.0
;
double
indicatorRight
=
400.0
-
indicatorWeight
/
2.0
;
// 400 = screen_width / 2
expect
(
tabBarBox
,
paints
..
line
(
strokeWidth:
indicatorWeight
,
p1:
new
Offset
(
indicatorLeft
,
indicatorY
),
p2:
new
Offset
(
indicatorRight
,
indicatorY
),
));
await
tester
.
tap
(
find
.
text
(
'RIGHT'
));
await
tester
.
pumpAndSettle
();
expect
(
controller1
.
index
,
0
);
expect
(
controller2
.
index
,
1
);
// Verify that the TabBar's _IndicatorPainter is now listening to
// tabController2.
indicatorLeft
=
400.0
+
indicatorWeight
/
2.0
;
indicatorRight
=
800.0
-
indicatorWeight
/
2.0
;
expect
(
tabBarBox
,
paints
..
line
(
strokeWidth:
indicatorWeight
,
p1:
new
Offset
(
indicatorLeft
,
indicatorY
),
p2:
new
Offset
(
indicatorRight
,
indicatorY
),
));
});
}
}
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