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
71a5c619
Unverified
Commit
71a5c619
authored
Jun 05, 2020
by
Michel Feinstein
Committed by
GitHub
Jun 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds physics to the TabBar (#57416) (#57644)
parent
94b7ff24
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+10
-0
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+33
-0
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
71a5c619
...
...
@@ -613,6 +613,7 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
mouseCursor
,
this
.
onTap
,
this
.
physics
,
})
:
assert
(
tabs
!=
null
),
assert
(
isScrollable
!=
null
),
assert
(
dragStartBehavior
!=
null
),
...
...
@@ -752,6 +753,14 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
/// interfere with the default tap handler.
final
ValueChanged
<
int
>
onTap
;
/// How the [TabBar]'s scroll view should respond to user input.
///
/// For example, determines how the scroll view continues to animate after the
/// user stops dragging the scroll view.
///
/// Defaults to matching platform conventions.
final
ScrollPhysics
physics
;
/// A size whose height depends on if the tabs have both icons and text.
///
/// [AppBar] uses this size to compute its own preferred size.
...
...
@@ -1115,6 +1124,7 @@ class _TabBarState extends State<TabBar> {
dragStartBehavior:
widget
.
dragStartBehavior
,
scrollDirection:
Axis
.
horizontal
,
controller:
_scrollController
,
physics:
widget
.
physics
,
child:
tabBar
,
);
}
...
...
packages/flutter/test/material/tabs_test.dart
View file @
71a5c619
...
...
@@ -215,6 +215,11 @@ class TestScrollPhysics extends ScrollPhysics {
return
TestScrollPhysics
(
parent:
buildParent
(
ancestor
));
}
@override
double
applyPhysicsToUserOffset
(
ScrollMetrics
position
,
double
offset
)
{
return
offset
==
10
?
20
:
offset
;
}
static
final
SpringDescription
_kDefaultSpring
=
SpringDescription
.
withDampingRatio
(
mass:
0.5
,
stiffness:
500.0
,
...
...
@@ -1108,6 +1113,34 @@ void main() {
expect
(
tabController
.
index
,
0
);
});
testWidgets
(
'TabBar accepts custom physics'
,
(
WidgetTester
tester
)
async
{
final
List
<
Tab
>
tabs
=
List
<
Tab
>.
generate
(
20
,
(
int
index
)
{
return
Tab
(
text:
'TAB #
$index
'
);
});
final
TabController
controller
=
TabController
(
vsync:
const
TestVSync
(),
length:
tabs
.
length
,
initialIndex:
tabs
.
length
-
1
,
);
await
tester
.
pumpWidget
(
boilerplate
(
child:
TabBar
(
isScrollable:
true
,
controller:
controller
,
tabs:
tabs
,
physics:
const
TestScrollPhysics
(),
),
),
);
final
TabBar
tabBar
=
tester
.
widget
(
find
.
byType
(
TabBar
));
final
double
position
=
tabBar
.
physics
.
applyPhysicsToUserOffset
(
null
,
10
);
expect
(
position
,
equals
(
20
));
});
testWidgets
(
'Scrollable TabBar with a non-zero TabController initialIndex'
,
(
WidgetTester
tester
)
async
{
// This is a regression test for https://github.com/flutter/flutter/issues/9374
...
...
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