Add IconButton.filled, IconButton.filledTonal, IconButton.outlined (#121884)
This commit is contained in:
@@ -30,6 +30,8 @@ import 'tooltip.dart';
|
||||
// See: <https://material.io/design/usability/accessibility.html#layout-typography>.
|
||||
const double _kMinButtonSize = kMinInteractiveDimension;
|
||||
|
||||
enum _IconButtonVariant { standard, filled, filledTonal, outlined }
|
||||
|
||||
/// A Material Design icon button.
|
||||
///
|
||||
/// An icon button is a picture printed on a [Material] widget that reacts to
|
||||
@@ -115,8 +117,9 @@ const double _kMinButtonSize = kMinInteractiveDimension;
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// Material Design 3 introduced new types (standard and contained) of [IconButton]s.
|
||||
/// The default [IconButton] is the standard type, and contained icon buttons can be produced
|
||||
/// by configuring the [IconButton] widget's properties.
|
||||
/// The default [IconButton] is the standard type. To create a filled icon button,
|
||||
/// use [IconButton.filled]; to create a filled tonal icon button, use [IconButton.filledTonal];
|
||||
/// to create a outlined icon button, use [IconButton.outlined].
|
||||
///
|
||||
/// Material Design 3 also treats [IconButton]s as toggle buttons. In order
|
||||
/// to not break existing apps, the toggle feature can be optionally controlled
|
||||
@@ -198,7 +201,104 @@ class IconButton extends StatelessWidget {
|
||||
this.isSelected,
|
||||
this.selectedIcon,
|
||||
required this.icon,
|
||||
}) : assert(splashRadius == null || splashRadius > 0);
|
||||
}) : assert(splashRadius == null || splashRadius > 0),
|
||||
_variant = _IconButtonVariant.standard;
|
||||
|
||||
/// Create a filled variant of IconButton.
|
||||
///
|
||||
/// Filled icon buttons have higher visual impact and should be used for
|
||||
/// high emphasis actions, such as turning off a microphone or camera.
|
||||
const IconButton.filled({
|
||||
super.key,
|
||||
this.iconSize,
|
||||
this.visualDensity,
|
||||
this.padding,
|
||||
this.alignment,
|
||||
this.splashRadius,
|
||||
this.color,
|
||||
this.focusColor,
|
||||
this.hoverColor,
|
||||
this.highlightColor,
|
||||
this.splashColor,
|
||||
this.disabledColor,
|
||||
required this.onPressed,
|
||||
this.mouseCursor,
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.tooltip,
|
||||
this.enableFeedback,
|
||||
this.constraints,
|
||||
this.style,
|
||||
this.isSelected,
|
||||
this.selectedIcon,
|
||||
required this.icon,
|
||||
}) : assert(splashRadius == null || splashRadius > 0),
|
||||
_variant = _IconButtonVariant.filled;
|
||||
|
||||
/// Create a filled tonal variant of IconButton.
|
||||
///
|
||||
/// Filled tonal icon buttons are a middle ground between filled and outlined
|
||||
/// icon buttons. They’re useful in contexts where the button requires slightly
|
||||
/// more emphasis than an outline would give, such as a secondary action paired
|
||||
/// with a high emphasis action.
|
||||
const IconButton.filledTonal({
|
||||
super.key,
|
||||
this.iconSize,
|
||||
this.visualDensity,
|
||||
this.padding,
|
||||
this.alignment,
|
||||
this.splashRadius,
|
||||
this.color,
|
||||
this.focusColor,
|
||||
this.hoverColor,
|
||||
this.highlightColor,
|
||||
this.splashColor,
|
||||
this.disabledColor,
|
||||
required this.onPressed,
|
||||
this.mouseCursor,
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.tooltip,
|
||||
this.enableFeedback,
|
||||
this.constraints,
|
||||
this.style,
|
||||
this.isSelected,
|
||||
this.selectedIcon,
|
||||
required this.icon,
|
||||
}) : assert(splashRadius == null || splashRadius > 0),
|
||||
_variant = _IconButtonVariant.filledTonal;
|
||||
|
||||
/// Create a filled tonal variant of IconButton.
|
||||
///
|
||||
/// Outlined icon buttons are medium-emphasis buttons. They’re useful when an
|
||||
/// icon button needs more emphasis than a standard icon button but less than
|
||||
/// a filled or filled tonal icon button.
|
||||
const IconButton.outlined({
|
||||
super.key,
|
||||
this.iconSize,
|
||||
this.visualDensity,
|
||||
this.padding,
|
||||
this.alignment,
|
||||
this.splashRadius,
|
||||
this.color,
|
||||
this.focusColor,
|
||||
this.hoverColor,
|
||||
this.highlightColor,
|
||||
this.splashColor,
|
||||
this.disabledColor,
|
||||
required this.onPressed,
|
||||
this.mouseCursor,
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.tooltip,
|
||||
this.enableFeedback,
|
||||
this.constraints,
|
||||
this.style,
|
||||
this.isSelected,
|
||||
this.selectedIcon,
|
||||
required this.icon,
|
||||
}) : assert(splashRadius == null || splashRadius > 0),
|
||||
_variant = _IconButtonVariant.outlined;
|
||||
|
||||
/// The size of the icon inside the button.
|
||||
///
|
||||
@@ -465,6 +565,8 @@ class IconButton extends StatelessWidget {
|
||||
/// * [ImageIcon], for showing icons from [AssetImage]s or other [ImageProvider]s.
|
||||
final Widget? selectedIcon;
|
||||
|
||||
final _IconButtonVariant _variant;
|
||||
|
||||
/// A static convenience method that constructs an icon button
|
||||
/// [ButtonStyle] given simple values. This method is only used for Material 3.
|
||||
///
|
||||
@@ -615,6 +717,7 @@ class IconButton extends StatelessWidget {
|
||||
autofocus: autofocus,
|
||||
focusNode: focusNode,
|
||||
isSelected: isSelected,
|
||||
variant: _variant,
|
||||
child: iconButton,
|
||||
);
|
||||
}
|
||||
@@ -714,6 +817,7 @@ class _SelectableIconButton extends StatefulWidget {
|
||||
this.isSelected,
|
||||
this.style,
|
||||
this.focusNode,
|
||||
required this.variant,
|
||||
required this.autofocus,
|
||||
required this.onPressed,
|
||||
required this.child,
|
||||
@@ -722,6 +826,7 @@ class _SelectableIconButton extends StatefulWidget {
|
||||
final bool? isSelected;
|
||||
final ButtonStyle? style;
|
||||
final FocusNode? focusNode;
|
||||
final _IconButtonVariant variant;
|
||||
final bool autofocus;
|
||||
final VoidCallback? onPressed;
|
||||
final Widget child;
|
||||
@@ -761,12 +866,16 @@ class _SelectableIconButtonState extends State<_SelectableIconButton> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool toggleable = widget.isSelected != null;
|
||||
|
||||
return _IconButtonM3(
|
||||
statesController: statesController,
|
||||
style: widget.style,
|
||||
autofocus: widget.autofocus,
|
||||
focusNode: widget.focusNode,
|
||||
onPressed: widget.onPressed,
|
||||
variant: widget.variant,
|
||||
toggleable: toggleable,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
@@ -779,6 +888,8 @@ class _IconButtonM3 extends ButtonStyleButton {
|
||||
super.focusNode,
|
||||
super.autofocus = false,
|
||||
super.statesController,
|
||||
required this.variant,
|
||||
required this.toggleable,
|
||||
required Widget super.child,
|
||||
}) : super(
|
||||
onLongPress: null,
|
||||
@@ -786,6 +897,9 @@ class _IconButtonM3 extends ButtonStyleButton {
|
||||
onFocusChange: null,
|
||||
clipBehavior: Clip.none);
|
||||
|
||||
final _IconButtonVariant variant;
|
||||
final bool toggleable;
|
||||
|
||||
/// ## Material 3 defaults
|
||||
///
|
||||
/// If [ThemeData.useMaterial3] is set to true the following defaults will
|
||||
@@ -825,7 +939,16 @@ class _IconButtonM3 extends ButtonStyleButton {
|
||||
/// * `splashFactory` - Theme.splashFactory
|
||||
@override
|
||||
ButtonStyle defaultStyleOf(BuildContext context) {
|
||||
return _IconButtonDefaultsM3(context);
|
||||
switch (variant) {
|
||||
case _IconButtonVariant.filled:
|
||||
return _FilledIconButtonDefaultsM3(context, toggleable);
|
||||
case _IconButtonVariant.filledTonal:
|
||||
return _FilledTonalIconButtonDefaultsM3(context, toggleable);
|
||||
case _IconButtonVariant.outlined:
|
||||
return _OutlinedIconButtonDefaultsM3(context, toggleable);
|
||||
case _IconButtonVariant.standard:
|
||||
return _IconButtonDefaultsM3(context, toggleable);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the [IconButtonThemeData.style] of the closest [IconButtonTheme] ancestor.
|
||||
@@ -963,15 +1086,16 @@ class _IconButtonDefaultMouseCursor extends MaterialStateProperty<MouseCursor> w
|
||||
// Token database version: v0_158
|
||||
|
||||
class _IconButtonDefaultsM3 extends ButtonStyle {
|
||||
_IconButtonDefaultsM3(this.context)
|
||||
_IconButtonDefaultsM3(this.context, this.toggleable)
|
||||
: super(
|
||||
animationDuration: kThemeChangeDuration,
|
||||
enableFeedback: true,
|
||||
alignment: Alignment.center,
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
||||
final BuildContext context;
|
||||
final bool toggleable;
|
||||
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
||||
|
||||
// No default text style
|
||||
|
||||
@@ -1014,7 +1138,7 @@ class _IconButtonDefaultsM3 extends ButtonStyle {
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.onSurfaceVariant.withOpacity(0.12);
|
||||
}
|
||||
return null;
|
||||
return Colors.transparent;
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -1047,7 +1171,8 @@ class _IconButtonDefaultsM3 extends ButtonStyle {
|
||||
MaterialStateProperty<double>? get iconSize =>
|
||||
const MaterialStatePropertyAll<double>(24.0);
|
||||
|
||||
// No default side
|
||||
@override
|
||||
MaterialStateProperty<BorderSide?>? get side => null;
|
||||
|
||||
@override
|
||||
MaterialStateProperty<OutlinedBorder>? get shape =>
|
||||
@@ -1073,3 +1198,442 @@ class _IconButtonDefaultsM3 extends ButtonStyle {
|
||||
}
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - IconButton
|
||||
|
||||
// BEGIN GENERATED TOKEN PROPERTIES - FilledIconButton
|
||||
|
||||
// Do not edit by hand. The code between the "BEGIN GENERATED" and
|
||||
// "END GENERATED" comments are generated from data in the Material
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// Token database version: v0_158
|
||||
|
||||
class _FilledIconButtonDefaultsM3 extends ButtonStyle {
|
||||
_FilledIconButtonDefaultsM3(this.context, this.toggleable)
|
||||
: super(
|
||||
animationDuration: kThemeChangeDuration,
|
||||
enableFeedback: true,
|
||||
alignment: Alignment.center,
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
final bool toggleable;
|
||||
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
||||
|
||||
// No default text style
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get backgroundColor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return _colors.onSurface.withOpacity(0.12);
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return _colors.primary;
|
||||
}
|
||||
if (toggleable) { // toggleable but unselected case
|
||||
return _colors.surfaceVariant;
|
||||
}
|
||||
return _colors.primary;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get foregroundColor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return _colors.onSurface.withOpacity(0.38);
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return _colors.onPrimary;
|
||||
}
|
||||
if (toggleable) { // toggleable but unselected case
|
||||
return _colors.primary;
|
||||
}
|
||||
return _colors.onPrimary;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get overlayColor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return _colors.onPrimary.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return _colors.onPrimary.withOpacity(0.12);
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.onPrimary.withOpacity(0.12);
|
||||
}
|
||||
}
|
||||
if (toggleable) { // toggleable but unselected case
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return _colors.primary.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return _colors.primary.withOpacity(0.12);
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.primary.withOpacity(0.12);
|
||||
}
|
||||
}
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return _colors.onPrimary.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return _colors.onPrimary.withOpacity(0.12);
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.onPrimary.withOpacity(0.12);
|
||||
}
|
||||
return Colors.transparent;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<double>? get elevation =>
|
||||
const MaterialStatePropertyAll<double>(0.0);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color>? get shadowColor =>
|
||||
const MaterialStatePropertyAll<Color>(Colors.transparent);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color>? get surfaceTintColor =>
|
||||
const MaterialStatePropertyAll<Color>(Colors.transparent);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<EdgeInsetsGeometry>? get padding =>
|
||||
const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.all(8.0));
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Size>? get minimumSize =>
|
||||
const MaterialStatePropertyAll<Size>(Size(40.0, 40.0));
|
||||
|
||||
// No default fixedSize
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Size>? get maximumSize =>
|
||||
const MaterialStatePropertyAll<Size>(Size.infinite);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<double>? get iconSize =>
|
||||
const MaterialStatePropertyAll<double>(24.0);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<BorderSide?>? get side => null;
|
||||
|
||||
@override
|
||||
MaterialStateProperty<OutlinedBorder>? get shape =>
|
||||
const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder());
|
||||
|
||||
@override
|
||||
MaterialStateProperty<MouseCursor?>? get mouseCursor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return SystemMouseCursors.basic;
|
||||
}
|
||||
return SystemMouseCursors.click;
|
||||
});
|
||||
|
||||
@override
|
||||
VisualDensity? get visualDensity => VisualDensity.standard;
|
||||
|
||||
@override
|
||||
MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize;
|
||||
|
||||
@override
|
||||
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
|
||||
}
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - FilledIconButton
|
||||
|
||||
// BEGIN GENERATED TOKEN PROPERTIES - FilledTonalIconButton
|
||||
|
||||
// Do not edit by hand. The code between the "BEGIN GENERATED" and
|
||||
// "END GENERATED" comments are generated from data in the Material
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// Token database version: v0_158
|
||||
|
||||
class _FilledTonalIconButtonDefaultsM3 extends ButtonStyle {
|
||||
_FilledTonalIconButtonDefaultsM3(this.context, this.toggleable)
|
||||
: super(
|
||||
animationDuration: kThemeChangeDuration,
|
||||
enableFeedback: true,
|
||||
alignment: Alignment.center,
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
final bool toggleable;
|
||||
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
||||
|
||||
// No default text style
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get backgroundColor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return _colors.onSurface.withOpacity(0.12);
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return _colors.secondaryContainer;
|
||||
}
|
||||
if (toggleable) { // toggleable but unselected case
|
||||
return _colors.surfaceVariant;
|
||||
}
|
||||
return _colors.secondaryContainer;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get foregroundColor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return _colors.onSurface.withOpacity(0.38);
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return _colors.onSecondaryContainer;
|
||||
}
|
||||
if (toggleable) { // toggleable but unselected case
|
||||
return _colors.onSurfaceVariant;
|
||||
}
|
||||
return _colors.onSecondaryContainer;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get overlayColor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return _colors.onSecondaryContainer.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return _colors.onSecondaryContainer.withOpacity(0.12);
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.onSecondaryContainer.withOpacity(0.12);
|
||||
}
|
||||
}
|
||||
if (toggleable) { // toggleable but unselected case
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return _colors.onSurfaceVariant.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return _colors.onSurfaceVariant.withOpacity(0.12);
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.onSurfaceVariant.withOpacity(0.12);
|
||||
}
|
||||
}
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return _colors.onSecondaryContainer.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return _colors.onSecondaryContainer.withOpacity(0.12);
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.onSecondaryContainer.withOpacity(0.12);
|
||||
}
|
||||
return Colors.transparent;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<double>? get elevation =>
|
||||
const MaterialStatePropertyAll<double>(0.0);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color>? get shadowColor =>
|
||||
const MaterialStatePropertyAll<Color>(Colors.transparent);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color>? get surfaceTintColor =>
|
||||
const MaterialStatePropertyAll<Color>(Colors.transparent);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<EdgeInsetsGeometry>? get padding =>
|
||||
const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.all(8.0));
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Size>? get minimumSize =>
|
||||
const MaterialStatePropertyAll<Size>(Size(40.0, 40.0));
|
||||
|
||||
// No default fixedSize
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Size>? get maximumSize =>
|
||||
const MaterialStatePropertyAll<Size>(Size.infinite);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<double>? get iconSize =>
|
||||
const MaterialStatePropertyAll<double>(24.0);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<BorderSide?>? get side => null;
|
||||
|
||||
@override
|
||||
MaterialStateProperty<OutlinedBorder>? get shape =>
|
||||
const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder());
|
||||
|
||||
@override
|
||||
MaterialStateProperty<MouseCursor?>? get mouseCursor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return SystemMouseCursors.basic;
|
||||
}
|
||||
return SystemMouseCursors.click;
|
||||
});
|
||||
|
||||
@override
|
||||
VisualDensity? get visualDensity => VisualDensity.standard;
|
||||
|
||||
@override
|
||||
MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize;
|
||||
|
||||
@override
|
||||
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
|
||||
}
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - FilledTonalIconButton
|
||||
|
||||
// BEGIN GENERATED TOKEN PROPERTIES - OutlinedIconButton
|
||||
|
||||
// Do not edit by hand. The code between the "BEGIN GENERATED" and
|
||||
// "END GENERATED" comments are generated from data in the Material
|
||||
// Design token database by the script:
|
||||
// dev/tools/gen_defaults/bin/gen_defaults.dart.
|
||||
|
||||
// Token database version: v0_158
|
||||
|
||||
class _OutlinedIconButtonDefaultsM3 extends ButtonStyle {
|
||||
_OutlinedIconButtonDefaultsM3(this.context, this.toggleable)
|
||||
: super(
|
||||
animationDuration: kThemeChangeDuration,
|
||||
enableFeedback: true,
|
||||
alignment: Alignment.center,
|
||||
);
|
||||
|
||||
final BuildContext context;
|
||||
final bool toggleable;
|
||||
late final ColorScheme _colors = Theme.of(context).colorScheme;
|
||||
|
||||
// No default text style
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get backgroundColor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return _colors.onSurface.withOpacity(0.12);
|
||||
}
|
||||
return Colors.transparent;
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return _colors.inverseSurface;
|
||||
}
|
||||
return Colors.transparent;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get foregroundColor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return _colors.onSurface.withOpacity(0.38);
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return _colors.onInverseSurface;
|
||||
}
|
||||
return _colors.onSurfaceVariant;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color?>? get overlayColor => MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return _colors.onInverseSurface.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return _colors.onInverseSurface.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.onInverseSurface.withOpacity(0.12);
|
||||
}
|
||||
}
|
||||
if (states.contains(MaterialState.hovered)) {
|
||||
return _colors.onSurfaceVariant.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.focused)) {
|
||||
return _colors.onSurfaceVariant.withOpacity(0.08);
|
||||
}
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return _colors.onSurface.withOpacity(0.12);
|
||||
}
|
||||
return Colors.transparent;
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<double>? get elevation =>
|
||||
const MaterialStatePropertyAll<double>(0.0);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color>? get shadowColor =>
|
||||
const MaterialStatePropertyAll<Color>(Colors.transparent);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Color>? get surfaceTintColor =>
|
||||
const MaterialStatePropertyAll<Color>(Colors.transparent);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<EdgeInsetsGeometry>? get padding =>
|
||||
const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.all(8.0));
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Size>? get minimumSize =>
|
||||
const MaterialStatePropertyAll<Size>(Size(40.0, 40.0));
|
||||
|
||||
// No default fixedSize
|
||||
|
||||
@override
|
||||
MaterialStateProperty<Size>? get maximumSize =>
|
||||
const MaterialStatePropertyAll<Size>(Size.infinite);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<double>? get iconSize =>
|
||||
const MaterialStatePropertyAll<double>(24.0);
|
||||
|
||||
@override
|
||||
MaterialStateProperty<BorderSide?>? get side =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return null;
|
||||
} else {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return BorderSide(color: _colors.onSurface.withOpacity(0.12));
|
||||
}
|
||||
return BorderSide(color: _colors.outline);
|
||||
}
|
||||
});
|
||||
|
||||
@override
|
||||
MaterialStateProperty<OutlinedBorder>? get shape =>
|
||||
const MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder());
|
||||
|
||||
@override
|
||||
MaterialStateProperty<MouseCursor?>? get mouseCursor =>
|
||||
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return SystemMouseCursors.basic;
|
||||
}
|
||||
return SystemMouseCursors.click;
|
||||
});
|
||||
|
||||
@override
|
||||
VisualDensity? get visualDensity => VisualDensity.standard;
|
||||
|
||||
@override
|
||||
MaterialTapTargetSize? get tapTargetSize => Theme.of(context).materialTapTargetSize;
|
||||
|
||||
@override
|
||||
InteractiveInkFeatureFactory? get splashFactory => Theme.of(context).splashFactory;
|
||||
}
|
||||
|
||||
// END GENERATED TOKEN PROPERTIES - OutlinedIconButton
|
||||
|
||||
@@ -1133,6 +1133,609 @@ void main() {
|
||||
expect(material.type, MaterialType.button);
|
||||
});
|
||||
|
||||
testWidgets('IconButton.fill defaults - M3', (WidgetTester tester) async {
|
||||
final ThemeData themeM3 = ThemeData.from(colorScheme: colorScheme, useMaterial3: true);
|
||||
|
||||
// Enabled IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.filled(
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder buttonMaterial = find.descendant(
|
||||
of: find.byType(IconButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
Color? iconColor() => _iconStyle(tester, Icons.ac_unit)?.color;
|
||||
expect(iconColor(), colorScheme.onPrimary);
|
||||
|
||||
Material material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.primary);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
final Align align = tester.firstWidget<Align>(find.ancestor(of: find.byIcon(Icons.ac_unit), matching: find.byType(Align)));
|
||||
expect(align.alignment, Alignment.center);
|
||||
expect(tester.getSize(find.byIcon(Icons.ac_unit)), const Size(24.0, 24.0));
|
||||
|
||||
final Offset center = tester.getCenter(find.byType(IconButton));
|
||||
final TestGesture gesture = await tester.startGesture(center);
|
||||
await tester.pump(); // start the splash animation
|
||||
await tester.pump(const Duration(milliseconds: 100)); // splash is underway
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
// No change vs enabled and not pressed.
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.primary);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
// Disabled IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: const Center(
|
||||
child: IconButton.filled(
|
||||
onPressed: null,
|
||||
icon: Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.onSurface.withOpacity(0.12));
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.onSurface.withOpacity(0.38));
|
||||
});
|
||||
|
||||
testWidgets('Toggleable IconButton.fill defaults - M3', (WidgetTester tester) async {
|
||||
final ThemeData themeM3 = ThemeData.from(colorScheme: colorScheme, useMaterial3: true);
|
||||
|
||||
// Enabled selected IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.filled(
|
||||
isSelected: true,
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder buttonMaterial = find.descendant(
|
||||
of: find.byType(IconButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
Color? iconColor() => _iconStyle(tester, Icons.ac_unit)?.color;
|
||||
expect(iconColor(), colorScheme.onPrimary);
|
||||
|
||||
Material material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.primary);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
final Align align = tester.firstWidget<Align>(find.ancestor(of: find.byIcon(Icons.ac_unit), matching: find.byType(Align)));
|
||||
expect(align.alignment, Alignment.center);
|
||||
expect(tester.getSize(find.byIcon(Icons.ac_unit)), const Size(24.0, 24.0));
|
||||
|
||||
final Offset center = tester.getCenter(find.byType(IconButton));
|
||||
final TestGesture gesture = await tester.startGesture(center);
|
||||
await tester.pump(); // start the splash animation
|
||||
await tester.pump(const Duration(milliseconds: 100)); // splash is underway
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
// No change vs enabled and not pressed.
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.primary);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
// Enabled unselected IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.filled(
|
||||
isSelected: false,
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.surfaceVariant);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.primary);
|
||||
|
||||
// Disabled IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: const Center(
|
||||
child: IconButton.filled(
|
||||
isSelected: true,
|
||||
onPressed: null,
|
||||
icon: Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.onSurface.withOpacity(0.12));
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.onSurface.withOpacity(0.38));
|
||||
});
|
||||
|
||||
testWidgets('IconButton.filledTonal defaults - M3', (WidgetTester tester) async {
|
||||
final ThemeData themeM3 = ThemeData.from(colorScheme: colorScheme, useMaterial3: true);
|
||||
|
||||
// Enabled IconButton.tonal
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.filledTonal(
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder buttonMaterial = find.descendant(
|
||||
of: find.byType(IconButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
Color? iconColor() => _iconStyle(tester, Icons.ac_unit)?.color;
|
||||
expect(iconColor(), colorScheme.onSecondaryContainer);
|
||||
|
||||
Material material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.secondaryContainer);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
final Align align = tester.firstWidget<Align>(find.ancestor(of: find.byIcon(Icons.ac_unit), matching: find.byType(Align)));
|
||||
expect(align.alignment, Alignment.center);
|
||||
expect(tester.getSize(find.byIcon(Icons.ac_unit)), const Size(24.0, 24.0));
|
||||
|
||||
final Offset center = tester.getCenter(find.byType(IconButton));
|
||||
final TestGesture gesture = await tester.startGesture(center);
|
||||
await tester.pump(); // start the splash animation
|
||||
await tester.pump(const Duration(milliseconds: 100)); // splash is underway
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
// No change vs enabled and not pressed.
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.secondaryContainer);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
// Disabled IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: const Center(
|
||||
child: IconButton.filledTonal(
|
||||
onPressed: null,
|
||||
icon: Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.onSurface.withOpacity(0.12));
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.onSurface.withOpacity(0.38));
|
||||
});
|
||||
|
||||
testWidgets('Toggleable IconButton.filledTonal defaults - M3', (WidgetTester tester) async {
|
||||
final ThemeData themeM3 = ThemeData.from(colorScheme: colorScheme, useMaterial3: true);
|
||||
|
||||
// Enabled selected IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.filledTonal(
|
||||
isSelected: true,
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder buttonMaterial = find.descendant(
|
||||
of: find.byType(IconButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
Color? iconColor() => _iconStyle(tester, Icons.ac_unit)?.color;
|
||||
expect(iconColor(), colorScheme.onSecondaryContainer);
|
||||
|
||||
Material material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.secondaryContainer);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
final Align align = tester.firstWidget<Align>(find.ancestor(of: find.byIcon(Icons.ac_unit), matching: find.byType(Align)));
|
||||
expect(align.alignment, Alignment.center);
|
||||
expect(tester.getSize(find.byIcon(Icons.ac_unit)), const Size(24.0, 24.0));
|
||||
|
||||
final Offset center = tester.getCenter(find.byType(IconButton));
|
||||
final TestGesture gesture = await tester.startGesture(center);
|
||||
await tester.pump(); // start the splash animation
|
||||
await tester.pump(const Duration(milliseconds: 100)); // splash is underway
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
// No change vs enabled and not pressed.
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.secondaryContainer);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
// Enabled unselected IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.filledTonal(
|
||||
isSelected: false,
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.surfaceVariant);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.onSurfaceVariant);
|
||||
|
||||
// Disabled IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: const Center(
|
||||
child: IconButton.filledTonal(
|
||||
isSelected: true,
|
||||
onPressed: null,
|
||||
icon: Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.onSurface.withOpacity(0.12));
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.onSurface.withOpacity(0.38));
|
||||
});
|
||||
|
||||
testWidgets('IconButton.outlined defaults - M3', (WidgetTester tester) async {
|
||||
final ThemeData themeM3 = ThemeData.from(colorScheme: colorScheme, useMaterial3: true);
|
||||
|
||||
// Enabled IconButton.tonal
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.outlined(
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder buttonMaterial = find.descendant(
|
||||
of: find.byType(IconButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
Color? iconColor() => _iconStyle(tester, Icons.ac_unit)?.color;
|
||||
expect(iconColor(), colorScheme.onSurfaceVariant);
|
||||
|
||||
Material material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, Colors.transparent);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, StadiumBorder(side: BorderSide(color: colorScheme.outline)));
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
final Align align = tester.firstWidget<Align>(find.ancestor(of: find.byIcon(Icons.ac_unit), matching: find.byType(Align)));
|
||||
expect(align.alignment, Alignment.center);
|
||||
expect(tester.getSize(find.byIcon(Icons.ac_unit)), const Size(24.0, 24.0));
|
||||
|
||||
final Offset center = tester.getCenter(find.byType(IconButton));
|
||||
final TestGesture gesture = await tester.startGesture(center);
|
||||
await tester.pump(); // start the splash animation
|
||||
await tester.pump(const Duration(milliseconds: 100)); // splash is underway
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
// No change vs enabled and not pressed.
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, Colors.transparent);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, StadiumBorder(side: BorderSide(color: colorScheme.outline)));
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
// Disabled IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: const Center(
|
||||
child: IconButton.outlined(
|
||||
onPressed: null,
|
||||
icon: Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, Colors.transparent);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, StadiumBorder(side: BorderSide(color: colorScheme.onSurface.withOpacity(0.12))));
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.onSurface.withOpacity(0.38));
|
||||
});
|
||||
|
||||
testWidgets('Toggleable IconButton.outlined defaults - M3', (WidgetTester tester) async {
|
||||
final ThemeData themeM3 = ThemeData.from(colorScheme: colorScheme, useMaterial3: true);
|
||||
|
||||
// Enabled selected IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.outlined(
|
||||
isSelected: true,
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder buttonMaterial = find.descendant(
|
||||
of: find.byType(IconButton),
|
||||
matching: find.byType(Material),
|
||||
);
|
||||
Color? iconColor() => _iconStyle(tester, Icons.ac_unit)?.color;
|
||||
expect(iconColor(), colorScheme.onInverseSurface);
|
||||
|
||||
Material material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.inverseSurface);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
final Align align = tester.firstWidget<Align>(find.ancestor(of: find.byIcon(Icons.ac_unit), matching: find.byType(Align)));
|
||||
expect(align.alignment, Alignment.center);
|
||||
expect(tester.getSize(find.byIcon(Icons.ac_unit)), const Size(24.0, 24.0));
|
||||
|
||||
final Offset center = tester.getCenter(find.byType(IconButton));
|
||||
final TestGesture gesture = await tester.startGesture(center);
|
||||
await tester.pump(); // start the splash animation
|
||||
await tester.pump(const Duration(milliseconds: 100)); // splash is underway
|
||||
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
// No change vs enabled and not pressed.
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.inverseSurface);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
|
||||
// Enabled unselected IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: Center(
|
||||
child: IconButton.outlined(
|
||||
isSelected: false,
|
||||
onPressed: () { },
|
||||
icon: const Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, Colors.transparent);
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, StadiumBorder(side: BorderSide(color: colorScheme.outline)));
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.onSurfaceVariant);
|
||||
|
||||
// Disabled IconButton
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: themeM3,
|
||||
home: const Center(
|
||||
child: IconButton.outlined(
|
||||
isSelected: true,
|
||||
onPressed: null,
|
||||
icon: Icon(Icons.ac_unit),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
material = tester.widget<Material>(buttonMaterial);
|
||||
expect(material.animationDuration, const Duration(milliseconds: 200));
|
||||
expect(material.borderOnForeground, true);
|
||||
expect(material.borderRadius, null);
|
||||
expect(material.clipBehavior, Clip.none);
|
||||
expect(material.color, colorScheme.onSurface.withOpacity(0.12));
|
||||
expect(material.elevation, 0.0);
|
||||
expect(material.shadowColor, Colors.transparent);
|
||||
expect(material.shape, const StadiumBorder());
|
||||
expect(material.textStyle, null);
|
||||
expect(material.type, MaterialType.button);
|
||||
expect(iconColor(), colorScheme.onSurface.withOpacity(0.38));
|
||||
});
|
||||
|
||||
testWidgets('Default IconButton meets a11y contrast guidelines - M3', (WidgetTester tester) async {
|
||||
final FocusNode focusNode = FocusNode();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user