From bae79714317430baa8e9d2edeb6accdaedfd5e06 Mon Sep 17 00:00:00 2001 From: Jatin Nagar <121741542+itsjatinnagar@users.noreply.github.com> Date: Sun, 6 Oct 2024 20:19:20 +0530 Subject: [PATCH] CheckboxListTile: add property to scale the checkbox (#154806) Added a property in the CheckboxListTile to scale the underlying Checkbox using `Transform.scale`. Fixes: #81334 --- .../lib/src/material/checkbox_list_tile.dart | 81 +++++++++++-------- .../material/checkbox_list_tile_test.dart | 43 ++++++++++ 2 files changed, 90 insertions(+), 34 deletions(-) diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index 0c3718fb7f6..decde74b991 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -205,6 +205,7 @@ class CheckboxListTile extends StatelessWidget { this.onFocusChange, this.enableFeedback, this.checkboxSemanticLabel, + this.checkboxScaleFactor = 1.0, this.internalAddSemanticForOnTap = false, }) : _checkboxType = _CheckboxType.material, assert(tristate || value != null), @@ -250,6 +251,7 @@ class CheckboxListTile extends StatelessWidget { this.onFocusChange, this.enableFeedback, this.checkboxSemanticLabel, + this.checkboxScaleFactor = 1.0, this.internalAddSemanticForOnTap = false, }) : _checkboxType = _CheckboxType.adaptive, assert(tristate || value != null), @@ -473,6 +475,11 @@ class CheckboxListTile extends StatelessWidget { // the default value to true. final bool internalAddSemanticForOnTap; + /// Controls the scaling factor applied to the [Checkbox] within the [CheckboxListTile]. + /// + /// Defaults to 1.0. + final double checkboxScaleFactor; + /// {@macro flutter.material.checkbox.semanticLabel} final String? checkboxSemanticLabel; @@ -497,44 +504,50 @@ class CheckboxListTile extends StatelessWidget { switch (_checkboxType) { case _CheckboxType.material: control = ExcludeFocus( - child: Checkbox( - value: value, - onChanged: enabled ?? true ? onChanged : null, - mouseCursor: mouseCursor, - activeColor: activeColor, - fillColor: fillColor, - checkColor: checkColor, - hoverColor: hoverColor, - overlayColor: overlayColor, - splashRadius: splashRadius, - materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, - autofocus: autofocus, - tristate: tristate, - shape: checkboxShape, - side: side, - isError: isError, - semanticLabel: checkboxSemanticLabel, + child: Transform.scale( + scale: checkboxScaleFactor, + child: Checkbox( + value: value, + onChanged: enabled ?? true ? onChanged : null, + mouseCursor: mouseCursor, + activeColor: activeColor, + fillColor: fillColor, + checkColor: checkColor, + hoverColor: hoverColor, + overlayColor: overlayColor, + splashRadius: splashRadius, + materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, + autofocus: autofocus, + tristate: tristate, + shape: checkboxShape, + side: side, + isError: isError, + semanticLabel: checkboxSemanticLabel, + ), ), ); case _CheckboxType.adaptive: control = ExcludeFocus( - child: Checkbox.adaptive( - value: value, - onChanged: enabled ?? true ? onChanged : null, - mouseCursor: mouseCursor, - activeColor: activeColor, - fillColor: fillColor, - checkColor: checkColor, - hoverColor: hoverColor, - overlayColor: overlayColor, - splashRadius: splashRadius, - materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, - autofocus: autofocus, - tristate: tristate, - shape: checkboxShape, - side: side, - isError: isError, - semanticLabel: checkboxSemanticLabel, + child: Transform.scale( + scale: checkboxScaleFactor, + child: Checkbox.adaptive( + value: value, + onChanged: enabled ?? true ? onChanged : null, + mouseCursor: mouseCursor, + activeColor: activeColor, + fillColor: fillColor, + checkColor: checkColor, + hoverColor: hoverColor, + overlayColor: overlayColor, + splashRadius: splashRadius, + materialTapTargetSize: materialTapTargetSize ?? MaterialTapTargetSize.shrinkWrap, + autofocus: autofocus, + tristate: tristate, + shape: checkboxShape, + side: side, + isError: isError, + semanticLabel: checkboxSemanticLabel, + ), ), ); } diff --git a/packages/flutter/test/material/checkbox_list_tile_test.dart b/packages/flutter/test/material/checkbox_list_tile_test.dart index 0b96de6162c..c32bacd9785 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -1266,6 +1266,49 @@ void main() { final Offset offsetPlatform = tester.getTopLeft(platform); expect(offsetPlatform, const Offset(736.0, 8.0)); }); + + testWidgets('CheckboxListTile renders with default scale', (WidgetTester tester) async { + await tester.pumpWidget(const MaterialApp( + home: Material( + child: CheckboxListTile( + value: false, + onChanged: null, + ), + ), + )); + + final Transform widget = tester.widget( + find.ancestor( + of: find.byType(Checkbox), + matching: find.byType(Transform), + ), + ); + + expect(widget.transform.getMaxScaleOnAxis(), 1.0); + }); + + testWidgets('CheckboxListTile respects checkboxScaleFactor', (WidgetTester tester) async { + const double scale = 1.5; + + await tester.pumpWidget(const MaterialApp( + home: Material( + child: CheckboxListTile( + value: false, + onChanged: null, + checkboxScaleFactor: scale, + ), + ), + )); + + final Transform widget = tester.widget( + find.ancestor( + of: find.byType(Checkbox), + matching: find.byType(Transform), + ), + ); + + expect(widget.transform.getMaxScaleOnAxis(), scale); + }); } class _SelectedGrabMouseCursor extends MaterialStateMouseCursor {