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
c90b1182
Commit
c90b1182
authored
Jan 10, 2020
by
Maya
Committed by
Flutter GitHub Bot
Jan 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add padEnds option to SliverFillViewport (#48207)
parent
5280dda1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
3 deletions
+65
-3
sliver_fill.dart
packages/flutter/lib/src/widgets/sliver_fill.dart
+18
-3
sliver_fill_viewport_test.dart
packages/flutter/test/widgets/sliver_fill_viewport_test.dart
+47
-0
No files found.
packages/flutter/lib/src/widgets/sliver_fill.dart
View file @
c90b1182
...
...
@@ -30,9 +30,11 @@ class SliverFillViewport extends StatelessWidget {
Key
key
,
@required
this
.
delegate
,
this
.
viewportFraction
=
1.0
,
this
.
padEnds
=
true
,
})
:
assert
(
viewportFraction
!=
null
),
assert
(
viewportFraction
>
0.0
),
super
(
key:
key
);
assert
(
viewportFraction
>
0.0
),
assert
(
padEnds
!=
null
),
super
(
key:
key
);
/// The fraction of the viewport that each child should fill in the main axis.
///
...
...
@@ -41,13 +43,26 @@ class SliverFillViewport extends StatelessWidget {
/// the viewport in the main axis.
final
double
viewportFraction
;
/// Whether to add padding to both ends of the list.
///
/// If this is set to true and [viewportFraction] < 1.0, padding will be added
/// such that the first and last child slivers will be in the center of
/// the viewport when scrolled all the way to the start or end, respectively.
/// You may want to set this to false if this [SliverFillViewport] is not the only
/// widget along this main axis, such as in a [CustomScrollView] with multiple
/// children.
///
/// This option cannot be [null]. If [viewportFraction] >= 1.0, this option has no
/// effect. Defaults to [true].
final
bool
padEnds
;
/// {@macro flutter.widgets.sliverMultiBoxAdaptor.delegate}
final
SliverChildDelegate
delegate
;
@override
Widget
build
(
BuildContext
context
)
{
return
_SliverFractionalPadding
(
viewportFraction:
(
1
-
viewportFraction
).
clamp
(
0
,
1
)
/
2
,
viewportFraction:
padEnds
?
(
1
-
viewportFraction
).
clamp
(
0
,
1
)
/
2
:
0
,
sliver:
_SliverFillViewportRenderObjectWidget
(
viewportFraction:
viewportFraction
,
delegate:
delegate
,
...
...
packages/flutter/test/widgets/sliver_fill_viewport_test.dart
View file @
c90b1182
...
...
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -145,4 +146,50 @@ void main() {
),
);
});
testWidgets
(
'SliverFillViewport padding test'
,
(
WidgetTester
tester
)
async
{
final
SliverChildListDelegate
delegate
=
SliverChildListDelegate
(
<
Widget
>[
Container
(
child:
const
Text
(
'0'
)),
],
addAutomaticKeepAlives:
false
,
addSemanticIndexes:
false
,
);
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
CustomScrollView
(
slivers:
<
Widget
>[
SliverFillViewport
(
padEnds:
true
,
viewportFraction:
0.5
,
delegate:
delegate
,
),
],
),
),
);
final
RenderSliver
boxWithPadding
=
tester
.
renderObject
<
RenderSliver
>(
find
.
byType
(
SliverFillViewport
));
expect
(
boxWithPadding
.
geometry
.
paintExtent
,
equals
(
600.0
));
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
CustomScrollView
(
slivers:
<
Widget
>[
SliverFillViewport
(
padEnds:
false
,
viewportFraction:
0.5
,
delegate:
delegate
,
),
],
),
),
);
final
RenderSliver
boxWithoutPadding
=
tester
.
renderObject
<
RenderSliver
>(
find
.
byType
(
SliverFillViewport
));
expect
(
boxWithoutPadding
.
geometry
.
paintExtent
,
equals
(
300.0
));
});
}
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