Style: Rename CupertinoSwitch activeColor and trackColor to activeTrackColor and InactiveTrackColor (#151367)
Style: Rename CupertinoSwitch `activeColor` and `trackColor` to `activeTrackColor` and `InactiveTrackColor` Resolves #151256
This commit is contained in:
parent
d595e98d85
commit
0f7bceb9c4
@ -40,7 +40,7 @@ class _CupertinoSwitchExampleState extends State<CupertinoSwitchExample> {
|
||||
child: CupertinoSwitch(
|
||||
// This bool value toggles the switch.
|
||||
value: switchValue,
|
||||
activeColor: CupertinoColors.activeBlue,
|
||||
activeTrackColor: CupertinoColors.activeBlue,
|
||||
onChanged: (bool? value) {
|
||||
// This is called when the user toggles the switch.
|
||||
setState(() {
|
||||
|
@ -295,4 +295,50 @@ transforms:
|
||||
- kind: 'rename'
|
||||
newName: 'buildOverscrollIndicator'
|
||||
|
||||
# Changes made in https://github.com/flutter/flutter/pull/151367
|
||||
- title: "Rename to 'activeTrackColor'"
|
||||
date: 2024-07-15
|
||||
element:
|
||||
uris: [ 'cupertino.dart' ]
|
||||
getter: 'activeColor'
|
||||
inClass: 'CupertinoSwitch'
|
||||
changes:
|
||||
- kind: 'rename'
|
||||
newName: 'activeTrackColor'
|
||||
|
||||
# Changes made in https://github.com/flutter/flutter/pull/151367
|
||||
- title: "Migrate to 'activeTrackColor'"
|
||||
date: 2024-07-15
|
||||
element:
|
||||
uris: [ 'cupertino.dart' ]
|
||||
constructor: ''
|
||||
inClass: 'CupertinoSwitch'
|
||||
changes:
|
||||
- kind: 'renameParameter'
|
||||
oldName: 'activeColor'
|
||||
newName: 'activeTrackColor'
|
||||
|
||||
# Changes made in https://github.com/flutter/flutter/pull/151367
|
||||
- title: "Rename to 'inactiveTrackColor'"
|
||||
date: 2024-07-15
|
||||
element:
|
||||
uris: [ 'cupertino.dart' ]
|
||||
getter: 'trackColor'
|
||||
inClass: 'CupertinoSwitch'
|
||||
changes:
|
||||
- kind: 'rename'
|
||||
newName: 'inactiveTrackColor'
|
||||
|
||||
# Changes made in https://github.com/flutter/flutter/pull/151367
|
||||
- title: "Migrate to 'inactiveTrackColor'"
|
||||
date: 2024-07-15
|
||||
element:
|
||||
uris: [ 'cupertino.dart' ]
|
||||
constructor: ''
|
||||
inClass: 'CupertinoSwitch'
|
||||
changes:
|
||||
- kind: 'renameParameter'
|
||||
oldName: 'trackColor'
|
||||
newName: 'inactiveTrackColor'
|
||||
|
||||
# Before adding a new fix: read instructions at the top of this file.
|
||||
|
@ -120,8 +120,18 @@ class CupertinoSwitch extends StatefulWidget {
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.activeColor,
|
||||
this.trackColor,
|
||||
@Deprecated(
|
||||
'Use activeTrackColor instead. '
|
||||
'This feature was deprecated after v3.24.0-0.2.pre.'
|
||||
)
|
||||
Color? activeColor,
|
||||
@Deprecated(
|
||||
'Use inactiveTrackColor instead. '
|
||||
'This feature was deprecated after v3.24.0-0.2.pre.'
|
||||
)
|
||||
Color? trackColor,
|
||||
Color? activeTrackColor,
|
||||
Color? inactiveTrackColor,
|
||||
this.thumbColor,
|
||||
this.inactiveThumbColor,
|
||||
this.applyTheme,
|
||||
@ -141,7 +151,11 @@ class CupertinoSwitch extends StatefulWidget {
|
||||
this.autofocus = false,
|
||||
this.dragStartBehavior = DragStartBehavior.start,
|
||||
}) : assert(activeThumbImage != null || onActiveThumbImageError == null),
|
||||
assert(inactiveThumbImage != null || onInactiveThumbImageError == null);
|
||||
assert(inactiveThumbImage != null || onInactiveThumbImageError == null),
|
||||
assert(activeTrackColor == null || activeColor == null),
|
||||
assert(inactiveTrackColor == null || trackColor == null),
|
||||
activeTrackColor = activeTrackColor ?? activeColor,
|
||||
inactiveTrackColor = inactiveTrackColor ?? trackColor;
|
||||
|
||||
/// Whether this switch is on or off.
|
||||
final bool value;
|
||||
@ -178,8 +192,23 @@ class CupertinoSwitch extends StatefulWidget {
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [trackColor], the color to use for the track when the switch is off.
|
||||
final Color? activeColor;
|
||||
/// * [inactiveTrackColor], the color to use for the track when the switch is off.
|
||||
@Deprecated(
|
||||
'Use activeTrackColor instead. '
|
||||
'This feature was deprecated after v3.24.0-0.2.pre.'
|
||||
)
|
||||
Color? get activeColor => activeTrackColor;
|
||||
|
||||
/// The color to use for the track when the switch is on.
|
||||
///
|
||||
/// If null and [applyTheme] is false, defaults to [CupertinoColors.systemGreen]
|
||||
/// in accordance to native iOS behavior. Otherwise, defaults to
|
||||
/// [CupertinoThemeData.primaryColor].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [inactiveTrackColor], the color to use for the track when the switch is off.
|
||||
final Color? activeTrackColor;
|
||||
|
||||
/// The color to use for the track when the switch is off.
|
||||
///
|
||||
@ -187,8 +216,21 @@ class CupertinoSwitch extends StatefulWidget {
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [activeColor], the color to use for the track when the switch is on.
|
||||
final Color? trackColor;
|
||||
/// * [inactiveTrackColor], the color to use for the track when the switch is off.
|
||||
@Deprecated(
|
||||
'Use inactiveTrackColor instead. '
|
||||
'This feature was deprecated after v3.24.0-0.2.pre.'
|
||||
)
|
||||
Color? get trackColor => inactiveTrackColor;
|
||||
|
||||
/// The color to use for the track when the switch is off.
|
||||
///
|
||||
/// Defaults to [CupertinoColors.secondarySystemFill] when null.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [activeTrackColor], the color to use for the track when the switch is on.
|
||||
final Color? inactiveTrackColor;
|
||||
|
||||
/// The color to use for the thumb when the switch is on.
|
||||
///
|
||||
@ -483,9 +525,9 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
|
||||
WidgetStateProperty<Color?> get _widgetTrackColor {
|
||||
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return widget.activeColor;
|
||||
return widget.activeTrackColor;
|
||||
}
|
||||
return widget.trackColor;
|
||||
return widget.inactiveTrackColor;
|
||||
});
|
||||
}
|
||||
|
||||
@ -584,7 +626,7 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
|
||||
final CupertinoThemeData theme = CupertinoTheme.of(context);
|
||||
|
||||
final Color activeColor = CupertinoDynamicColor.resolve(
|
||||
widget.activeColor
|
||||
widget.activeTrackColor
|
||||
?? ((widget.applyTheme ?? theme.applyThemeToAll) ? theme.primaryColor : null)
|
||||
?? CupertinoColors.systemGreen,
|
||||
context,
|
||||
|
@ -1867,6 +1867,50 @@ void main() {
|
||||
imageProvider2.complete();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Switch uses inactive track color when set', (WidgetTester tester) async {
|
||||
const Color inactiveTrackColor = Color(0xFF00FF00);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: CupertinoSwitch(
|
||||
value: false,
|
||||
inactiveTrackColor: inactiveTrackColor,
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onChanged: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CupertinoSwitch), findsOneWidget);
|
||||
expect(tester.widget<CupertinoSwitch>(find.byType(CupertinoSwitch)).inactiveTrackColor, inactiveTrackColor);
|
||||
expect(find.byType(CupertinoSwitch), paints..rrect(color: inactiveTrackColor));
|
||||
});
|
||||
|
||||
testWidgets('Switch uses active track color when set', (WidgetTester tester) async {
|
||||
const Color activeTrackColor = Color(0xFF00FF00);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: CupertinoSwitch(
|
||||
value: true,
|
||||
activeTrackColor: activeTrackColor,
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onChanged: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(CupertinoSwitch), findsOneWidget);
|
||||
expect(tester.widget<CupertinoSwitch>(find.byType(CupertinoSwitch)).activeTrackColor, activeTrackColor);
|
||||
expect(find.byType(CupertinoSwitch), paints..rrect(color: activeTrackColor));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -248,4 +248,20 @@ void main() {
|
||||
|
||||
final PlatformMenuBar platformMenuBar = PlatformMenuBar(menus: <PlatformMenuItem>[], body: const SizedBox());
|
||||
final Widget bodyValue = platformMenuBar.body;
|
||||
|
||||
// Changes made in https://github.com/flutter/flutter/pull/151367
|
||||
final cupertinoSwitch = CupertinoSwitch(
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
activeColor: Colors.red,
|
||||
);
|
||||
Color? activeTrackColor = cupertinoSwitch.activeColor;
|
||||
|
||||
// Changes made in https://github.com/flutter/flutter/pull/151367
|
||||
final cupertinoSwitch = CupertinoSwitch(
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
trackColor: Colors.red,
|
||||
);
|
||||
Color? inactiveTrackColor = cupertinoSwitch.trackColor;
|
||||
}
|
||||
|
@ -248,4 +248,20 @@ void main() {
|
||||
|
||||
final PlatformMenuBar platformMenuBar = PlatformMenuBar(menus: <PlatformMenuItem>[], child: const SizedBox());
|
||||
final Widget bodyValue = platformMenuBar.child;
|
||||
|
||||
// Changes made in https://github.com/flutter/flutter/pull/151367
|
||||
final cupertinoSwitch = CupertinoSwitch(
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
activeTrackColor: Colors.red,
|
||||
);
|
||||
Color? activeTrackColor = cupertinoSwitch.activeTrackColor;
|
||||
|
||||
// Changes made in https://github.com/flutter/flutter/pull/151367
|
||||
final cupertinoSwitch = CupertinoSwitch(
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
inactiveTrackColor: Colors.red,
|
||||
);
|
||||
Color? inactiveTrackColor = cupertinoSwitch.inactiveTrackColor;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user