diff --git a/packages/flutter/lib/fix_data/fix_cupertino.yaml b/packages/flutter/lib/fix_data/fix_cupertino.yaml index ff380c1286..f1d8ba878d 100644 --- a/packages/flutter/lib/fix_data/fix_cupertino.yaml +++ b/packages/flutter/lib/fix_data/fix_cupertino.yaml @@ -404,4 +404,28 @@ transforms: fillColor: kind: fragment value: 'arguments[fillColor]' + + # Changes made in https://github.com/flutter/flutter/pull/161295 + - title: "Migrate 'minSize' to 'minimumSize'" + date: 2025-01-09 + element: + uris: [ 'cupertino.dart' ] + constructor: '' + inClass: 'CupertinoButton' + oneOf: + - if: "minSize != ''" + changes: + - kind: 'addParameter' + index: 7 + name: 'minimumSize' + style: optional_named + argumentValue: + expression: 'Size({% minSize %}, {% minSize %})' + requiredIf: "minSize != ''" + - kind: 'removeParameter' + name: 'minSize' + variables: + minSize: + kind: fragment + value: 'arguments[minSize]' # Before adding a new fix: read instructions at the top of this file. \ No newline at end of file diff --git a/packages/flutter/lib/src/cupertino/button.dart b/packages/flutter/lib/src/cupertino/button.dart index 19bd455dd5..4e929daab5 100644 --- a/packages/flutter/lib/src/cupertino/button.dart +++ b/packages/flutter/lib/src/cupertino/button.dart @@ -76,7 +76,12 @@ class CupertinoButton extends StatefulWidget { this.padding, this.color, this.disabledColor = CupertinoColors.quaternarySystemFill, + @Deprecated( + 'Use minimumSize instead. ' + 'This feature was deprecated after v3.28.0-3.0.pre.', + ) this.minSize, + this.minimumSize, this.pressedOpacity = 0.4, this.borderRadius, this.alignment = Alignment.center, @@ -87,6 +92,7 @@ class CupertinoButton extends StatefulWidget { this.onLongPress, required this.onPressed, }) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)), + assert(minimumSize == null || minSize == null), _style = _CupertinoButtonStyle.plain; /// Creates an iOS-style button with a tinted background. @@ -105,7 +111,12 @@ class CupertinoButton extends StatefulWidget { this.padding, this.color, this.disabledColor = CupertinoColors.tertiarySystemFill, + @Deprecated( + 'Use minimumSize instead. ' + 'This feature was deprecated after v3.28.0-3.0.pre.', + ) this.minSize, + this.minimumSize, this.pressedOpacity = 0.4, this.borderRadius, this.alignment = Alignment.center, @@ -115,7 +126,8 @@ class CupertinoButton extends StatefulWidget { this.autofocus = false, this.onLongPress, required this.onPressed, - }) : _style = _CupertinoButtonStyle.tinted; + }) : assert(minimumSize == null || minSize == null), + _style = _CupertinoButtonStyle.tinted; /// Creates an iOS-style button with a filled background. /// @@ -129,7 +141,12 @@ class CupertinoButton extends StatefulWidget { this.sizeStyle = CupertinoButtonSize.large, this.padding, this.disabledColor = CupertinoColors.tertiarySystemFill, + @Deprecated( + 'Use minimumSize instead. ' + 'This feature was deprecated after v3.28.0-3.0.pre.', + ) this.minSize, + this.minimumSize, this.pressedOpacity = 0.4, this.borderRadius, this.alignment = Alignment.center, @@ -140,6 +157,7 @@ class CupertinoButton extends StatefulWidget { this.onLongPress, required this.onPressed, }) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)), + assert(minimumSize == null || minSize == null), color = null, _style = _CupertinoButtonStyle.filled; @@ -181,8 +199,19 @@ class CupertinoButton extends StatefulWidget { /// /// Defaults to kMinInteractiveDimensionCupertino which the iOS Human /// Interface Guidelines recommends as the minimum tappable area. + @Deprecated( + 'Use minimumSize instead. ' + 'This feature was deprecated after v3.28.0-3.0.pre.', + ) final double? minSize; + /// The minimum size of the button. + /// + /// Defaults to a button with a height and a width of + /// [kMinInteractiveDimensionCupertino], which the iOS Human + /// Interface Guidelines recommends as the minimum tappable area. + final Size? minimumSize; + /// The opacity that the button will fade to when it is pressed. /// The button will have an opacity of 1.0 when it is not pressed. /// @@ -355,6 +384,12 @@ class _CupertinoButtonState extends State with SingleTickerProv @override Widget build(BuildContext context) { final bool enabled = widget.enabled; + final Size? minimumSize = + widget.minimumSize == null + ? widget.minSize == null + ? null + : Size(widget.minSize!, widget.minSize!) + : widget.minimumSize!; final CupertinoThemeData themeData = CupertinoTheme.of(context); final Color primaryColor = themeData.primaryColor; final Color? backgroundColor = (widget.color == null @@ -418,11 +453,11 @@ class _CupertinoButtonState extends State with SingleTickerProv child: ConstrainedBox( constraints: BoxConstraints( minWidth: - widget.minSize ?? + minimumSize?.width ?? kCupertinoButtonMinSize[widget.sizeStyle] ?? kMinInteractiveDimensionCupertino, minHeight: - widget.minSize ?? + minimumSize?.height ?? kCupertinoButtonMinSize[widget.sizeStyle] ?? kMinInteractiveDimensionCupertino, ), diff --git a/packages/flutter/test/cupertino/button_test.dart b/packages/flutter/test/cupertino/button_test.dart index 384cb37d34..c08d800377 100644 --- a/packages/flutter/test/cupertino/button_test.dart +++ b/packages/flutter/test/cupertino/button_test.dart @@ -48,6 +48,17 @@ void main() { ); }); + testWidgets('Minimum size minimumSize parameter', (WidgetTester tester) async { + const Size size = Size(60.0, 100.0); + await tester.pumpWidget( + boilerplate( + child: const CupertinoButton(onPressed: null, minimumSize: size, child: SizedBox.shrink()), + ), + ); + final RenderBox buttonBox = tester.renderObject(find.byType(CupertinoButton)); + expect(buttonBox.size, size); + }); + testWidgets('Size grows with text', (WidgetTester tester) async { await tester.pumpWidget( boilerplate( diff --git a/packages/flutter/test_fixes/cupertino/cupertino.dart b/packages/flutter/test_fixes/cupertino/cupertino.dart index 0af9e34817..dffefec18f 100644 --- a/packages/flutter/test_fixes/cupertino/cupertino.dart +++ b/packages/flutter/test_fixes/cupertino/cupertino.dart @@ -286,4 +286,7 @@ void main() { inactiveColor: Colors.red, fillColor: WidgetStatePropertyAll(CupertinoColors.white), ); + + // https://github.com/flutter/flutter/pull/161295 + CupertinoButton(minSize: 60.0); } diff --git a/packages/flutter/test_fixes/cupertino/cupertino.dart.expect b/packages/flutter/test_fixes/cupertino/cupertino.dart.expect index 41876a0177..bd25a93304 100644 --- a/packages/flutter/test_fixes/cupertino/cupertino.dart.expect +++ b/packages/flutter/test_fixes/cupertino/cupertino.dart.expect @@ -304,4 +304,7 @@ void main() { CupertinoCheckbox( fillColor: WidgetStatePropertyAll(CupertinoColors.white), ); + + // https://github.com/flutter/flutter/pull/161295 + CupertinoButton(minimumSize: Size(60.0, 60.0)); }