Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Make Decoration.padding non-nullable (#119581)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hixie committed Jan 31, 2023
1 parent f6b0c6d commit d4c7485
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/material/ink_decoration.dart
Expand Up @@ -237,10 +237,10 @@ class Ink extends StatefulWidget {
final double? height;

EdgeInsetsGeometry get _paddingIncludingDecoration {
if (decoration == null || decoration!.padding == null) {
if (decoration == null) {
return padding ?? EdgeInsets.zero;
}
final EdgeInsetsGeometry decorationPadding = decoration!.padding!;
final EdgeInsetsGeometry decorationPadding = decoration!.padding;
if (padding == null) {
return decorationPadding;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/painting/box_decoration.dart
Expand Up @@ -208,7 +208,7 @@ class BoxDecoration extends Decoration {
final BoxShape shape;

@override
EdgeInsetsGeometry? get padding => border?.dimensions;
EdgeInsetsGeometry get padding => border?.dimensions ?? EdgeInsets.zero;

@override
Path getClipPath(Rect rect, TextDirection textDirection) {
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/painting/decoration.dart
Expand Up @@ -59,7 +59,7 @@ abstract class Decoration with Diagnosticable {
/// [EdgeInsetsGeometry.resolve] to obtain an absolute [EdgeInsets]. (For
/// example, [BorderDirectional] will return an [EdgeInsetsDirectional] for
/// its [padding].)
EdgeInsetsGeometry? get padding => EdgeInsets.zero;
EdgeInsetsGeometry get padding => EdgeInsets.zero;

/// Whether this decoration is complex enough to benefit from caching its painting.
bool get isComplex => false;
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/widgets/container.dart
Expand Up @@ -367,14 +367,14 @@ class Container extends StatelessWidget {
final Clip clipBehavior;

EdgeInsetsGeometry? get _paddingIncludingDecoration {
if (decoration == null || decoration!.padding == null) {
if (decoration == null) {
return padding;
}
final EdgeInsetsGeometry? decorationPadding = decoration!.padding;
final EdgeInsetsGeometry decorationPadding = decoration!.padding;
if (padding == null) {
return decorationPadding;
}
return padding!.add(decorationPadding!);
return padding!.add(decorationPadding);
}

@override
Expand Down
22 changes: 14 additions & 8 deletions packages/flutter/test/widgets/animated_container_test.dart
Expand Up @@ -80,18 +80,24 @@ void main() {
' │ PlatformAssetBundle#00000(), devicePixelRatio: 3.0, platform:\n'
' │ android)\n'
' │\n'
' └─child: RenderLimitedBox#00000\n'
' └─child: RenderPadding#00000\n'
' │ parentData: <none> (can use size)\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n'
' │ maxWidth: 0.0\n'
' │ maxHeight: 0.0\n'
' │ padding: EdgeInsets.zero\n'
' │\n'
' └─child: RenderConstrainedBox#00000\n'
' parentData: <none> (can use size)\n'
' constraints: BoxConstraints(w=800.0, h=600.0)\n'
' size: Size(800.0, 600.0)\n'
' additionalConstraints: BoxConstraints(biggest)\n',
' └─child: RenderLimitedBox#00000\n'
' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n'
' │ maxWidth: 0.0\n'
' │ maxHeight: 0.0\n'
' │\n'
' └─child: RenderConstrainedBox#00000\n'
' parentData: <none> (can use size)\n'
' constraints: BoxConstraints(w=800.0, h=600.0)\n'
' size: Size(800.0, 600.0)\n'
' additionalConstraints: BoxConstraints(biggest)\n',
),
);
});
Expand Down

0 comments on commit d4c7485

Please sign in to comment.