Skip to content

Commit 4bf297c

Browse files
authored
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).
1 parent f53335b commit 4bf297c

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

packages/flutter/lib/src/cupertino/list_section.dart

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ class CupertinoListSection extends StatelessWidget {
402402
);
403403
}
404404

405-
BorderRadius? childrenGroupBorderRadius;
406-
DecoratedBox? decoratedChildrenGroup;
405+
Widget? decoratedChildrenGroup;
407406
if (children != null && children!.isNotEmpty) {
408407
// We construct childrenWithDividers as follows:
409408
// Insert a short divider between all rows.
@@ -425,15 +424,11 @@ class CupertinoListSection extends StatelessWidget {
425424
childrenWithDividers.add(longDivider);
426425
}
427426

428-
switch (type) {
429-
case CupertinoListSectionType.insetGrouped:
430-
childrenGroupBorderRadius = _kDefaultInsetGroupedBorderRadius;
431-
case CupertinoListSectionType.base:
432-
childrenGroupBorderRadius = BorderRadius.zero;
433-
}
427+
final BorderRadius childrenGroupBorderRadius = switch (type) {
428+
CupertinoListSectionType.insetGrouped => _kDefaultInsetGroupedBorderRadius,
429+
CupertinoListSectionType.base => BorderRadius.zero,
430+
};
434431

435-
// Refactored the decorate children group in one place to avoid repeating it
436-
// twice down bellow in the returned widget.
437432
decoratedChildrenGroup = DecoratedBox(
438433
decoration: decoration ??
439434
BoxDecoration(
@@ -445,6 +440,17 @@ class CupertinoListSection extends StatelessWidget {
445440
),
446441
child: Column(children: childrenWithDividers),
447442
);
443+
444+
decoratedChildrenGroup = Padding(
445+
padding: margin,
446+
child: clipBehavior == Clip.none
447+
? decoratedChildrenGroup
448+
: ClipRRect(
449+
borderRadius: childrenGroupBorderRadius,
450+
clipBehavior: clipBehavior,
451+
child: decoratedChildrenGroup,
452+
),
453+
);
448454
}
449455

450456
return DecoratedBox(
@@ -464,17 +470,8 @@ class CupertinoListSection extends StatelessWidget {
464470
child: headerWidget,
465471
),
466472
),
467-
if (children != null && children!.isNotEmpty)
468-
Padding(
469-
padding: margin,
470-
child: clipBehavior == Clip.none
471-
? decoratedChildrenGroup
472-
: ClipRRect(
473-
borderRadius: childrenGroupBorderRadius,
474-
clipBehavior: clipBehavior,
475-
child: decoratedChildrenGroup,
476-
),
477-
),
473+
if (decoratedChildrenGroup != null)
474+
decoratedChildrenGroup,
478475
if (footerWidget != null)
479476
Align(
480477
alignment: AlignmentDirectional.centerStart,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,15 +850,15 @@ class ClipRRect extends SingleChildRenderObjectWidget {
850850
this.clipper,
851851
this.clipBehavior = Clip.antiAlias,
852852
super.child,
853-
}) : assert(borderRadius != null || clipper != null);
853+
});
854854

855855
/// The border radius of the rounded corners.
856856
///
857857
/// Values are clamped so that horizontal and vertical radii sums do not
858858
/// exceed width/height.
859859
///
860860
/// This value is ignored if [clipper] is non-null.
861-
final BorderRadiusGeometry? borderRadius;
861+
final BorderRadiusGeometry borderRadius;
862862

863863
/// If non-null, determines which clip to use.
864864
final CustomClipper<RRect>? clipper;
@@ -871,7 +871,7 @@ class ClipRRect extends SingleChildRenderObjectWidget {
871871
@override
872872
RenderClipRRect createRenderObject(BuildContext context) {
873873
return RenderClipRRect(
874-
borderRadius: borderRadius!,
874+
borderRadius: borderRadius,
875875
clipper: clipper,
876876
clipBehavior: clipBehavior,
877877
textDirection: Directionality.maybeOf(context),
@@ -881,7 +881,7 @@ class ClipRRect extends SingleChildRenderObjectWidget {
881881
@override
882882
void updateRenderObject(BuildContext context, RenderClipRRect renderObject) {
883883
renderObject
884-
..borderRadius = borderRadius!
884+
..borderRadius = borderRadius
885885
..clipBehavior = clipBehavior
886886
..clipper = clipper
887887
..textDirection = Directionality.maybeOf(context);

0 commit comments

Comments
 (0)