Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5282952

Browse files
authored
Deprecate toggleableActiveColor (#97972)
1 parent c6bb9cc commit 5282952

18 files changed

+897
-135
lines changed

dev/integration_tests/flutter_gallery/lib/gallery/themes.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ ThemeData _buildDarkTheme() {
3030
primaryColorDark: const Color(0xFF0050a0),
3131
primaryColorLight: secondaryColor,
3232
indicatorColor: Colors.white,
33-
toggleableActiveColor: const Color(0xFF6997DF),
3433
canvasColor: const Color(0xFF202124),
3534
scaffoldBackgroundColor: const Color(0xFF202124),
3635
backgroundColor: const Color(0xFF202124),
@@ -54,7 +53,6 @@ ThemeData _buildLightTheme() {
5453
colorScheme: colorScheme,
5554
primaryColor: primaryColor,
5655
indicatorColor: Colors.white,
57-
toggleableActiveColor: const Color(0xFF1E88E5),
5856
splashColor: Colors.white24,
5957
splashFactory: InkRipple.splashFactory,
6058
canvasColor: Colors.white,

packages/flutter/lib/fix_data.yaml

Lines changed: 432 additions & 0 deletions
Large diffs are not rendered by default.

packages/flutter/lib/src/material/checkbox.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Checkbox extends StatefulWidget {
147147

148148
/// The color to use when this checkbox is checked.
149149
///
150-
/// Defaults to [ThemeData.toggleableActiveColor].
150+
/// Defaults to [ColorScheme.secondary].
151151
///
152152
/// If [fillColor] returns a non-null color in the [MaterialState.selected]
153153
/// state, it will be used instead of this color.
@@ -185,7 +185,7 @@ class Checkbox extends StatefulWidget {
185185
/// If null, then the value of [activeColor] is used in the selected
186186
/// state. If that is also null, the value of [CheckboxThemeData.fillColor]
187187
/// is used. If that is also null, then [ThemeData.disabledColor] is used in
188-
/// the disabled state, [ThemeData.toggleableActiveColor] is used in the
188+
/// the disabled state, [ColorScheme.secondary] is used in the
189189
/// selected state, and [ThemeData.unselectedWidgetColor] is used in the
190190
/// default state.
191191
final MaterialStateProperty<Color?>? fillColor;
@@ -272,7 +272,7 @@ class Checkbox extends StatefulWidget {
272272
/// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the
273273
/// pressed, focused and hovered state. If that is also null,
274274
/// the value of [CheckboxThemeData.overlayColor] is used. If that is
275-
/// also null, then the value of [ThemeData.toggleableActiveColor] with alpha
275+
/// also null, then the value of [ColorScheme.secondary] with alpha
276276
/// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor]
277277
/// is used in the pressed, focused and hovered state.
278278
final MaterialStateProperty<Color?>? overlayColor;
@@ -385,7 +385,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin, Togg
385385
return themeData.disabledColor;
386386
}
387387
if (states.contains(MaterialState.selected)) {
388-
return themeData.toggleableActiveColor;
388+
return themeData.colorScheme.secondary;
389389
}
390390
return themeData.unselectedWidgetColor;
391391
});

packages/flutter/lib/src/material/checkbox_list_tile.dart

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import 'package:flutter/widgets.dart';
66

77
import 'checkbox.dart';
8+
import 'checkbox_theme.dart';
89
import 'list_tile.dart';
910
import 'list_tile_theme.dart';
11+
import 'material_state.dart';
1012
import 'theme.dart';
1113
import 'theme_data.dart';
1214

@@ -29,7 +31,7 @@ import 'theme_data.dart';
2931
///
3032
/// The [selected] property on this widget is similar to the [ListTile.selected]
3133
/// property. This tile's [activeColor] is used for the selected item's text color, or
32-
/// the theme's [ThemeData.toggleableActiveColor] if [activeColor] is null.
34+
/// the theme's [CheckboxThemeData.overlayColor] if [activeColor] is null.
3335
///
3436
/// This widget does not coordinate the [selected] state and the [value] state; to have the list tile
3537
/// appear selected when the checkbox is checked, pass the same value to both.
@@ -372,28 +374,34 @@ class CheckboxListTile extends StatelessWidget {
372374
trailing = control;
373375
break;
374376
}
377+
final ThemeData theme = Theme.of(context);
378+
final CheckboxThemeData checkboxTheme = CheckboxTheme.of(context);
379+
final Set<MaterialState> states = <MaterialState>{
380+
if (selected) MaterialState.selected,
381+
};
382+
final Color effectiveActiveColor = activeColor
383+
?? checkboxTheme.fillColor?.resolve(states)
384+
?? theme.colorScheme.secondary;
375385
return MergeSemantics(
376-
child: ListTileTheme.merge(
377-
selectedColor: activeColor ?? Theme.of(context).toggleableActiveColor,
378-
child: ListTile(
379-
leading: leading,
380-
title: title,
381-
subtitle: subtitle,
382-
trailing: trailing,
383-
isThreeLine: isThreeLine,
384-
dense: dense,
385-
enabled: enabled ?? onChanged != null,
386-
onTap: onChanged != null ? _handleValueChange : null,
387-
selected: selected,
388-
autofocus: autofocus,
389-
contentPadding: contentPadding,
390-
shape: shape,
391-
selectedTileColor: selectedTileColor,
392-
tileColor: tileColor,
393-
visualDensity: visualDensity,
394-
focusNode: focusNode,
395-
enableFeedback: enableFeedback,
396-
),
386+
child: ListTile(
387+
selectedColor: effectiveActiveColor,
388+
leading: leading,
389+
title: title,
390+
subtitle: subtitle,
391+
trailing: trailing,
392+
isThreeLine: isThreeLine,
393+
dense: dense,
394+
enabled: enabled ?? onChanged != null,
395+
onTap: onChanged != null ? _handleValueChange : null,
396+
selected: selected,
397+
autofocus: autofocus,
398+
contentPadding: contentPadding,
399+
shape: shape,
400+
selectedTileColor: selectedTileColor,
401+
tileColor: tileColor,
402+
visualDensity: visualDensity,
403+
focusNode: focusNode,
404+
enableFeedback: enableFeedback,
397405
),
398406
);
399407
}

packages/flutter/lib/src/material/radio.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class Radio<T> extends StatefulWidget {
175175

176176
/// The color to use when this radio button is selected.
177177
///
178-
/// Defaults to [ThemeData.toggleableActiveColor].
178+
/// Defaults to [ColorScheme.secondary].
179179
///
180180
/// If [fillColor] returns a non-null color in the [MaterialState.selected]
181181
/// state, it will be used instead of this color.
@@ -214,7 +214,7 @@ class Radio<T> extends StatefulWidget {
214214
/// If null, then the value of [activeColor] is used in the selected state. If
215215
/// that is also null, then the value of [RadioThemeData.fillColor] is used.
216216
/// If that is also null, then [ThemeData.disabledColor] is used in
217-
/// the disabled state, [ThemeData.toggleableActiveColor] is used in the
217+
/// the disabled state, [ColorScheme.secondary] is used in the
218218
/// selected state, and [ThemeData.unselectedWidgetColor] is used in the
219219
/// default state.
220220
final MaterialStateProperty<Color?>? fillColor;
@@ -281,7 +281,7 @@ class Radio<T> extends StatefulWidget {
281281
/// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the
282282
/// pressed, focused and hovered state. If that is also null,
283283
/// the value of [RadioThemeData.overlayColor] is used. If that is also null,
284-
/// then the value of [ThemeData.toggleableActiveColor] with alpha
284+
/// then the value of [ColorScheme.secondary] with alpha
285285
/// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor]
286286
/// is used in the pressed, focused and hovered state.
287287
final MaterialStateProperty<Color?>? overlayColor;
@@ -361,7 +361,7 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin, Togg
361361
return themeData.disabledColor;
362362
}
363363
if (states.contains(MaterialState.selected)) {
364-
return themeData.toggleableActiveColor;
364+
return themeData.colorScheme.secondary;
365365
}
366366
return themeData.unselectedWidgetColor;
367367
});

packages/flutter/lib/src/material/radio_list_tile.dart

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import 'package:flutter/widgets.dart';
66

77
import 'list_tile.dart';
88
import 'list_tile_theme.dart';
9+
import 'material_state.dart';
910
import 'radio.dart';
11+
import 'radio_theme.dart';
1012
import 'theme.dart';
1113
import 'theme_data.dart';
1214

@@ -346,36 +348,42 @@ class RadioListTile<T> extends StatelessWidget {
346348
trailing = control;
347349
break;
348350
}
351+
final ThemeData theme = Theme.of(context);
352+
final RadioThemeData radioThemeData = RadioTheme.of(context);
353+
final Set<MaterialState> states = <MaterialState>{
354+
if (selected) MaterialState.selected,
355+
};
356+
final Color effectiveActiveColor = activeColor
357+
?? radioThemeData.fillColor?.resolve(states)
358+
?? theme.colorScheme.secondary;
349359
return MergeSemantics(
350-
child: ListTileTheme.merge(
351-
selectedColor: activeColor ?? Theme.of(context).toggleableActiveColor,
352-
child: ListTile(
353-
leading: leading,
354-
title: title,
355-
subtitle: subtitle,
356-
trailing: trailing,
357-
isThreeLine: isThreeLine,
358-
dense: dense,
359-
enabled: onChanged != null,
360-
shape: shape,
361-
tileColor: tileColor,
362-
selectedTileColor: selectedTileColor,
363-
onTap: onChanged != null ? () {
364-
if (toggleable && checked) {
365-
onChanged!(null);
366-
return;
367-
}
368-
if (!checked) {
369-
onChanged!(value);
370-
}
371-
} : null,
372-
selected: selected,
373-
autofocus: autofocus,
374-
contentPadding: contentPadding,
375-
visualDensity: visualDensity,
376-
focusNode: focusNode,
377-
enableFeedback: enableFeedback,
378-
),
360+
child: ListTile(
361+
selectedColor: effectiveActiveColor,
362+
leading: leading,
363+
title: title,
364+
subtitle: subtitle,
365+
trailing: trailing,
366+
isThreeLine: isThreeLine,
367+
dense: dense,
368+
enabled: onChanged != null,
369+
shape: shape,
370+
tileColor: tileColor,
371+
selectedTileColor: selectedTileColor,
372+
onTap: onChanged != null ? () {
373+
if (toggleable && checked) {
374+
onChanged!(null);
375+
return;
376+
}
377+
if (!checked) {
378+
onChanged!(value);
379+
}
380+
} : null,
381+
selected: selected,
382+
autofocus: autofocus,
383+
contentPadding: contentPadding,
384+
visualDensity: visualDensity,
385+
focusNode: focusNode,
386+
enableFeedback: enableFeedback,
379387
),
380388
);
381389
}

packages/flutter/lib/src/material/switch.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ class Switch extends StatelessWidget {
182182

183183
/// The color to use when this switch is on.
184184
///
185-
/// Defaults to [ThemeData.toggleableActiveColor].
185+
/// Defaults to [ColorScheme.secondary].
186186
///
187187
/// If [thumbColor] returns a non-null color in the [MaterialState.selected]
188188
/// state, it will be used instead of this color.
189189
final Color? activeColor;
190190

191191
/// The color to use on the track when this switch is on.
192192
///
193-
/// Defaults to [ThemeData.toggleableActiveColor] with the opacity set at 50%.
193+
/// Defaults to [ColorScheme.secondary] with the opacity set at 50%.
194194
///
195195
/// Ignored if this switch is created with [Switch.adaptive].
196196
///
@@ -273,7 +273,7 @@ class Switch extends StatelessWidget {
273273
/// | State | Light theme | Dark theme |
274274
/// |----------|-----------------------------------|-----------------------------------|
275275
/// | Default | `Colors.grey.shade50` | `Colors.grey.shade400` |
276-
/// | Selected | [ThemeData.toggleableActiveColor] | [ThemeData.toggleableActiveColor] |
276+
/// | Selected | [ColorScheme.secondary] | [ColorScheme.secondary] |
277277
/// | Disabled | `Colors.grey.shade400` | `Colors.grey.shade800` |
278278
final MaterialStateProperty<Color?>? thumbColor;
279279

@@ -393,7 +393,7 @@ class Switch extends StatelessWidget {
393393
/// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the
394394
/// pressed, focused and hovered state. If that is also null,
395395
/// the value of [SwitchThemeData.overlayColor] is used. If that is
396-
/// also null, then the value of [ThemeData.toggleableActiveColor] with alpha
396+
/// also null, then the value of [ColorScheme.secondary] with alpha
397397
/// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor]
398398
/// is used in the pressed, focused and hovered state.
399399
final MaterialStateProperty<Color?>? overlayColor;
@@ -614,7 +614,7 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta
614614
return isDark ? Colors.grey.shade800 : Colors.grey.shade400;
615615
}
616616
if (states.contains(MaterialState.selected)) {
617-
return theme.toggleableActiveColor;
617+
return theme.colorScheme.secondary;
618618
}
619619
return isDark ? Colors.grey.shade400 : Colors.grey.shade50;
620620
});

packages/flutter/lib/src/material/switch_list_tile.dart

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import 'package:flutter/widgets.dart';
66

77
import 'list_tile.dart';
88
import 'list_tile_theme.dart';
9+
import 'material_state.dart';
910
import 'switch.dart';
11+
import 'switch_theme.dart';
1012
import 'theme.dart';
1113
import 'theme_data.dart';
1214

@@ -37,7 +39,7 @@ enum _SwitchListTileType { material, adaptive }
3739
///
3840
/// The [selected] property on this widget is similar to the [ListTile.selected]
3941
/// property. This tile's [activeColor] is used for the selected item's text color, or
40-
/// the theme's [ThemeData.toggleableActiveColor] if [activeColor] is null.
42+
/// the theme's [SwitchThemeData.overlayColor] if [activeColor] is null.
4143
///
4244
/// This widget does not coordinate the [selected] state and the
4345
/// [value]; to have the list tile appear selected when the
@@ -423,29 +425,35 @@ class SwitchListTile extends StatelessWidget {
423425
break;
424426
}
425427

428+
final ThemeData theme = Theme.of(context);
429+
final SwitchThemeData switchTheme = SwitchTheme.of(context);
430+
final Set<MaterialState> states = <MaterialState>{
431+
if (selected) MaterialState.selected,
432+
};
433+
final Color effectiveActiveColor = activeColor
434+
?? switchTheme.thumbColor?.resolve(states)
435+
?? theme.colorScheme.secondary;
426436
return MergeSemantics(
427-
child: ListTileTheme.merge(
428-
selectedColor: activeColor ?? Theme.of(context).toggleableActiveColor,
429-
child: ListTile(
430-
leading: leading,
431-
title: title,
432-
subtitle: subtitle,
433-
trailing: trailing,
434-
isThreeLine: isThreeLine,
435-
dense: dense,
436-
contentPadding: contentPadding,
437-
enabled: onChanged != null,
438-
onTap: onChanged != null ? () { onChanged!(!value); } : null,
439-
selected: selected,
440-
selectedTileColor: selectedTileColor,
441-
autofocus: autofocus,
442-
shape: shape,
443-
tileColor: tileColor,
444-
visualDensity: visualDensity,
445-
focusNode: focusNode,
446-
enableFeedback: enableFeedback,
447-
hoverColor: hoverColor,
448-
),
437+
child: ListTile(
438+
selectedColor: effectiveActiveColor,
439+
leading: leading,
440+
title: title,
441+
subtitle: subtitle,
442+
trailing: trailing,
443+
isThreeLine: isThreeLine,
444+
dense: dense,
445+
contentPadding: contentPadding,
446+
enabled: onChanged != null,
447+
onTap: onChanged != null ? () { onChanged!(!value); } : null,
448+
selected: selected,
449+
selectedTileColor: selectedTileColor,
450+
autofocus: autofocus,
451+
shape: shape,
452+
tileColor: tileColor,
453+
visualDensity: visualDensity,
454+
focusNode: focusNode,
455+
enableFeedback: enableFeedback,
456+
hoverColor: hoverColor,
449457
),
450458
);
451459
}

0 commit comments

Comments
 (0)