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
566cacbd
Commit
566cacbd
authored
Jul 29, 2016
by
Hans Muller
Committed by
GitHub
Jul 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't leave tabs hanging in the middle (#5153)
parent
c674b4a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
3 deletions
+86
-3
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+4
-2
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+82
-1
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
566cacbd
...
...
@@ -1217,8 +1217,10 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
if
(
scrollVelocity
.
abs
()
>
_kMinFlingVelocity
)
{
final
int
selectionDelta
=
scrollVelocity
.
sign
.
truncate
();
final
int
targetIndex
=
(
_selection
.
index
+
selectionDelta
).
clamp
(
0
,
_tabCount
-
1
);
_selection
.
value
=
_selection
.
values
[
targetIndex
];
return
new
Future
<
Null
>.
value
();
if
(
_selection
.
index
!=
targetIndex
)
{
_selection
.
value
=
_selection
.
values
[
targetIndex
];
return
new
Future
<
Null
>.
value
();
}
}
final
int
selectionIndex
=
_selection
.
index
;
...
...
packages/flutter/test/material/tabs_test.dart
View file @
566cacbd
...
...
@@ -31,7 +31,6 @@ Widget buildFrame({ List<String> tabs, String value, bool isScrollable: false, K
child:
new
TabBarSelection
<
String
>(
value:
value
,
values:
tabs
,
onChanged:
null
,
child:
new
TabBar
<
String
>(
key:
tabBarKey
,
labels:
new
Map
<
String
,
TabLabel
>.
fromIterable
(
tabs
,
value:
(
String
tab
)
=>
new
TabLabel
(
text:
tab
)),
...
...
@@ -41,6 +40,31 @@ Widget buildFrame({ List<String> tabs, String value, bool isScrollable: false, K
);
}
Widget
buildLeftRightApp
(
{
List
<
String
>
tabs
,
String
value
})
{
return
new
MaterialApp
(
theme:
new
ThemeData
(
platform:
TargetPlatform
.
android
),
home:
new
TabBarSelection
<
String
>(
value:
value
,
values:
tabs
,
child:
new
Scaffold
(
appBar:
new
AppBar
(
title:
new
Text
(
'tabs'
),
bottom:
new
TabBar
<
String
>(
labels:
new
Map
<
String
,
TabLabel
>.
fromIterable
(
tabs
,
value:
(
String
tab
)
=>
new
TabLabel
(
text:
tab
)),
)
),
body:
new
TabBarView
<
String
>(
children:
<
Widget
>[
new
Center
(
child:
new
Text
(
'LEFT CHILD'
)),
new
Center
(
child:
new
Text
(
'RIGHT CHILD'
))
]
)
)
)
);
}
void
main
(
)
{
testWidgets
(
'TabBar tap selects tab'
,
(
WidgetTester
tester
)
async
{
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
,
'C'
];
...
...
@@ -228,4 +252,61 @@ void main() {
await
tester
.
pumpWidget
(
builder
());
expect
(
findStateMarkerState
(
tabs
[
1
]).
marker
,
equals
(
'marked'
));
});
testWidgets
(
'TabBar left/right fling'
,
(
WidgetTester
tester
)
async
{
List
<
String
>
tabs
=
<
String
>[
'LEFT'
,
'RIGHT'
];
await
tester
.
pumpWidget
(
buildLeftRightApp
(
tabs:
tabs
,
value:
'LEFT'
));
expect
(
find
.
text
(
'LEFT'
),
findsOneWidget
);
expect
(
find
.
text
(
'RIGHT'
),
findsOneWidget
);
expect
(
find
.
text
(
'LEFT CHILD'
),
findsOneWidget
);
expect
(
find
.
text
(
'RIGHT CHILD'
),
findsNothing
);
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
element
(
find
.
text
(
'LEFT'
)));
expect
(
selection
.
value
,
equals
(
'LEFT'
));
// Fling to the left, switch from the 'LEFT' tab to the 'RIGHT'
Point
flingStart
=
tester
.
getCenter
(
find
.
text
(
'LEFT CHILD'
));
await
tester
.
flingFrom
(
flingStart
,
new
Offset
(-
200.0
,
0.0
),
1000.0
);
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the scroll animation
expect
(
selection
.
value
,
equals
(
'RIGHT'
));
expect
(
find
.
text
(
'LEFT CHILD'
),
findsNothing
);
expect
(
find
.
text
(
'RIGHT CHILD'
),
findsOneWidget
);
// Fling to the right, switch back to the 'LEFT' tab
flingStart
=
tester
.
getCenter
(
find
.
text
(
'RIGHT CHILD'
));
await
tester
.
flingFrom
(
flingStart
,
new
Offset
(
200.0
,
0.0
),
1000.0
);
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the scroll animation
expect
(
selection
.
value
,
equals
(
'LEFT'
));
expect
(
find
.
text
(
'LEFT CHILD'
),
findsOneWidget
);
expect
(
find
.
text
(
'RIGHT CHILD'
),
findsNothing
);
});
// A regression test for https://github.com/flutter/flutter/issues/5095
testWidgets
(
'TabBar left/right fling reverse'
,
(
WidgetTester
tester
)
async
{
List
<
String
>
tabs
=
<
String
>[
'LEFT'
,
'RIGHT'
];
await
tester
.
pumpWidget
(
buildLeftRightApp
(
tabs:
tabs
,
value:
'LEFT'
));
expect
(
find
.
text
(
'LEFT'
),
findsOneWidget
);
expect
(
find
.
text
(
'RIGHT'
),
findsOneWidget
);
expect
(
find
.
text
(
'LEFT CHILD'
),
findsOneWidget
);
expect
(
find
.
text
(
'RIGHT CHILD'
),
findsNothing
);
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
element
(
find
.
text
(
'LEFT'
)));
expect
(
selection
.
value
,
equals
(
'LEFT'
));
// End the fling by reversing direction. This should cause not cause
// a change to the selected tab, everything should just settle back to
// to where it started.
Point
flingStart
=
tester
.
getCenter
(
find
.
text
(
'LEFT CHILD'
));
await
tester
.
flingFrom
(
flingStart
,
new
Offset
(-
200.0
,
0.0
),
-
1000.0
);
await
tester
.
pump
();
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the scroll animation
expect
(
selection
.
value
,
equals
(
'LEFT'
));
expect
(
find
.
text
(
'LEFT CHILD'
),
findsOneWidget
);
expect
(
find
.
text
(
'RIGHT CHILD'
),
findsNothing
);
});
}
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