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
872e6048
Unverified
Commit
872e6048
authored
Mar 01, 2022
by
Hari07
Committed by
GitHub
Mar 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added viewport fraction parameter to tabView (#98512)
parent
078deb92
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
1 deletion
+97
-1
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+8
-1
page_view.dart
packages/flutter/lib/src/widgets/page_view.dart
+2
-0
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+87
-0
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
872e6048
...
...
@@ -1328,6 +1328,7 @@ class TabBarView extends StatefulWidget {
this
.
controller
,
this
.
physics
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
viewportFraction
=
1.0
,
})
:
assert
(
children
!=
null
),
assert
(
dragStartBehavior
!=
null
),
super
(
key:
key
);
...
...
@@ -1358,6 +1359,9 @@ class TabBarView extends StatefulWidget {
/// {@macro flutter.widgets.scrollable.dragStartBehavior}
final
DragStartBehavior
dragStartBehavior
;
/// {@macro flutter.widgets.pageview.viewportFraction}
final
double
viewportFraction
;
@override
State
<
TabBarView
>
createState
()
=>
_TabBarViewState
();
}
...
...
@@ -1411,7 +1415,10 @@ class _TabBarViewState extends State<TabBarView> {
super
.
didChangeDependencies
();
_updateTabController
();
_currentIndex
=
_controller
!.
index
;
_pageController
=
PageController
(
initialPage:
_currentIndex
!);
_pageController
=
PageController
(
initialPage:
_currentIndex
!,
viewportFraction:
widget
.
viewportFraction
,
);
}
@override
...
...
packages/flutter/lib/src/widgets/page_view.dart
View file @
872e6048
...
...
@@ -144,10 +144,12 @@ class PageController extends ScrollController {
/// locations used to save scroll offsets.
final
bool
keepPage
;
/// {@template flutter.widgets.pageview.viewportFraction}
/// The fraction of the viewport that each page should occupy.
///
/// Defaults to 1.0, which means each page fills the viewport in the scrolling
/// direction.
/// {@endtemplate}
final
double
viewportFraction
;
/// The current page displayed in the controlled [PageView].
...
...
packages/flutter/test/material/tabs_test.dart
View file @
872e6048
...
...
@@ -1017,6 +1017,93 @@ void main() {
expect
(
position
.
pixels
,
800
);
});
testWidgets
(
'TabBarView viewportFraction sets PageView viewport fraction'
,
(
WidgetTester
tester
)
async
{
const
Duration
animationDuration
=
Duration
(
milliseconds:
100
);
final
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
,
'C'
];
final
TabController
tabController
=
TabController
(
vsync:
const
TestVSync
(),
initialIndex:
1
,
length:
tabs
.
length
,
animationDuration:
animationDuration
,
);
await
tester
.
pumpWidget
(
boilerplate
(
child:
Column
(
children:
<
Widget
>[
TabBar
(
tabs:
tabs
.
map
<
Widget
>((
String
tab
)
=>
Tab
(
text:
tab
)).
toList
(),
controller:
tabController
,
),
SizedBox
(
width:
400.0
,
height:
400.0
,
child:
TabBarView
(
viewportFraction:
0.8
,
controller:
tabController
,
children:
const
<
Widget
>[
Center
(
child:
Text
(
'0'
)),
Center
(
child:
Text
(
'1'
)),
Center
(
child:
Text
(
'2'
)),
],
),
),
],
),
));
expect
(
tabController
.
index
,
1
);
final
PageView
pageView
=
tester
.
widget
(
find
.
byType
(
PageView
));
final
PageController
pageController
=
pageView
.
controller
;
// The TabView was initialized with viewportFraction as 0.8
// So it's expected the PageView inside would obtain the same viewportFraction
expect
(
pageController
.
viewportFraction
,
0.8
);
});
testWidgets
(
'TabBarView viewportFraction is 1 by default'
,
(
WidgetTester
tester
)
async
{
const
Duration
animationDuration
=
Duration
(
milliseconds:
100
);
final
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
,
'C'
];
final
TabController
tabController
=
TabController
(
vsync:
const
TestVSync
(),
initialIndex:
1
,
length:
tabs
.
length
,
animationDuration:
animationDuration
,
);
await
tester
.
pumpWidget
(
boilerplate
(
child:
Column
(
children:
<
Widget
>[
TabBar
(
tabs:
tabs
.
map
<
Widget
>((
String
tab
)
=>
Tab
(
text:
tab
)).
toList
(),
controller:
tabController
,
),
SizedBox
(
width:
400.0
,
height:
400.0
,
child:
TabBarView
(
controller:
tabController
,
children:
const
<
Widget
>[
Center
(
child:
Text
(
'0'
)),
Center
(
child:
Text
(
'1'
)),
Center
(
child:
Text
(
'2'
)),
],
),
),
],
),
));
expect
(
tabController
.
index
,
1
);
final
PageView
pageView
=
tester
.
widget
(
find
.
byType
(
PageView
));
final
PageController
pageController
=
pageView
.
controller
;
// The TabView was initialized with default viewportFraction
// So it's expected the PageView inside would obtain the value 1
expect
(
pageController
.
viewportFraction
,
1
);
});
testWidgets
(
'TabBar tap skips indicator animation when disabled in controller'
,
(
WidgetTester
tester
)
async
{
final
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
];
...
...
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