Unverified Commit 4bf297ce authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix nullability of ClipRRect.borderRadius (#125878)

The property was typed as nullable, but the code assumed its always non-null. This makes the property non-nullable as well.

Also refactors CupertinoListSection, which was flagged by the analyzer when borderRadius became non-nullable (no functional change, just cleaning up existing code to avoid the warning).
parent f53335bf
...@@ -402,8 +402,7 @@ class CupertinoListSection extends StatelessWidget { ...@@ -402,8 +402,7 @@ class CupertinoListSection extends StatelessWidget {
); );
} }
BorderRadius? childrenGroupBorderRadius; Widget? decoratedChildrenGroup;
DecoratedBox? decoratedChildrenGroup;
if (children != null && children!.isNotEmpty) { if (children != null && children!.isNotEmpty) {
// We construct childrenWithDividers as follows: // We construct childrenWithDividers as follows:
// Insert a short divider between all rows. // Insert a short divider between all rows.
...@@ -425,15 +424,11 @@ class CupertinoListSection extends StatelessWidget { ...@@ -425,15 +424,11 @@ class CupertinoListSection extends StatelessWidget {
childrenWithDividers.add(longDivider); childrenWithDividers.add(longDivider);
} }
switch (type) { final BorderRadius childrenGroupBorderRadius = switch (type) {
case CupertinoListSectionType.insetGrouped: CupertinoListSectionType.insetGrouped => _kDefaultInsetGroupedBorderRadius,
childrenGroupBorderRadius = _kDefaultInsetGroupedBorderRadius; CupertinoListSectionType.base => BorderRadius.zero,
case CupertinoListSectionType.base: };
childrenGroupBorderRadius = BorderRadius.zero;
}
// Refactored the decorate children group in one place to avoid repeating it
// twice down bellow in the returned widget.
decoratedChildrenGroup = DecoratedBox( decoratedChildrenGroup = DecoratedBox(
decoration: decoration ?? decoration: decoration ??
BoxDecoration( BoxDecoration(
...@@ -445,6 +440,17 @@ class CupertinoListSection extends StatelessWidget { ...@@ -445,6 +440,17 @@ class CupertinoListSection extends StatelessWidget {
), ),
child: Column(children: childrenWithDividers), child: Column(children: childrenWithDividers),
); );
decoratedChildrenGroup = Padding(
padding: margin,
child: clipBehavior == Clip.none
? decoratedChildrenGroup
: ClipRRect(
borderRadius: childrenGroupBorderRadius,
clipBehavior: clipBehavior,
child: decoratedChildrenGroup,
),
);
} }
return DecoratedBox( return DecoratedBox(
...@@ -464,17 +470,8 @@ class CupertinoListSection extends StatelessWidget { ...@@ -464,17 +470,8 @@ class CupertinoListSection extends StatelessWidget {
child: headerWidget, child: headerWidget,
), ),
), ),
if (children != null && children!.isNotEmpty) if (decoratedChildrenGroup != null)
Padding( decoratedChildrenGroup,
padding: margin,
child: clipBehavior == Clip.none
? decoratedChildrenGroup
: ClipRRect(
borderRadius: childrenGroupBorderRadius,
clipBehavior: clipBehavior,
child: decoratedChildrenGroup,
),
),
if (footerWidget != null) if (footerWidget != null)
Align( Align(
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
......
...@@ -850,7 +850,7 @@ class ClipRRect extends SingleChildRenderObjectWidget { ...@@ -850,7 +850,7 @@ class ClipRRect extends SingleChildRenderObjectWidget {
this.clipper, this.clipper,
this.clipBehavior = Clip.antiAlias, this.clipBehavior = Clip.antiAlias,
super.child, super.child,
}) : assert(borderRadius != null || clipper != null); });
/// The border radius of the rounded corners. /// The border radius of the rounded corners.
/// ///
...@@ -858,7 +858,7 @@ class ClipRRect extends SingleChildRenderObjectWidget { ...@@ -858,7 +858,7 @@ class ClipRRect extends SingleChildRenderObjectWidget {
/// exceed width/height. /// exceed width/height.
/// ///
/// This value is ignored if [clipper] is non-null. /// This value is ignored if [clipper] is non-null.
final BorderRadiusGeometry? borderRadius; final BorderRadiusGeometry borderRadius;
/// If non-null, determines which clip to use. /// If non-null, determines which clip to use.
final CustomClipper<RRect>? clipper; final CustomClipper<RRect>? clipper;
...@@ -871,7 +871,7 @@ class ClipRRect extends SingleChildRenderObjectWidget { ...@@ -871,7 +871,7 @@ class ClipRRect extends SingleChildRenderObjectWidget {
@override @override
RenderClipRRect createRenderObject(BuildContext context) { RenderClipRRect createRenderObject(BuildContext context) {
return RenderClipRRect( return RenderClipRRect(
borderRadius: borderRadius!, borderRadius: borderRadius,
clipper: clipper, clipper: clipper,
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
textDirection: Directionality.maybeOf(context), textDirection: Directionality.maybeOf(context),
...@@ -881,7 +881,7 @@ class ClipRRect extends SingleChildRenderObjectWidget { ...@@ -881,7 +881,7 @@ class ClipRRect extends SingleChildRenderObjectWidget {
@override @override
void updateRenderObject(BuildContext context, RenderClipRRect renderObject) { void updateRenderObject(BuildContext context, RenderClipRRect renderObject) {
renderObject renderObject
..borderRadius = borderRadius! ..borderRadius = borderRadius
..clipBehavior = clipBehavior ..clipBehavior = clipBehavior
..clipper = clipper ..clipper = clipper
..textDirection = Directionality.maybeOf(context); ..textDirection = Directionality.maybeOf(context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment