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
dc4fe525
Commit
dc4fe525
authored
Mar 03, 2016
by
Hans Muller
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2350 from HansMuller/tab_scroll
Restore scrolled tabs support
parents
74ffda0f
4eae547c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
3 deletions
+49
-3
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+3
-2
tabs_test.dart
packages/flutter/test/widget/tabs_test.dart
+46
-1
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
dc4fe525
...
@@ -704,7 +704,8 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
...
@@ -704,7 +704,8 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
void
_updateScrollBehavior
()
{
void
_updateScrollBehavior
()
{
scrollTo
(
scrollBehavior
.
updateExtents
(
scrollTo
(
scrollBehavior
.
updateExtents
(
containerExtent:
config
.
scrollDirection
==
Axis
.
vertical
?
_viewportSize
.
height
:
_viewportSize
.
width
,
containerExtent:
config
.
scrollDirection
==
Axis
.
vertical
?
_viewportSize
.
height
:
_viewportSize
.
width
,
contentExtent:
_tabWidths
.
reduce
((
double
sum
,
double
width
)
=>
sum
+
width
)
contentExtent:
_tabWidths
.
reduce
((
double
sum
,
double
width
)
=>
sum
+
width
),
scrollOffset:
scrollOffset
));
));
}
}
...
@@ -780,7 +781,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
...
@@ -780,7 +781,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
);
);
if
(
config
.
isScrollable
)
{
if
(
config
.
isScrollable
)
{
child:
new
Viewport
(
return
new
Viewport
(
scrollDirection:
Axis
.
horizontal
,
scrollDirection:
Axis
.
horizontal
,
paintOffset:
scrollOffsetToPixelDelta
(
scrollOffset
),
paintOffset:
scrollOffsetToPixelDelta
(
scrollOffset
),
onPaintOffsetUpdateNeeded:
_handlePaintOffsetUpdateNeeded
,
onPaintOffsetUpdateNeeded:
_handlePaintOffsetUpdateNeeded
,
...
...
packages/flutter/test/widget/tabs_test.dart
View file @
dc4fe525
...
@@ -7,12 +7,13 @@ import 'package:flutter/material.dart';
...
@@ -7,12 +7,13 @@ import 'package:flutter/material.dart';
import
'package:flutter/widgets.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
Widget
buildFrame
(
{
List
<
String
>
tabs
,
String
value
,
bool
isScrollable:
false
})
{
Widget
buildFrame
(
{
List
<
String
>
tabs
,
String
value
,
bool
isScrollable:
false
,
Key
tabBarKey
})
{
return
new
Material
(
return
new
Material
(
child:
new
TabBarSelection
<
String
>(
child:
new
TabBarSelection
<
String
>(
value:
value
,
value:
value
,
values:
tabs
,
values:
tabs
,
child:
new
TabBar
<
String
>(
child:
new
TabBar
<
String
>(
key:
tabBarKey
,
labels:
new
Map
<
String
,
TabLabel
>.
fromIterable
(
tabs
,
value:
(
String
tab
)
=>
new
TabLabel
(
text:
tab
)),
labels:
new
Map
<
String
,
TabLabel
>.
fromIterable
(
tabs
,
value:
(
String
tab
)
=>
new
TabLabel
(
text:
tab
)),
isScrollable:
isScrollable
isScrollable:
isScrollable
)
)
...
@@ -98,4 +99,48 @@ void main() {
...
@@ -98,4 +99,48 @@ void main() {
expect
(
selection
.
value
,
equals
(
'A'
));
expect
(
selection
.
value
,
equals
(
'A'
));
});
});
});
});
test
(
'Scrollable TabBar tap centers selected tab'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
List
<
String
>
tabs
=
<
String
>[
'AAAAAA'
,
'BBBBBB'
,
'CCCCCC'
,
'DDDDDD'
,
'EEEEEE'
,
'FFFFFF'
,
'GGGGGG'
,
'HHHHHH'
,
'IIIIII'
,
'JJJJJJ'
,
'KKKKKK'
,
'LLLLLL'
];
Key
tabBarKey
=
new
Key
(
'TabBar'
);
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'AAAAAA'
,
isScrollable:
true
,
tabBarKey:
tabBarKey
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
findText
(
'AAAAAA'
));
expect
(
selection
,
isNotNull
);
expect
(
selection
.
value
,
equals
(
'AAAAAA'
));
expect
(
tester
.
getSize
(
tester
.
findElementByKey
(
tabBarKey
)).
width
,
equals
(
800.0
));
// The center of the FFFFFF item is to the right of the TabBar's center
expect
(
tester
.
getCenter
(
tester
.
findText
(
'FFFFFF'
)).
x
,
greaterThan
(
401.0
));
tester
.
tap
(
tester
.
findText
(
'FFFFFF'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the scroll animation
expect
(
selection
.
value
,
equals
(
'FFFFFF'
));
// The center of the FFFFFF item is now at the TabBar's center
expect
(
tester
.
getCenter
(
tester
.
findText
(
'FFFFFF'
)).
x
,
closeTo
(
400.0
,
1.0
));
});
});
test
(
'TabBar can be scrolled independent of the selection'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
List
<
String
>
tabs
=
<
String
>[
'AAAAAA'
,
'BBBBBB'
,
'CCCCCC'
,
'DDDDDD'
,
'EEEEEE'
,
'FFFFFF'
,
'GGGGGG'
,
'HHHHHH'
,
'IIIIII'
,
'JJJJJJ'
,
'KKKKKK'
,
'LLLLLL'
];
Key
tabBarKey
=
new
Key
(
'TabBar'
);
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'AAAAAA'
,
isScrollable:
true
,
tabBarKey:
tabBarKey
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
findText
(
'AAAAAA'
));
expect
(
selection
,
isNotNull
);
expect
(
selection
.
value
,
equals
(
'AAAAAA'
));
// Fling-scroll the TabBar to the left
expect
(
tester
.
getCenter
(
tester
.
findText
(
'HHHHHH'
)).
x
,
lessThan
(
700.0
));
tester
.
fling
(
tester
.
findElementByKey
(
tabBarKey
),
const
Offset
(-
20.0
,
0.0
),
1000.0
);
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the scroll animation
expect
(
tester
.
getCenter
(
tester
.
findText
(
'HHHHHH'
)).
x
,
lessThan
(
500.0
));
// Scrolling the TabBar doesn't change the selection
expect
(
selection
.
value
,
equals
(
'AAAAAA'
));
});
});
}
}
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