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

Skip to content

Deprecate toggleableActiveColor #97972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions dev/integration_tests/flutter_gallery/lib/gallery/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ThemeData _buildDarkTheme() {
primaryColorDark: const Color(0xFF0050a0),
primaryColorLight: secondaryColor,
indicatorColor: Colors.white,
toggleableActiveColor: const Color(0xFF6997DF),
canvasColor: const Color(0xFF202124),
scaffoldBackgroundColor: const Color(0xFF202124),
backgroundColor: const Color(0xFF202124),
Expand All @@ -54,7 +53,6 @@ ThemeData _buildLightTheme() {
colorScheme: colorScheme,
primaryColor: primaryColor,
indicatorColor: Colors.white,
toggleableActiveColor: const Color(0xFF1E88E5),
splashColor: Colors.white24,
splashFactory: InkRipple.splashFactory,
canvasColor: Colors.white,
Expand Down
432 changes: 432 additions & 0 deletions packages/flutter/lib/fix_data.yaml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/flutter/lib/src/material/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Checkbox extends StatefulWidget {

/// The color to use when this checkbox is checked.
///
/// Defaults to [ThemeData.toggleableActiveColor].
/// Defaults to [ColorScheme.secondary].
///
/// If [fillColor] returns a non-null color in the [MaterialState.selected]
/// state, it will be used instead of this color.
Expand Down Expand Up @@ -185,7 +185,7 @@ class Checkbox extends StatefulWidget {
/// If null, then the value of [activeColor] is used in the selected
/// state. If that is also null, the value of [CheckboxThemeData.fillColor]
/// is used. If that is also null, then [ThemeData.disabledColor] is used in
/// the disabled state, [ThemeData.toggleableActiveColor] is used in the
/// the disabled state, [ColorScheme.secondary] is used in the
/// selected state, and [ThemeData.unselectedWidgetColor] is used in the
/// default state.
final MaterialStateProperty<Color?>? fillColor;
Expand Down Expand Up @@ -272,7 +272,7 @@ class Checkbox extends StatefulWidget {
/// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the
/// pressed, focused and hovered state. If that is also null,
/// the value of [CheckboxThemeData.overlayColor] is used. If that is
/// also null, then the value of [ThemeData.toggleableActiveColor] with alpha
/// also null, then the value of [ColorScheme.secondary] with alpha
/// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor]
/// is used in the pressed, focused and hovered state.
final MaterialStateProperty<Color?>? overlayColor;
Expand Down Expand Up @@ -385,7 +385,7 @@ class _CheckboxState extends State<Checkbox> with TickerProviderStateMixin, Togg
return themeData.disabledColor;
}
if (states.contains(MaterialState.selected)) {
return themeData.toggleableActiveColor;
return themeData.colorScheme.secondary;
}
return themeData.unselectedWidgetColor;
});
Expand Down
52 changes: 30 additions & 22 deletions packages/flutter/lib/src/material/checkbox_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import 'package:flutter/widgets.dart';

import 'checkbox.dart';
import 'checkbox_theme.dart';
import 'list_tile.dart';
import 'list_tile_theme.dart';
import 'material_state.dart';
import 'theme.dart';
import 'theme_data.dart';

Expand All @@ -29,7 +31,7 @@ import 'theme_data.dart';
///
/// The [selected] property on this widget is similar to the [ListTile.selected]
/// property. This tile's [activeColor] is used for the selected item's text color, or
/// the theme's [ThemeData.toggleableActiveColor] if [activeColor] is null.
/// the theme's [CheckboxThemeData.overlayColor] if [activeColor] is null.
///
/// This widget does not coordinate the [selected] state and the [value] state; to have the list tile
/// appear selected when the checkbox is checked, pass the same value to both.
Expand Down Expand Up @@ -372,28 +374,34 @@ class CheckboxListTile extends StatelessWidget {
trailing = control;
break;
}
final ThemeData theme = Theme.of(context);
final CheckboxThemeData checkboxTheme = CheckboxTheme.of(context);
final Set<MaterialState> states = <MaterialState>{
if (selected) MaterialState.selected,
};
final Color effectiveActiveColor = activeColor
?? checkboxTheme.fillColor?.resolve(states)
?? theme.colorScheme.secondary;
return MergeSemantics(
child: ListTileTheme.merge(
selectedColor: activeColor ?? Theme.of(context).toggleableActiveColor,
child: ListTile(
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
isThreeLine: isThreeLine,
dense: dense,
enabled: enabled ?? onChanged != null,
onTap: onChanged != null ? _handleValueChange : null,
selected: selected,
autofocus: autofocus,
contentPadding: contentPadding,
shape: shape,
selectedTileColor: selectedTileColor,
tileColor: tileColor,
visualDensity: visualDensity,
focusNode: focusNode,
enableFeedback: enableFeedback,
),
child: ListTile(
selectedColor: effectiveActiveColor,
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
isThreeLine: isThreeLine,
dense: dense,
enabled: enabled ?? onChanged != null,
onTap: onChanged != null ? _handleValueChange : null,
selected: selected,
autofocus: autofocus,
contentPadding: contentPadding,
shape: shape,
selectedTileColor: selectedTileColor,
tileColor: tileColor,
visualDensity: visualDensity,
focusNode: focusNode,
enableFeedback: enableFeedback,
),
);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter/lib/src/material/radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Radio<T> extends StatefulWidget {

/// The color to use when this radio button is selected.
///
/// Defaults to [ThemeData.toggleableActiveColor].
/// Defaults to [ColorScheme.secondary].
///
/// If [fillColor] returns a non-null color in the [MaterialState.selected]
/// state, it will be used instead of this color.
Expand Down Expand Up @@ -214,7 +214,7 @@ class Radio<T> extends StatefulWidget {
/// If null, then the value of [activeColor] is used in the selected state. If
/// that is also null, then the value of [RadioThemeData.fillColor] is used.
/// If that is also null, then [ThemeData.disabledColor] is used in
/// the disabled state, [ThemeData.toggleableActiveColor] is used in the
/// the disabled state, [ColorScheme.secondary] is used in the
/// selected state, and [ThemeData.unselectedWidgetColor] is used in the
/// default state.
final MaterialStateProperty<Color?>? fillColor;
Expand Down Expand Up @@ -281,7 +281,7 @@ class Radio<T> extends StatefulWidget {
/// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the
/// pressed, focused and hovered state. If that is also null,
/// the value of [RadioThemeData.overlayColor] is used. If that is also null,
/// then the value of [ThemeData.toggleableActiveColor] with alpha
/// then the value of [ColorScheme.secondary] with alpha
/// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor]
/// is used in the pressed, focused and hovered state.
final MaterialStateProperty<Color?>? overlayColor;
Expand Down Expand Up @@ -361,7 +361,7 @@ class _RadioState<T> extends State<Radio<T>> with TickerProviderStateMixin, Togg
return themeData.disabledColor;
}
if (states.contains(MaterialState.selected)) {
return themeData.toggleableActiveColor;
return themeData.colorScheme.secondary;
}
return themeData.unselectedWidgetColor;
});
Expand Down
66 changes: 37 additions & 29 deletions packages/flutter/lib/src/material/radio_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:flutter/widgets.dart';

import 'list_tile.dart';
import 'list_tile_theme.dart';
import 'material_state.dart';
import 'radio.dart';
import 'radio_theme.dart';
import 'theme.dart';
import 'theme_data.dart';

Expand Down Expand Up @@ -346,36 +348,42 @@ class RadioListTile<T> extends StatelessWidget {
trailing = control;
break;
}
final ThemeData theme = Theme.of(context);
final RadioThemeData radioThemeData = RadioTheme.of(context);
final Set<MaterialState> states = <MaterialState>{
if (selected) MaterialState.selected,
};
final Color effectiveActiveColor = activeColor
?? radioThemeData.fillColor?.resolve(states)
?? theme.colorScheme.secondary;
return MergeSemantics(
child: ListTileTheme.merge(
selectedColor: activeColor ?? Theme.of(context).toggleableActiveColor,
child: ListTile(
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
isThreeLine: isThreeLine,
dense: dense,
enabled: onChanged != null,
shape: shape,
tileColor: tileColor,
selectedTileColor: selectedTileColor,
onTap: onChanged != null ? () {
if (toggleable && checked) {
onChanged!(null);
return;
}
if (!checked) {
onChanged!(value);
}
} : null,
selected: selected,
autofocus: autofocus,
contentPadding: contentPadding,
visualDensity: visualDensity,
focusNode: focusNode,
enableFeedback: enableFeedback,
),
child: ListTile(
selectedColor: effectiveActiveColor,
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
isThreeLine: isThreeLine,
dense: dense,
enabled: onChanged != null,
shape: shape,
tileColor: tileColor,
selectedTileColor: selectedTileColor,
onTap: onChanged != null ? () {
if (toggleable && checked) {
onChanged!(null);
return;
}
if (!checked) {
onChanged!(value);
}
} : null,
selected: selected,
autofocus: autofocus,
contentPadding: contentPadding,
visualDensity: visualDensity,
focusNode: focusNode,
enableFeedback: enableFeedback,
),
);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/flutter/lib/src/material/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ class Switch extends StatelessWidget {

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

/// The color to use on the track when this switch is on.
///
/// Defaults to [ThemeData.toggleableActiveColor] with the opacity set at 50%.
/// Defaults to [ColorScheme.secondary] with the opacity set at 50%.
///
/// Ignored if this switch is created with [Switch.adaptive].
///
Expand Down Expand Up @@ -273,7 +273,7 @@ class Switch extends StatelessWidget {
/// | State | Light theme | Dark theme |
/// |----------|-----------------------------------|-----------------------------------|
/// | Default | `Colors.grey.shade50` | `Colors.grey.shade400` |
/// | Selected | [ThemeData.toggleableActiveColor] | [ThemeData.toggleableActiveColor] |
/// | Selected | [ColorScheme.secondary] | [ColorScheme.secondary] |
/// | Disabled | `Colors.grey.shade400` | `Colors.grey.shade800` |
final MaterialStateProperty<Color?>? thumbColor;

Expand Down Expand Up @@ -393,7 +393,7 @@ class Switch extends StatelessWidget {
/// [kRadialReactionAlpha], [focusColor] and [hoverColor] is used in the
/// pressed, focused and hovered state. If that is also null,
/// the value of [SwitchThemeData.overlayColor] is used. If that is
/// also null, then the value of [ThemeData.toggleableActiveColor] with alpha
/// also null, then the value of [ColorScheme.secondary] with alpha
/// [kRadialReactionAlpha], [ThemeData.focusColor] and [ThemeData.hoverColor]
/// is used in the pressed, focused and hovered state.
final MaterialStateProperty<Color?>? overlayColor;
Expand Down Expand Up @@ -614,7 +614,7 @@ class _MaterialSwitchState extends State<_MaterialSwitch> with TickerProviderSta
return isDark ? Colors.grey.shade800 : Colors.grey.shade400;
}
if (states.contains(MaterialState.selected)) {
return theme.toggleableActiveColor;
return theme.colorScheme.secondary;
}
return isDark ? Colors.grey.shade400 : Colors.grey.shade50;
});
Expand Down
54 changes: 31 additions & 23 deletions packages/flutter/lib/src/material/switch_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:flutter/widgets.dart';

import 'list_tile.dart';
import 'list_tile_theme.dart';
import 'material_state.dart';
import 'switch.dart';
import 'switch_theme.dart';
import 'theme.dart';
import 'theme_data.dart';

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

final ThemeData theme = Theme.of(context);
final SwitchThemeData switchTheme = SwitchTheme.of(context);
final Set<MaterialState> states = <MaterialState>{
if (selected) MaterialState.selected,
};
final Color effectiveActiveColor = activeColor
?? switchTheme.thumbColor?.resolve(states)
?? theme.colorScheme.secondary;
return MergeSemantics(
child: ListTileTheme.merge(
selectedColor: activeColor ?? Theme.of(context).toggleableActiveColor,
child: ListTile(
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
isThreeLine: isThreeLine,
dense: dense,
contentPadding: contentPadding,
enabled: onChanged != null,
onTap: onChanged != null ? () { onChanged!(!value); } : null,
selected: selected,
selectedTileColor: selectedTileColor,
autofocus: autofocus,
shape: shape,
tileColor: tileColor,
visualDensity: visualDensity,
focusNode: focusNode,
enableFeedback: enableFeedback,
hoverColor: hoverColor,
),
child: ListTile(
selectedColor: effectiveActiveColor,
leading: leading,
title: title,
subtitle: subtitle,
trailing: trailing,
isThreeLine: isThreeLine,
dense: dense,
contentPadding: contentPadding,
enabled: onChanged != null,
onTap: onChanged != null ? () { onChanged!(!value); } : null,
selected: selected,
selectedTileColor: selectedTileColor,
autofocus: autofocus,
shape: shape,
tileColor: tileColor,
visualDensity: visualDensity,
focusNode: focusNode,
enableFeedback: enableFeedback,
hoverColor: hoverColor,
),
);
}
Expand Down
Loading