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
898c19d7
Commit
898c19d7
authored
Jul 17, 2017
by
najeira
Committed by
Ian Hickson
Jul 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add physics to TabBarView (#11150)
parent
744921fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
1 deletion
+79
-1
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+13
-1
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+66
-0
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
898c19d7
...
...
@@ -795,6 +795,7 @@ class TabBarView extends StatefulWidget {
Key
key
,
@required
this
.
children
,
this
.
controller
,
this
.
physics
,
})
:
assert
(
children
!=
null
),
super
(
key:
key
);
/// This widget's selection and animation state.
...
...
@@ -806,6 +807,17 @@ class TabBarView extends StatefulWidget {
/// One widget per tab.
final
List
<
Widget
>
children
;
/// How the page view should respond to user input.
///
/// For example, determines how the page view continues to animate after the
/// user stops dragging the page view.
///
/// The physics are modified to snap to page boundaries using
/// [PageScrollPhysics] prior to being used.
///
/// Defaults to matching platform conventions.
final
ScrollPhysics
physics
;
@override
_TabBarViewState
createState
()
=>
new
_TabBarViewState
();
}
...
...
@@ -954,7 +966,7 @@ class _TabBarViewState extends State<TabBarView> {
onNotification:
_handleScrollNotification
,
child:
new
PageView
(
controller:
_pageController
,
physics:
_kTabBarViewPhysics
,
physics:
widget
.
physics
==
null
?
_kTabBarViewPhysics
:
_kTabBarViewPhysics
.
applyTo
(
widget
.
physics
)
,
children:
_children
,
),
);
...
...
packages/flutter/test/material/tabs_test.dart
View file @
898c19d7
...
...
@@ -7,6 +7,7 @@ import 'dart:ui' show SemanticsFlags, SemanticsAction;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/physics.dart'
;
import
'../rendering/mock_canvas.dart'
;
import
'../rendering/recording_canvas.dart'
;
...
...
@@ -128,6 +129,24 @@ class TabIndicatorRecordingCanvas extends TestRecordingCanvas {
}
}
class
TestScrollPhysics
extends
ScrollPhysics
{
const
TestScrollPhysics
({
ScrollPhysics
parent
})
:
super
(
parent:
parent
);
@override
TestScrollPhysics
applyTo
(
ScrollPhysics
ancestor
)
{
return
new
TestScrollPhysics
(
parent:
buildParent
(
ancestor
));
}
static
final
SpringDescription
_kDefaultSpring
=
new
SpringDescription
.
withDampingRatio
(
mass:
0.5
,
springConstant:
500.0
,
ratio:
1.1
,
);
@override
SpringDescription
get
spring
=>
_kDefaultSpring
;
}
void
main
(
)
{
testWidgets
(
'TabBar tap selects tab'
,
(
WidgetTester
tester
)
async
{
final
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
,
'C'
];
...
...
@@ -812,6 +831,53 @@ void main() {
expect
(
tabController
.
index
,
2
);
});
testWidgets
(
'TabBarView scrolls end very close to a new page with custom physics'
,
(
WidgetTester
tester
)
async
{
final
TabController
tabController
=
new
TabController
(
vsync:
const
TestVSync
(),
initialIndex:
1
,
length:
3
,
);
await
tester
.
pumpWidget
(
new
SizedBox
.
expand
(
child:
new
Center
(
child:
new
SizedBox
(
width:
400.0
,
height:
400.0
,
child:
new
TabBarView
(
controller:
tabController
,
physics:
const
TestScrollPhysics
(),
children:
<
Widget
>[
const
Center
(
child:
const
Text
(
'0'
)),
const
Center
(
child:
const
Text
(
'1'
)),
const
Center
(
child:
const
Text
(
'2'
)),
],
),
),
),
),
);
expect
(
tabController
.
index
,
1
);
final
PageView
pageView
=
tester
.
widget
(
find
.
byType
(
PageView
));
final
PageController
pageController
=
pageView
.
controller
;
final
ScrollPosition
position
=
pageController
.
position
;
// The TabBarView's page width is 400, so page 0 is at scroll offset 0.0,
// page 1 is at 400.0, page 2 is at 800.0.
expect
(
position
.
pixels
,
400.0
);
// Not close enough to switch to page 2
pageController
.
jumpTo
(
800.0
-
1.25
*
position
.
physics
.
tolerance
.
distance
);
expect
(
tabController
.
index
,
1
);
// Close enough to switch to page 2
pageController
.
jumpTo
(
800.0
-
0.75
*
position
.
physics
.
tolerance
.
distance
);
expect
(
tabController
.
index
,
2
);
});
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