iconButtonTheme static method
IconButtonThemeData
iconButtonTheme({
- required ColorScheme colorScheme,
- bool? useTintedInteraction,
- bool? useTintedDisable,
An opinionated IconButtonThemeData.
Current only used to set tinted interaction and disable style on IconButtonThemeData when these feature are opted in on in FCS.
Implementation
static IconButtonThemeData iconButtonTheme({
/// Typically the same `ColorScheme` that is also used for your `ThemeData`.
required final ColorScheme colorScheme,
/// Defines if the theme uses tinted interaction effects.
///
/// If undefined, defaults to false.
final bool? useTintedInteraction,
/// Defines if the theme uses tinted disabled color.
///
/// If undefined, defaults to false.
final bool? useTintedDisable,
}) {
final bool tintInteract = useTintedInteraction ?? false;
final bool tintDisable = useTintedDisable ?? false;
// Due to issue:
// https://github.com/flutter/flutter/pull/121884#issuecomment-1458505977
// Only supports default colors for now, the colors below are only used
// for default color matching tinted ink effects.
// Get right foreground on color for background, defaults to primary.
final Color foreground = schemeColor(SchemeColor.primary, colorScheme);
// Get background color, defaults to onPrimary.
final Color background = schemeColorPair(SchemeColor.primary, colorScheme);
// Using these tinted overlay variable in all themes for ease of
// reasoning and duplication.
final Color overlay = background;
final Color tint = foreground;
final double factor = _tintAlphaFactor(tint, colorScheme.brightness, false);
// TODO(rydmike): Conditional tintInteract and tintDisabled due to issue.
// See https://github.com/flutter/flutter/issues/123829
return tintInteract || tintDisable
? IconButtonThemeData(
style: ButtonStyle(
// TODO(rydmike): Add tinted disable support when doable in SDK.
// Due to above mentioned issue backgroundColor cannot be added yet
// without destroying the different styles.
// backgroundColor:
// MaterialStateProperty.resolveWith((Set<MaterialState> states) {
// if (states.contains(MaterialState.disabled)) {
// if (tintDisable) {
// return tintedDisable(colorScheme.onSurface, tint)
// .withAlpha(kAlphaVeryLowDisabled);
// }
// if (states.contains(MaterialState.selected)) {
// return colorScheme.onSurface.withOpacity(0.12);
// }
// return Colors.transparent;
// }
// if (states.contains(MaterialState.selected)) {
// return colorScheme.inverseSurface;
// }
// return Colors.transparent;
// }),
foregroundColor:
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
// We can do a tinted foreground color when requested, since it
// is the same for all variants by default as well.
if (states.contains(MaterialState.disabled)) {
if (tintDisable) {
return tintedDisable(colorScheme.onSurface, tint);
}
// return colorScheme.onSurface.withOpacity(0.38);
}
// if (states.contains(MaterialState.selected)) {
// return colorScheme.onInverseSurface;
// }
// return colorScheme.onSurfaceVariant;
return null; // Gets us default for foregroundColor
}),
overlayColor: tintInteract
? MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
if (states.contains(MaterialState.pressed)) {
if (tintInteract) {
return tintedPressed(overlay, tint, factor);
}
// TODO(rydmike): Add option when Flutter issue fixed.
// return
// colorScheme.onSurface.withAlpha(kAlphaPressed);
}
if (states.contains(MaterialState.hovered)) {
if (tintInteract) {
return tintedHovered(overlay, tint, factor);
}
// TODO(rydmike): Add option when Flutter issue fixed.
// return foreground.withAlpha(kAlphaHovered);
}
if (states.contains(MaterialState.focused)) {
if (tintInteract) {
return tintedFocused(overlay, tint, factor);
}
// TODO(rydmike): Add option when Flutter issue fixed.
// return foreground.withAlpha(kAlphaFocused);
}
return Colors.transparent;
}
if (states.contains(MaterialState.pressed)) {
if (tintInteract) {
return tintedPressed(overlay, tint, factor);
}
// TODO(rydmike): Add option when Flutter issue fixed.
// return foreground.withAlpha(kAlphaPressed);
}
if (states.contains(MaterialState.hovered)) {
if (tintInteract) {
return tintedHovered(overlay, tint, factor);
}
// TODO(rydmike): Add option when Flutter issue fixed.
// return colorScheme.onSurface.withAlpha(kAlphaHovered);
}
if (states.contains(MaterialState.focused)) {
if (tintInteract) {
return tintedFocused(overlay, tint, factor);
}
// TODO(rydmike): Add option when Flutter issue fixed.
// return colorScheme.onSurface.withAlpha(kAlphaFocused);
}
return Colors.transparent;
})
: null, // Gets us default for overlayColor.
))
: const IconButtonThemeData();
}