Skip to content

Commit d4c7485

Browse files
authored
Make Decoration.padding non-nullable (#119581)
The default implementation returns EdgeInsets.zero, the ShapeDecoration subclass already makes it non-nullable, and there isn't any benefit to returning null as far as I can tell.
1 parent f6b0c6d commit d4c7485

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

packages/flutter/lib/src/material/ink_decoration.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ class Ink extends StatefulWidget {
237237
final double? height;
238238

239239
EdgeInsetsGeometry get _paddingIncludingDecoration {
240-
if (decoration == null || decoration!.padding == null) {
240+
if (decoration == null) {
241241
return padding ?? EdgeInsets.zero;
242242
}
243-
final EdgeInsetsGeometry decorationPadding = decoration!.padding!;
243+
final EdgeInsetsGeometry decorationPadding = decoration!.padding;
244244
if (padding == null) {
245245
return decorationPadding;
246246
}

packages/flutter/lib/src/painting/box_decoration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class BoxDecoration extends Decoration {
208208
final BoxShape shape;
209209

210210
@override
211-
EdgeInsetsGeometry? get padding => border?.dimensions;
211+
EdgeInsetsGeometry get padding => border?.dimensions ?? EdgeInsets.zero;
212212

213213
@override
214214
Path getClipPath(Rect rect, TextDirection textDirection) {

packages/flutter/lib/src/painting/decoration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ abstract class Decoration with Diagnosticable {
5959
/// [EdgeInsetsGeometry.resolve] to obtain an absolute [EdgeInsets]. (For
6060
/// example, [BorderDirectional] will return an [EdgeInsetsDirectional] for
6161
/// its [padding].)
62-
EdgeInsetsGeometry? get padding => EdgeInsets.zero;
62+
EdgeInsetsGeometry get padding => EdgeInsets.zero;
6363

6464
/// Whether this decoration is complex enough to benefit from caching its painting.
6565
bool get isComplex => false;

packages/flutter/lib/src/widgets/container.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,14 @@ class Container extends StatelessWidget {
367367
final Clip clipBehavior;
368368

369369
EdgeInsetsGeometry? get _paddingIncludingDecoration {
370-
if (decoration == null || decoration!.padding == null) {
370+
if (decoration == null) {
371371
return padding;
372372
}
373-
final EdgeInsetsGeometry? decorationPadding = decoration!.padding;
373+
final EdgeInsetsGeometry decorationPadding = decoration!.padding;
374374
if (padding == null) {
375375
return decorationPadding;
376376
}
377-
return padding!.add(decorationPadding!);
377+
return padding!.add(decorationPadding);
378378
}
379379

380380
@override

packages/flutter/test/widgets/animated_container_test.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,24 @@ void main() {
8080
' │ PlatformAssetBundle#00000(), devicePixelRatio: 3.0, platform:\n'
8181
' │ android)\n'
8282
' │\n'
83-
' └─child: RenderLimitedBox#00000\n'
83+
' └─child: RenderPadding#00000\n'
8484
' │ parentData: <none> (can use size)\n'
8585
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
8686
' │ size: Size(800.0, 600.0)\n'
87-
' │ maxWidth: 0.0\n'
88-
' │ maxHeight: 0.0\n'
87+
' │ padding: EdgeInsets.zero\n'
8988
' │\n'
90-
' └─child: RenderConstrainedBox#00000\n'
91-
' parentData: <none> (can use size)\n'
92-
' constraints: BoxConstraints(w=800.0, h=600.0)\n'
93-
' size: Size(800.0, 600.0)\n'
94-
' additionalConstraints: BoxConstraints(biggest)\n',
89+
' └─child: RenderLimitedBox#00000\n'
90+
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
91+
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
92+
' │ size: Size(800.0, 600.0)\n'
93+
' │ maxWidth: 0.0\n'
94+
' │ maxHeight: 0.0\n'
95+
' │\n'
96+
' └─child: RenderConstrainedBox#00000\n'
97+
' parentData: <none> (can use size)\n'
98+
' constraints: BoxConstraints(w=800.0, h=600.0)\n'
99+
' size: Size(800.0, 600.0)\n'
100+
' additionalConstraints: BoxConstraints(biggest)\n',
95101
),
96102
);
97103
});

0 commit comments

Comments
 (0)