diff --git a/packages/flutter/lib/fix_data/fix_cupertino.yaml b/packages/flutter/lib/fix_data/fix_cupertino.yaml index 1a4563dfac..ff380c1286 100644 --- a/packages/flutter/lib/fix_data/fix_cupertino.yaml +++ b/packages/flutter/lib/fix_data/fix_cupertino.yaml @@ -341,4 +341,67 @@ transforms: oldName: 'trackColor' newName: 'inactiveTrackColor' -# Before adding a new fix: read instructions at the top of this file. + # Changes made in https://github.com/flutter/flutter/pull/152981 + - title: "Replace with 'fillColor'" + date: 2024-08-08 + element: + uris: [ 'cupertino.dart' ] + constructor: '' + inClass: 'CupertinoCheckbox' + oneOf: + - if: "fillColor == '' && activeColor != ''" + changes: + - kind: 'addParameter' + index: 5 + name: 'fillColor' + style: optional_named + argumentValue: + expression: "WidgetStateProperty.resolveWith((Set states) {\n + if (states.contains(WidgetState.disabled)) {\n + return CupertinoColors.white.withOpacity(0.5);\n + }\n + if (states.contains(WidgetState.selected)) {\n + return {% activeColor %};\n + }\n + return {% inactiveColor %};\n + })" + requiredIf: "inactiveColor != ''" + - kind: 'removeParameter' + name: inactiveColor + - if: "fillColor == '' && activeColor == ''" + changes: + - kind: 'addParameter' + index: 5 + name: 'fillColor' + style: optional_named + argumentValue: + expression: "WidgetStateProperty.resolveWith((Set states) {\n + if (states.contains(WidgetState.disabled)) {\n + return CupertinoColors.white.withOpacity(0.5);\n + }\n + if (states.contains(WidgetState.selected)) {\n + return CupertinoDynamicColor.resolve(CupertinoDynamicColor.withBrightness(\n + color: CupertinoColors.activeBlue,\n + darkColor: Color.fromARGB(255, 50, 100, 215),\n + ), context);\n + }\n + return {% inactiveColor %};\n + })" + requiredIf: "inactiveColor != ''" + - kind: 'removeParameter' + name: inactiveColor + - if: "fillColor != ''" + changes: + - kind: 'removeParameter' + name: inactiveColor + variables: + inactiveColor: + kind: fragment + value: 'arguments[inactiveColor]' + activeColor: + kind: fragment + value: 'arguments[activeColor]' + fillColor: + kind: fragment + value: 'arguments[fillColor]' +# 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/checkbox.dart b/packages/flutter/lib/src/cupertino/checkbox.dart index b1117b33f6..ef13df6041 100644 --- a/packages/flutter/lib/src/cupertino/checkbox.dart +++ b/packages/flutter/lib/src/cupertino/checkbox.dart @@ -97,6 +97,11 @@ class CupertinoCheckbox extends StatefulWidget { this.tristate = false, required this.onChanged, this.activeColor, + @Deprecated( + 'Use fillColor instead. ' + 'fillColor now manages the background color in all states. ' + 'This feature was deprecated after v3.24.0-0.2.pre.' + ) this.inactiveColor, this.fillColor, this.checkColor, @@ -184,15 +189,19 @@ class CupertinoCheckbox extends StatefulWidget { /// /// If [fillColor] resolves to null for the requested state, then the fill color /// falls back to [activeColor] if the state includes [WidgetState.selected], - /// or [inactiveColor] otherwise. + /// [CupertinoColors.white] at 50% opacity if checkbox is disabled, + /// and [CupertinoColors.white] otherwise. final WidgetStateProperty? fillColor; /// The color used if the checkbox is inactive. /// - /// If [fillColor] returns a non-null color in the unselected - /// state, [fillColor] will be used instead of [inactiveColor]. - /// - /// By default, [CupertinoColors.inactiveGray] is used. + /// Currently [inactiveColor] is not used. Instead, [fillColor] controls the + /// color of the background in all states, including when unselected. + @Deprecated( + 'Use fillColor instead. ' + 'fillColor now manages the background color in all states. ' + 'This feature was deprecated after v3.24.0-0.2.pre.' + ) final Color? inactiveColor; /// The color to use for the check icon when this checkbox is checked. diff --git a/packages/flutter/test_fixes/cupertino/cupertino.dart b/packages/flutter/test_fixes/cupertino/cupertino.dart index e418c5cb9c..588ae37b7f 100644 --- a/packages/flutter/test_fixes/cupertino/cupertino.dart +++ b/packages/flutter/test_fixes/cupertino/cupertino.dart @@ -264,4 +264,9 @@ void main() { trackColor: Colors.red, ); Color? inactiveTrackColor = cupertinoSwitch.trackColor; + + // https://github.com/flutter/flutter/pull/152981 + CupertinoCheckbox(inactiveColor: Colors.red); + CupertinoCheckbox(inactiveColor: Colors.red, activeColor: Colors.white); + CupertinoCheckbox(inactiveColor: Colors.red, fillColor: WidgetStatePropertyAll(CupertinoColors.white)); } diff --git a/packages/flutter/test_fixes/cupertino/cupertino.dart.expect b/packages/flutter/test_fixes/cupertino/cupertino.dart.expect index e6ab0deeb4..ae7712e968 100644 --- a/packages/flutter/test_fixes/cupertino/cupertino.dart.expect +++ b/packages/flutter/test_fixes/cupertino/cupertino.dart.expect @@ -264,4 +264,28 @@ void main() { inactiveTrackColor: Colors.red, ); Color? inactiveTrackColor = cupertinoSwitch.inactiveTrackColor; + + // https://github.com/flutter/flutter/pull/152981 + CupertinoCheckbox(fillColor: WidgetStateProperty.resolveWith((Set states) { + if (states.contains(WidgetState.disabled)) { + return CupertinoColors.white.withOpacity(0.5); + } + if (states.contains(WidgetState.selected)) { + return CupertinoDynamicColor.resolve(CupertinoDynamicColor.withBrightness( + color: CupertinoColors.activeBlue, + darkColor: Color.fromARGB(255, 50, 100, 215), + ), context); + } + return Colors.red; + })); + CupertinoCheckbox(activeColor: Colors.white, fillColor: WidgetStateProperty.resolveWith((Set states) { + if (states.contains(WidgetState.disabled)) { + return CupertinoColors.white.withOpacity(0.5); + } + if (states.contains(WidgetState.selected)) { + return Colors.white; + } + return Colors.red; + })); + CupertinoCheckbox(fillColor: WidgetStatePropertyAll(CupertinoColors.white)); }