@@ -12,73 +12,27 @@ import 'debug.dart';
12
12
import 'object.dart' ;
13
13
import 'sliver.dart' ;
14
14
15
- /// Inset a [RenderSliver] , applying padding on each side.
15
+ /// Insets a [RenderSliver] by applying [resolvedPadding] on each side.
16
16
///
17
- /// A [RenderSliverPadding] object wraps the [SliverGeometry.layoutExtent] of
18
- /// its child. Any incoming [SliverConstraints.overlap] is ignored and not
17
+ /// A [RenderSliverEdgeInsetsPadding] subclass wraps the [SliverGeometry.layoutExtent]
18
+ /// of its child. Any incoming [SliverConstraints.overlap] is ignored and not
19
19
/// passed on to the child.
20
20
///
21
+ /// {@template flutter.rendering.sliverPadding.limitation}
21
22
/// Applying padding to anything but the most mundane sliver is likely to have
22
- /// undesired effects. For example, wrapping a
23
- /// [RenderSliverPinnedPersistentHeader] will cause the app bar to overlap
24
- /// earlier slivers (contrary to the normal behavior of pinned app bars), and
25
- /// while the app bar is pinned, the padding will scroll away.
26
- class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin <RenderSliver > {
27
- /// Creates a render object that insets its child in a viewport.
28
- ///
29
- /// The [padding] argument must not be null and must have non-negative insets.
30
- RenderSliverPadding ({
31
- @required EdgeInsetsGeometry padding,
32
- TextDirection textDirection,
33
- RenderSliver child,
34
- }) : assert (padding != null ),
35
- assert (padding.isNonNegative),
36
- _padding = padding,
37
- _textDirection = textDirection {
38
- this .child = child;
39
- }
40
-
41
- EdgeInsets _resolvedPadding;
42
-
43
- void _resolve () {
44
- if (_resolvedPadding != null )
45
- return ;
46
- _resolvedPadding = padding.resolve (textDirection);
47
- assert (_resolvedPadding.isNonNegative);
48
- }
49
-
50
- void _markNeedResolution () {
51
- _resolvedPadding = null ;
52
- markNeedsLayout ();
53
- }
54
-
23
+ /// undesired effects. For example, wrapping a [RenderSliverPinnedPersistentHeader]
24
+ /// will cause the app bar to overlap earlier slivers (contrary to the normal
25
+ /// behavior of pinned app bars), and while the app bar is pinned, the padding
26
+ /// will scroll away.
27
+ /// {@endtemplate}
28
+ abstract class RenderSliverEdgeInsetsPadding extends RenderSliver with RenderObjectWithChildMixin <RenderSliver > {
55
29
/// The amount to pad the child in each dimension.
56
30
///
57
- /// If this is set to an [EdgeInsetsDirectional] object, then [textDirection]
58
- /// must not be null.
59
- EdgeInsetsGeometry get padding => _padding;
60
- EdgeInsetsGeometry _padding;
61
- set padding (EdgeInsetsGeometry value) {
62
- assert (value != null );
63
- assert (padding.isNonNegative);
64
- if (_padding == value)
65
- return ;
66
- _padding = value;
67
- _markNeedResolution ();
68
- }
69
-
70
- /// The text direction with which to resolve [padding] .
31
+ /// The offsets are specified in terms of visual edges, left, top, right, and
32
+ /// bottom. These values are not affected by the [TextDirection] .
71
33
///
72
- /// This may be changed to null, but only after the [padding] has been changed
73
- /// to a value that does not depend on the direction.
74
- TextDirection get textDirection => _textDirection;
75
- TextDirection _textDirection;
76
- set textDirection (TextDirection value) {
77
- if (_textDirection == value)
78
- return ;
79
- _textDirection = value;
80
- _markNeedResolution ();
81
- }
34
+ /// Must not be null or contain negative values when [performLayout] is called.
35
+ EdgeInsets get resolvedPadding;
82
36
83
37
/// The padding in the scroll direction on the side nearest the 0.0 scroll direction.
84
38
///
@@ -88,16 +42,16 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
88
42
assert (constraints != null );
89
43
assert (constraints.axisDirection != null );
90
44
assert (constraints.growthDirection != null );
91
- assert (_resolvedPadding != null );
45
+ assert (resolvedPadding != null );
92
46
switch (applyGrowthDirectionToAxisDirection (constraints.axisDirection, constraints.growthDirection)) {
93
47
case AxisDirection .up:
94
- return _resolvedPadding .bottom;
48
+ return resolvedPadding .bottom;
95
49
case AxisDirection .right:
96
- return _resolvedPadding .left;
50
+ return resolvedPadding .left;
97
51
case AxisDirection .down:
98
- return _resolvedPadding .top;
52
+ return resolvedPadding .top;
99
53
case AxisDirection .left:
100
- return _resolvedPadding .right;
54
+ return resolvedPadding .right;
101
55
}
102
56
return null ;
103
57
}
@@ -110,16 +64,16 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
110
64
assert (constraints != null );
111
65
assert (constraints.axisDirection != null );
112
66
assert (constraints.growthDirection != null );
113
- assert (_resolvedPadding != null );
67
+ assert (resolvedPadding != null );
114
68
switch (applyGrowthDirectionToAxisDirection (constraints.axisDirection, constraints.growthDirection)) {
115
69
case AxisDirection .up:
116
- return _resolvedPadding .top;
70
+ return resolvedPadding .top;
117
71
case AxisDirection .right:
118
- return _resolvedPadding .right;
72
+ return resolvedPadding .right;
119
73
case AxisDirection .down:
120
- return _resolvedPadding .bottom;
74
+ return resolvedPadding .bottom;
121
75
case AxisDirection .left:
122
- return _resolvedPadding .left;
76
+ return resolvedPadding .left;
123
77
}
124
78
return null ;
125
79
}
@@ -133,8 +87,8 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
133
87
double get mainAxisPadding {
134
88
assert (constraints != null );
135
89
assert (constraints.axis != null );
136
- assert (_resolvedPadding != null );
137
- return _resolvedPadding .along (constraints.axis);
90
+ assert (resolvedPadding != null );
91
+ return resolvedPadding .along (constraints.axis);
138
92
}
139
93
140
94
/// The total padding in the cross-axis direction. (In other words, for a
@@ -146,12 +100,12 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
146
100
double get crossAxisPadding {
147
101
assert (constraints != null );
148
102
assert (constraints.axis != null );
149
- assert (_resolvedPadding != null );
103
+ assert (resolvedPadding != null );
150
104
switch (constraints.axis) {
151
105
case Axis .horizontal:
152
- return _resolvedPadding .vertical;
106
+ return resolvedPadding .vertical;
153
107
case Axis .vertical:
154
- return _resolvedPadding .horizontal;
108
+ return resolvedPadding .horizontal;
155
109
}
156
110
return null ;
157
111
}
@@ -164,8 +118,7 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
164
118
165
119
@override
166
120
void performLayout () {
167
- _resolve ();
168
- assert (_resolvedPadding != null );
121
+ assert (resolvedPadding != null );
169
122
final double beforePadding = this .beforePadding;
170
123
final double afterPadding = this .afterPadding;
171
124
final double mainAxisPadding = this .mainAxisPadding;
@@ -240,16 +193,16 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
240
193
assert (constraints.growthDirection != null );
241
194
switch (applyGrowthDirectionToAxisDirection (constraints.axisDirection, constraints.growthDirection)) {
242
195
case AxisDirection .up:
243
- childParentData.paintOffset = Offset (_resolvedPadding .left, calculatePaintOffset (constraints, from: _resolvedPadding .bottom + childLayoutGeometry.scrollExtent, to: _resolvedPadding .bottom + childLayoutGeometry.scrollExtent + _resolvedPadding .top));
196
+ childParentData.paintOffset = Offset (resolvedPadding .left, calculatePaintOffset (constraints, from: resolvedPadding .bottom + childLayoutGeometry.scrollExtent, to: resolvedPadding .bottom + childLayoutGeometry.scrollExtent + resolvedPadding .top));
244
197
break ;
245
198
case AxisDirection .right:
246
- childParentData.paintOffset = Offset (calculatePaintOffset (constraints, from: 0.0 , to: _resolvedPadding .left), _resolvedPadding .top);
199
+ childParentData.paintOffset = Offset (calculatePaintOffset (constraints, from: 0.0 , to: resolvedPadding .left), resolvedPadding .top);
247
200
break ;
248
201
case AxisDirection .down:
249
- childParentData.paintOffset = Offset (_resolvedPadding .left, calculatePaintOffset (constraints, from: 0.0 , to: _resolvedPadding .top));
202
+ childParentData.paintOffset = Offset (resolvedPadding .left, calculatePaintOffset (constraints, from: 0.0 , to: resolvedPadding .top));
250
203
break ;
251
204
case AxisDirection .left:
252
- childParentData.paintOffset = Offset (calculatePaintOffset (constraints, from: _resolvedPadding .right + childLayoutGeometry.scrollExtent, to: _resolvedPadding .right + childLayoutGeometry.scrollExtent + _resolvedPadding .left), _resolvedPadding .top);
205
+ childParentData.paintOffset = Offset (calculatePaintOffset (constraints, from: resolvedPadding .right + childLayoutGeometry.scrollExtent, to: resolvedPadding .right + childLayoutGeometry.scrollExtent + resolvedPadding .left), resolvedPadding .top);
253
206
break ;
254
207
}
255
208
assert (childParentData.paintOffset != null );
@@ -289,14 +242,14 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
289
242
assert (constraints != null );
290
243
assert (constraints.axisDirection != null );
291
244
assert (constraints.growthDirection != null );
292
- assert (_resolvedPadding != null );
245
+ assert (resolvedPadding != null );
293
246
switch (applyGrowthDirectionToAxisDirection (constraints.axisDirection, constraints.growthDirection)) {
294
247
case AxisDirection .up:
295
248
case AxisDirection .down:
296
- return _resolvedPadding .left;
249
+ return resolvedPadding .left;
297
250
case AxisDirection .left:
298
251
case AxisDirection .right:
299
- return _resolvedPadding .top;
252
+ return resolvedPadding .top;
300
253
}
301
254
return null ;
302
255
}
@@ -346,6 +299,79 @@ class RenderSliverPadding extends RenderSliver with RenderObjectWithChildMixin<R
346
299
return true ;
347
300
}());
348
301
}
302
+ }
303
+
304
+ /// Insets a [RenderSliver] , applying padding on each side.
305
+ ///
306
+ /// A [RenderSliverPadding] object wraps the [SliverGeometry.layoutExtent] of
307
+ /// its child. Any incoming [SliverConstraints.overlap] is ignored and not
308
+ /// passed on to the child.
309
+ ///
310
+ /// {@macro flutter.rendering.sliverPadding.limitation}
311
+ class RenderSliverPadding extends RenderSliverEdgeInsetsPadding {
312
+ /// Creates a render object that insets its child in a viewport.
313
+ ///
314
+ /// The [padding] argument must not be null and must have non-negative insets.
315
+ RenderSliverPadding ({
316
+ @required EdgeInsetsGeometry padding,
317
+ TextDirection textDirection,
318
+ RenderSliver child,
319
+ }) : assert (padding != null ),
320
+ assert (padding.isNonNegative),
321
+ _padding = padding,
322
+ _textDirection = textDirection {
323
+ this .child = child;
324
+ }
325
+
326
+ @override
327
+ EdgeInsets get resolvedPadding => _resolvedPadding;
328
+ EdgeInsets _resolvedPadding;
329
+
330
+ void _resolve () {
331
+ if (resolvedPadding != null )
332
+ return ;
333
+ _resolvedPadding = padding.resolve (textDirection);
334
+ assert (resolvedPadding.isNonNegative);
335
+ }
336
+
337
+ void _markNeedsResolution () {
338
+ _resolvedPadding = null ;
339
+ markNeedsLayout ();
340
+ }
341
+
342
+ /// The amount to pad the child in each dimension.
343
+ ///
344
+ /// If this is set to an [EdgeInsetsDirectional] object, then [textDirection]
345
+ /// must not be null.
346
+ EdgeInsetsGeometry get padding => _padding;
347
+ EdgeInsetsGeometry _padding;
348
+ set padding (EdgeInsetsGeometry value) {
349
+ assert (value != null );
350
+ assert (padding.isNonNegative);
351
+ if (_padding == value)
352
+ return ;
353
+ _padding = value;
354
+ _markNeedsResolution ();
355
+ }
356
+
357
+ /// The text direction with which to resolve [padding] .
358
+ ///
359
+ /// This may be changed to null, but only after the [padding] has been changed
360
+ /// to a value that does not depend on the direction.
361
+ TextDirection get textDirection => _textDirection;
362
+ TextDirection _textDirection;
363
+ set textDirection (TextDirection value) {
364
+ if (_textDirection == value)
365
+ return ;
366
+ _textDirection = value;
367
+ _markNeedsResolution ();
368
+ }
369
+
370
+ @override
371
+ void performLayout () {
372
+ _resolve ();
373
+ super .performLayout ();
374
+ }
349
375
350
376
@override
351
377
void debugFillProperties (DiagnosticPropertiesBuilder properties) {
0 commit comments