From d4c74858fd2c9e701df0b4fca424914c357c2d81 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Tue, 31 Jan 2023 09:51:49 -0800 Subject: [PATCH] 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. --- .../lib/src/material/ink_decoration.dart | 4 ++-- .../lib/src/painting/box_decoration.dart | 2 +- .../flutter/lib/src/painting/decoration.dart | 2 +- .../flutter/lib/src/widgets/container.dart | 6 ++--- .../test/widgets/animated_container_test.dart | 22 ++++++++++++------- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/flutter/lib/src/material/ink_decoration.dart b/packages/flutter/lib/src/material/ink_decoration.dart index 8425c6358f69..3b5a9c6880de 100644 --- a/packages/flutter/lib/src/material/ink_decoration.dart +++ b/packages/flutter/lib/src/material/ink_decoration.dart @@ -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; } diff --git a/packages/flutter/lib/src/painting/box_decoration.dart b/packages/flutter/lib/src/painting/box_decoration.dart index 15e103b0ea45..8bb448a43482 100644 --- a/packages/flutter/lib/src/painting/box_decoration.dart +++ b/packages/flutter/lib/src/painting/box_decoration.dart @@ -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) { diff --git a/packages/flutter/lib/src/painting/decoration.dart b/packages/flutter/lib/src/painting/decoration.dart index 7a68bdf6bb96..2a52c0385dc6 100644 --- a/packages/flutter/lib/src/painting/decoration.dart +++ b/packages/flutter/lib/src/painting/decoration.dart @@ -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; diff --git a/packages/flutter/lib/src/widgets/container.dart b/packages/flutter/lib/src/widgets/container.dart index 5f1c505194b2..5e3f65badfb3 100644 --- a/packages/flutter/lib/src/widgets/container.dart +++ b/packages/flutter/lib/src/widgets/container.dart @@ -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 diff --git a/packages/flutter/test/widgets/animated_container_test.dart b/packages/flutter/test/widgets/animated_container_test.dart index ce9f17c64302..6d40f450cd5c 100644 --- a/packages/flutter/test/widgets/animated_container_test.dart +++ b/packages/flutter/test/widgets/animated_container_test.dart @@ -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: (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: (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: (can use size)\n' + ' constraints: BoxConstraints(w=800.0, h=600.0)\n' + ' size: Size(800.0, 600.0)\n' + ' additionalConstraints: BoxConstraints(biggest)\n', ), ); });