Unverified Commit ab7161fa authored by Hans Muller's avatar Hans Muller Committed by GitHub

Revert "ChipThemeData is now conventional" (#93797)

parent 37005e8f
...@@ -225,15 +225,8 @@ abstract class DeletableChipAttributes { ...@@ -225,15 +225,8 @@ abstract class DeletableChipAttributes {
/// {@end-tool} /// {@end-tool}
VoidCallback? get onDeleted; VoidCallback? get onDeleted;
/// Used to define the delete icon's color with an [IconTheme] that /// The [Color] for the delete icon. The default is based on the ambient
/// contains the icon. /// [IconThemeData.color].
///
/// The default is `Color(0xde000000)`
/// (slightly transparent black) for light themes, and `Color(0xdeffffff)`
/// (slightly transparent white) for dark themes.
///
/// The delete icon appears if [DeletableChipAttributes.onDeleted] is
/// non-null.
Color? get deleteIconColor; Color? get deleteIconColor;
/// Whether to use a tooltip on the chip's delete button showing the /// Whether to use a tooltip on the chip's delete button showing the
...@@ -430,8 +423,7 @@ abstract class DisabledChipAttributes { ...@@ -430,8 +423,7 @@ abstract class DisabledChipAttributes {
/// Defaults to true. Cannot be null. /// Defaults to true. Cannot be null.
bool get isEnabled; bool get isEnabled;
/// The color used for the chip's background to indicate that it is not /// Color to be used for the chip's background indicating that it is disabled.
/// enabled.
/// ///
/// The chip is disabled when [isEnabled] is false, or all three of /// The chip is disabled when [isEnabled] is false, or all three of
/// [SelectableChipAttributes.onSelected], [TappableChipAttributes.onPressed], /// [SelectableChipAttributes.onSelected], [TappableChipAttributes.onPressed],
...@@ -1716,35 +1708,25 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1716,35 +1708,25 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
widget.onPressed?.call(); widget.onPressed?.call();
} }
OutlinedBorder _getShape(ThemeData theme, ChipThemeData chipTheme, ChipThemeData chipDefaults) { OutlinedBorder _getShape(ChipThemeData theme) {
final BorderSide? resolvedSide = MaterialStateProperty.resolveAs<BorderSide?>(widget.side, materialStates) final BorderSide? resolvedSide = MaterialStateProperty.resolveAs<BorderSide?>(widget.side, materialStates)
?? MaterialStateProperty.resolveAs<BorderSide?>(chipTheme.side, materialStates) ?? MaterialStateProperty.resolveAs<BorderSide?>(theme.side, materialStates);
?? MaterialStateProperty.resolveAs<BorderSide?>(chipDefaults.side, materialStates);
final OutlinedBorder resolvedShape = MaterialStateProperty.resolveAs<OutlinedBorder?>(widget.shape, materialStates) final OutlinedBorder resolvedShape = MaterialStateProperty.resolveAs<OutlinedBorder?>(widget.shape, materialStates)
?? MaterialStateProperty.resolveAs<OutlinedBorder?>(chipTheme.shape, materialStates) ?? MaterialStateProperty.resolveAs<OutlinedBorder?>(theme.shape, materialStates)
?? MaterialStateProperty.resolveAs<OutlinedBorder?>(chipDefaults.shape, materialStates)
?? const StadiumBorder(); ?? const StadiumBorder();
return resolvedShape.copyWith(side: resolvedSide); return resolvedShape.copyWith(side: resolvedSide);
} }
/// Picks between three different colors, depending upon the state of two /// Picks between three different colors, depending upon the state of two
/// different animations. /// different animations.
Color? _getBackgroundColor(ThemeData theme, ChipThemeData chipTheme, ChipThemeData chipDefaults) { Color? getBackgroundColor(ChipThemeData theme) {
final ColorTween backgroundTween = ColorTween( final ColorTween backgroundTween = ColorTween(
begin: widget.disabledColor begin: widget.disabledColor ?? theme.disabledColor,
?? chipTheme.disabledColor end: widget.backgroundColor ?? theme.backgroundColor,
?? theme.disabledColor,
end: widget.backgroundColor
?? chipTheme.backgroundColor
?? theme.chipTheme.backgroundColor
?? chipDefaults.backgroundColor,
); );
final ColorTween selectTween = ColorTween( final ColorTween selectTween = ColorTween(
begin: backgroundTween.evaluate(enableController), begin: backgroundTween.evaluate(enableController),
end: widget.selectedColor end: widget.selectedColor ?? theme.selectedColor,
?? chipTheme.selectedColor
?? theme.chipTheme.selectedColor
?? chipDefaults.selectedColor,
); );
return selectTween.evaluate(selectionFade); return selectTween.evaluate(selectionFade);
} }
...@@ -1806,7 +1788,6 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1806,7 +1788,6 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
BuildContext context, BuildContext context,
ThemeData theme, ThemeData theme,
ChipThemeData chipTheme, ChipThemeData chipTheme,
ChipThemeData chipDefaults,
) { ) {
if (!hasDeleteButton) { if (!hasDeleteButton) {
return null; return null;
...@@ -1815,9 +1796,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1815,9 +1796,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
container: true, container: true,
button: true, button: true,
child: _wrapWithTooltip( child: _wrapWithTooltip(
tooltip: widget.useDeleteButtonTooltip tooltip: widget.useDeleteButtonTooltip ? widget.deleteButtonTooltipMessage ?? MaterialLocalizations.of(context).deleteButtonTooltip : null,
? widget.deleteButtonTooltipMessage ?? MaterialLocalizations.of(context).deleteButtonTooltip
: null,
enabled: widget.onDeleted != null, enabled: widget.onDeleted != null,
child: InkWell( child: InkWell(
// Radius should be slightly less than the full size of the chip. // Radius should be slightly less than the full size of the chip.
...@@ -1827,10 +1806,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1827,10 +1806,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
onTap: widget.isEnabled ? widget.onDeleted : null, onTap: widget.isEnabled ? widget.onDeleted : null,
child: IconTheme( child: IconTheme(
data: theme.iconTheme.copyWith( data: theme.iconTheme.copyWith(
color: widget.deleteIconColor color: widget.deleteIconColor ?? chipTheme.deleteIconColor,
?? chipTheme.deleteIconColor
?? theme.chipTheme.deleteIconColor
?? chipDefaults.deleteIconColor,
), ),
child: widget.deleteIcon, child: widget.deleteIcon,
), ),
...@@ -1862,53 +1838,19 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1862,53 +1838,19 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
final ChipThemeData chipTheme = ChipTheme.of(context); final ChipThemeData chipTheme = ChipTheme.of(context);
final Brightness brightness = chipTheme.brightness ?? theme.brightness;
final ChipThemeData chipDefaults = ChipThemeData.fromDefaults(
brightness: brightness,
secondaryColor: brightness == Brightness.dark ? Colors.tealAccent[200]! : theme.primaryColor,
labelStyle: theme.textTheme.bodyText1!,
);
final TextDirection? textDirection = Directionality.maybeOf(context); final TextDirection? textDirection = Directionality.maybeOf(context);
final OutlinedBorder resolvedShape = _getShape(theme, chipTheme, chipDefaults); final OutlinedBorder resolvedShape = _getShape(chipTheme);
final double elevation = widget.elevation ?? chipTheme.elevation ?? _defaultElevation;
final double elevation = widget.elevation final double pressElevation = widget.pressElevation ?? chipTheme.pressElevation ?? _defaultPressElevation;
?? chipTheme.elevation final Color shadowColor = widget.shadowColor ?? chipTheme.shadowColor ?? _defaultShadowColor;
?? theme.chipTheme.elevation final Color selectedShadowColor = widget.selectedShadowColor ?? chipTheme.selectedShadowColor ?? _defaultShadowColor;
?? _defaultElevation; final Color? checkmarkColor = widget.checkmarkColor ?? chipTheme.checkmarkColor;
final double pressElevation = widget.pressElevation final bool showCheckmark = widget.showCheckmark ?? chipTheme.showCheckmark ?? true;
?? chipTheme.pressElevation
?? theme.chipTheme.pressElevation final TextStyle effectiveLabelStyle = chipTheme.labelStyle.merge(widget.labelStyle);
?? _defaultPressElevation;
final Color shadowColor = widget.shadowColor
?? chipTheme.shadowColor
?? theme.chipTheme.shadowColor
?? _defaultShadowColor;
final Color selectedShadowColor = widget.selectedShadowColor
?? chipTheme.selectedShadowColor
?? theme.chipTheme.selectedShadowColor
?? _defaultShadowColor;
final Color? checkmarkColor = widget.checkmarkColor
?? chipTheme.checkmarkColor
?? theme.chipTheme.checkmarkColor;
final bool showCheckmark = widget.showCheckmark
?? chipTheme.showCheckmark
?? theme.chipTheme.showCheckmark
?? true;
final EdgeInsetsGeometry padding = widget.padding
?? chipTheme.padding
?? theme.chipTheme.padding
?? chipDefaults.padding!;
final TextStyle? labelStyle = widget.labelStyle
?? chipTheme.labelStyle
?? theme.chipTheme.labelStyle;
final EdgeInsetsGeometry labelPadding = widget.labelPadding
?? chipTheme.labelPadding
?? theme.chipTheme.labelPadding
?? _defaultLabelPadding;
final TextStyle effectiveLabelStyle = chipDefaults.labelStyle!.merge(labelStyle);
final Color? resolvedLabelColor = MaterialStateProperty.resolveAs<Color?>(effectiveLabelStyle.color, materialStates); final Color? resolvedLabelColor = MaterialStateProperty.resolveAs<Color?>(effectiveLabelStyle.color, materialStates);
final TextStyle resolvedLabelStyle = effectiveLabelStyle.copyWith(color: resolvedLabelColor); final TextStyle resolvedLabelStyle = effectiveLabelStyle.copyWith(color: resolvedLabelColor);
final EdgeInsetsGeometry labelPadding = widget.labelPadding ?? chipTheme.labelPadding ?? _defaultLabelPadding;
Widget result = Material( Widget result = Material(
elevation: isTapping ? pressElevation : elevation, elevation: isTapping ? pressElevation : elevation,
...@@ -1932,7 +1874,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1932,7 +1874,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
return Container( return Container(
decoration: ShapeDecoration( decoration: ShapeDecoration(
shape: resolvedShape, shape: resolvedShape,
color: _getBackgroundColor(theme, chipTheme, chipDefaults), color: getBackgroundColor(chipTheme),
), ),
child: child, child: child,
); );
...@@ -1958,10 +1900,10 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1958,10 +1900,10 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
deleteIcon: AnimatedSwitcher( deleteIcon: AnimatedSwitcher(
duration: _kDrawerDuration, duration: _kDrawerDuration,
switchInCurve: Curves.fastOutSlowIn, switchInCurve: Curves.fastOutSlowIn,
child: _buildDeleteIcon(context, theme, chipTheme, chipDefaults), child: _buildDeleteIcon(context, theme, chipTheme),
), ),
brightness: brightness, brightness: chipTheme.brightness,
padding: padding.resolve(textDirection), padding: (widget.padding ?? chipTheme.padding).resolve(textDirection),
visualDensity: widget.visualDensity ?? theme.visualDensity, visualDensity: widget.visualDensity ?? theme.visualDensity,
labelPadding: labelPadding.resolve(textDirection), labelPadding: labelPadding.resolve(textDirection),
showAvatar: hasAvatar, showAvatar: hasAvatar,
...@@ -2630,7 +2572,6 @@ class _RenderChip extends RenderBox { ...@@ -2630,7 +2572,6 @@ class _RenderChip extends RenderBox {
overallSize.width + theme.padding.horizontal, overallSize.width + theme.padding.horizontal,
overallSize.height + theme.padding.vertical, overallSize.height + theme.padding.vertical,
); );
return _ChipSizes( return _ChipSizes(
size: constraints.constrain(paddedSize), size: constraints.constrain(paddedSize),
overall: overallSize, overall: overallSize,
......
...@@ -179,25 +179,32 @@ class ChipThemeData with Diagnosticable { ...@@ -179,25 +179,32 @@ class ChipThemeData with Diagnosticable {
/// This will rarely be used directly. It is used by [lerp] to /// This will rarely be used directly. It is used by [lerp] to
/// create intermediate themes based on two themes. /// create intermediate themes based on two themes.
const ChipThemeData({ const ChipThemeData({
this.backgroundColor, required this.backgroundColor,
this.deleteIconColor, this.deleteIconColor,
this.disabledColor, required this.disabledColor,
this.selectedColor, required this.selectedColor,
this.secondarySelectedColor, required this.secondarySelectedColor,
this.shadowColor, this.shadowColor,
this.selectedShadowColor, this.selectedShadowColor,
this.showCheckmark, this.showCheckmark,
this.checkmarkColor, this.checkmarkColor,
this.labelPadding, this.labelPadding,
this.padding, required this.padding,
this.side, this.side,
this.shape, this.shape,
this.labelStyle, required this.labelStyle,
this.secondaryLabelStyle, required this.secondaryLabelStyle,
this.brightness, required this.brightness,
this.elevation, this.elevation,
this.pressElevation, this.pressElevation,
}); }) : assert(backgroundColor != null),
assert(disabledColor != null),
assert(selectedColor != null),
assert(secondarySelectedColor != null),
assert(padding != null),
assert(labelStyle != null),
assert(secondaryLabelStyle != null),
assert(brightness != null);
/// Generates a ChipThemeData from a brightness, a primary color, and a text /// Generates a ChipThemeData from a brightness, a primary color, and a text
/// style. /// style.
...@@ -260,87 +267,91 @@ class ChipThemeData with Diagnosticable { ...@@ -260,87 +267,91 @@ class ChipThemeData with Diagnosticable {
padding: padding, padding: padding,
labelStyle: labelStyle, labelStyle: labelStyle,
secondaryLabelStyle: secondaryLabelStyle, secondaryLabelStyle: secondaryLabelStyle,
brightness: brightness, brightness: brightness!,
); );
} }
/// Overrides the default for [ChipAttributes.backgroundColor] /// Color to be used for the unselected, enabled chip's background.
/// which is used for unselected, enabled chip backgrounds.
/// ///
/// This property applies to [ActionChip], [Chip], [ChoiceChip], /// The default is light grey.
/// [FilterChip], [InputChip], [RawChip]. final Color backgroundColor;
final Color? backgroundColor;
/// Overrides the default for [DeletableChipAttributes.deleteIconColor]. /// The [Color] for the delete icon. The default is Color(0xde000000)
/// (slightly transparent black) for light themes, and Color(0xdeffffff)
/// (slightly transparent white) for dark themes.
/// ///
/// This property applies to [Chip], [InputChip], [RawChip]. /// May be set to null, in which case the ambient [IconThemeData.color] is used.
final Color? deleteIconColor; final Color? deleteIconColor;
/// Overrides the default for /// Color to be used for the chip's background indicating that it is disabled.
/// [DisabledChipAttributes.disabledColor], the background color
/// which indicates that the chip is not enabled.
/// ///
/// This property applies to [ChoiceChip], [FilterChip], /// The chip is disabled when [DisabledChipAttributes.isEnabled] is false, or
/// [InputChip], [RawChip]. /// all three of [SelectableChipAttributes.onSelected],
final Color? disabledColor; /// [TappableChipAttributes.onPressed], and
/// [DeletableChipAttributes.onDeleted] are null.
///
/// It defaults to [Colors.black38].
final Color disabledColor;
/// Overrides the default for /// Color to be used for the chip's background, indicating that it is
/// [SelectableChipAttributes.selectedColor], the background color /// selected.
/// that indicates that the chip is selected.
/// ///
/// This property applies to [ChoiceChip], [FilterChip], /// The chip is selected when [SelectableChipAttributes.selected] is true.
/// [InputChip], [RawChip]. final Color selectedColor;
final Color? selectedColor;
/// Overrides the default for [ChoiceChip.selectedColor], the /// An alternate color to be used for the chip's background, indicating that
/// background color that indicates that the chip is selected. /// it is selected. For example, this color is used by [ChoiceChip] when the
final Color? secondarySelectedColor; /// choice is selected.
///
/// The chip is selected when [SelectableChipAttributes.selected] is true.
final Color secondarySelectedColor;
/// Overrides the default for [ChipAttributes.shadowColor], the /// Color of the chip's shadow when the elevation is greater than 0.
/// Color of the chip's shadow when its elevation is greater than 0. ///
/// If null, the chip defaults to [Colors.black].
///
/// See also:
/// ///
/// This property applies to [ActionChip], [Chip], [ChoiceChip], /// * [selectedShadowColor]
/// [FilterChip], [InputChip], [RawChip].
final Color? shadowColor; final Color? shadowColor;
/// Overrides the default for /// Color of the chip's shadow when the elevation is greater than 0 and the
/// [SelectableChipAttributes.selectedShadowColor], the Color of the /// chip is selected.
/// chip's shadow when its elevation is greater than 0 and the chip ///
/// is selected. /// If null, the chip defaults to [Colors.black].
///
/// See also:
/// ///
/// This property applies to [ChoiceChip], [FilterChip], /// * [shadowColor]
/// [InputChip], [RawChip].
final Color? selectedShadowColor; final Color? selectedShadowColor;
/// Overrides the default for /// Whether or not to show a check mark when [SelectableChipAttributes.selected] is true.
/// [CheckmarkableChipAttributes.showCheckmark], which indicates if
/// a check mark should be shown.
/// ///
/// This property applies to [FilterChip], [InputChip], [RawChip]. /// For instance, the [ChoiceChip] sets this to false so that it can be
/// selected without showing the check mark.
///
/// Defaults to true.
final bool? showCheckmark; final bool? showCheckmark;
/// Overrides the default for /// Color of the chip's check mark when a check mark is visible.
/// [CheckmarkableChipAttributes.checkmarkColor].
/// ///
/// This property applies to [FilterChip], [InputChip], [RawChip]. /// This will override the color set by the platform's brightness setting.
final Color? checkmarkColor; final Color? checkmarkColor;
/// Overrides the default for [ChipAttributes.labelPadding], /// The padding around the [Chip.label] widget.
/// the padding around the chip's label widget.
/// ///
/// This property applies to [ActionChip], [Chip], [ChoiceChip], /// By default, this is 4 logical pixels at the beginning and the end of the
/// [FilterChip], [InputChip], [RawChip]. /// label, and zero on top and bottom.
final EdgeInsetsGeometry? labelPadding; final EdgeInsetsGeometry? labelPadding;
/// Overrides the default for [ChipAttributes.padding], /// The padding between the contents of the chip and the outside [shape].
/// the padding between the contents of the chip and the outside [shape].
/// ///
/// This property applies to [ActionChip], [Chip], [ChoiceChip], /// Defaults to 4 logical pixels on all sides.
/// [FilterChip], [InputChip], [RawChip]. final EdgeInsetsGeometry padding;
final EdgeInsetsGeometry? padding;
/// Overrides the default for [ChipAttributes.side], /// The color and weight of the chip's outline.
/// the color and weight of the chip's outline. ///
/// If null, the chip defaults to the border side of [shape].
/// ///
/// This value is combined with [shape] to create a shape decorated with an /// This value is combined with [shape] to create a shape decorated with an
/// outline. If it is a [MaterialStateBorderSide], /// outline. If it is a [MaterialStateBorderSide],
...@@ -352,13 +363,11 @@ class ChipThemeData with Diagnosticable { ...@@ -352,13 +363,11 @@ class ChipThemeData with Diagnosticable {
/// * [MaterialState.hovered]. /// * [MaterialState.hovered].
/// * [MaterialState.focused]. /// * [MaterialState.focused].
/// * [MaterialState.pressed]. /// * [MaterialState.pressed].
///
/// This property applies to [ActionChip], [Chip], [ChoiceChip],
/// [FilterChip], [InputChip], [RawChip].
final BorderSide? side; final BorderSide? side;
/// Overrides the default for [ChipAttributes.shape], /// The border to draw around the chip.
/// the shape of border to draw around the chip. ///
/// If null, the chip defaults to a [StadiumBorder].
/// ///
/// This shape is combined with [side] to create a shape decorated with an /// This shape is combined with [side] to create a shape decorated with an
/// outline. If it is a [MaterialStateOutlinedBorder], /// outline. If it is a [MaterialStateOutlinedBorder],
...@@ -370,45 +379,34 @@ class ChipThemeData with Diagnosticable { ...@@ -370,45 +379,34 @@ class ChipThemeData with Diagnosticable {
/// * [MaterialState.hovered]. /// * [MaterialState.hovered].
/// * [MaterialState.focused]. /// * [MaterialState.focused].
/// * [MaterialState.pressed]. /// * [MaterialState.pressed].
///
/// This property applies to [ActionChip], [Chip], [ChoiceChip],
/// [FilterChip], [InputChip], [RawChip].
final OutlinedBorder? shape; final OutlinedBorder? shape;
/// Overrides the default for [ChipAttributes.labelStyle], /// The style to be applied to the chip's label.
/// the style of the [DefaultTextStyle] that contains the
/// chip's label.
/// ///
/// This only has an effect on label widgets that respect the /// This only has an effect on label widgets that respect the
/// [DefaultTextStyle], such as [Text]. /// [DefaultTextStyle], such as [Text].
/// final TextStyle labelStyle;
/// This property applies to [ActionChip], [Chip],
/// [FilterChip], [InputChip], [RawChip].
final TextStyle? labelStyle;
/// Overrides the default for [ChoiceChip.labelStyle], /// An alternate style to be applied to the chip's label. For example, this
/// the style of the [DefaultTextStyle] that contains the /// style is applied to the text of a selected [ChoiceChip].
/// chip's label.
/// ///
/// This only has an effect on label widgets that respect the /// This only has an effect on label widgets that respect the
/// [DefaultTextStyle], such as [Text]. /// [DefaultTextStyle], such as [Text].
final TextStyle? secondaryLabelStyle; final TextStyle secondaryLabelStyle;
/// Overrides the default value for all chips which affects various base /// The brightness setting for this theme.
/// material color choices in the chip rendering. ///
final Brightness? brightness; /// This affects various base material color choices in the chip rendering.
final Brightness brightness;
/// Overrides the default for [ChipAttributes.elevation], /// The elevation to be applied to the chip.
/// the elevation of the chip's [Material].
/// ///
/// This property applies to [ActionChip], [Chip], [ChoiceChip], /// If null, the chip defaults to 0.
/// [FilterChip], [InputChip], [RawChip].
final double? elevation; final double? elevation;
/// Overrides the default for [TappableChipAttributes.pressElevation], /// The elevation to be applied to the chip during the press motion.
/// the elevation of the chip's [Material] during a "press" or tap down.
/// ///
/// This property applies to [ActionChip], [InputChip], [RawChip]. /// If null, the chip defaults to 8.
final double? pressElevation; final double? pressElevation;
/// Creates a copy of this object but with the given fields replaced with the /// Creates a copy of this object but with the given fields replaced with the
...@@ -463,20 +461,20 @@ class ChipThemeData with Diagnosticable { ...@@ -463,20 +461,20 @@ class ChipThemeData with Diagnosticable {
if (a == null && b == null) if (a == null && b == null)
return null; return null;
return ChipThemeData( return ChipThemeData(
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t), backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t)!,
deleteIconColor: Color.lerp(a?.deleteIconColor, b?.deleteIconColor, t), deleteIconColor: Color.lerp(a?.deleteIconColor, b?.deleteIconColor, t),
disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t), disabledColor: Color.lerp(a?.disabledColor, b?.disabledColor, t)!,
selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t), selectedColor: Color.lerp(a?.selectedColor, b?.selectedColor, t)!,
secondarySelectedColor: Color.lerp(a?.secondarySelectedColor, b?.secondarySelectedColor, t), secondarySelectedColor: Color.lerp(a?.secondarySelectedColor, b?.secondarySelectedColor, t)!,
shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t), shadowColor: Color.lerp(a?.shadowColor, b?.shadowColor, t),
selectedShadowColor: Color.lerp(a?.selectedShadowColor, b?.selectedShadowColor, t), selectedShadowColor: Color.lerp(a?.selectedShadowColor, b?.selectedShadowColor, t),
checkmarkColor: Color.lerp(a?.checkmarkColor, b?.checkmarkColor, t), checkmarkColor: Color.lerp(a?.checkmarkColor, b?.checkmarkColor, t),
labelPadding: EdgeInsetsGeometry.lerp(a?.labelPadding, b?.labelPadding, t), labelPadding: EdgeInsetsGeometry.lerp(a?.labelPadding, b?.labelPadding, t),
padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t), padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t)!,
side: _lerpSides(a?.side, b?.side, t), side: _lerpSides(a?.side, b?.side, t),
shape: _lerpShapes(a?.shape, b?.shape, t), shape: _lerpShapes(a?.shape, b?.shape, t),
labelStyle: TextStyle.lerp(a?.labelStyle, b?.labelStyle, t), labelStyle: TextStyle.lerp(a?.labelStyle, b?.labelStyle, t)!,
secondaryLabelStyle: TextStyle.lerp(a?.secondaryLabelStyle, b?.secondaryLabelStyle, t), secondaryLabelStyle: TextStyle.lerp(a?.secondaryLabelStyle, b?.secondaryLabelStyle, t)!,
brightness: t < 0.5 ? a?.brightness ?? Brightness.light : b?.brightness ?? Brightness.light, brightness: t < 0.5 ? a?.brightness ?? Brightness.light : b?.brightness ?? Brightness.light,
elevation: lerpDouble(a?.elevation, b?.elevation, t), elevation: lerpDouble(a?.elevation, b?.elevation, t),
pressElevation: lerpDouble(a?.pressElevation, b?.pressElevation, t), pressElevation: lerpDouble(a?.pressElevation, b?.pressElevation, t),
...@@ -555,22 +553,28 @@ class ChipThemeData with Diagnosticable { ...@@ -555,22 +553,28 @@ class ChipThemeData with Diagnosticable {
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: null)); final ThemeData defaultTheme = ThemeData.fallback();
properties.add(ColorProperty('deleteIconColor', deleteIconColor, defaultValue: null)); final ChipThemeData defaultData = ChipThemeData.fromDefaults(
properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: null)); secondaryColor: defaultTheme.primaryColor,
properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: null)); brightness: defaultTheme.brightness,
properties.add(ColorProperty('secondarySelectedColor', secondarySelectedColor, defaultValue: null)); labelStyle: defaultTheme.textTheme.bodyText1!,
properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); );
properties.add(ColorProperty('selectedShadowColor', selectedShadowColor, defaultValue: null)); properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: defaultData.backgroundColor));
properties.add(ColorProperty('checkMarkColor', checkmarkColor, defaultValue: null)); properties.add(ColorProperty('deleteIconColor', deleteIconColor, defaultValue: defaultData.deleteIconColor));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('labelPadding', labelPadding, defaultValue: null)); properties.add(ColorProperty('disabledColor', disabledColor, defaultValue: defaultData.disabledColor));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); properties.add(ColorProperty('selectedColor', selectedColor, defaultValue: defaultData.selectedColor));
properties.add(DiagnosticsProperty<BorderSide>('side', side, defaultValue: null)); properties.add(ColorProperty('secondarySelectedColor', secondarySelectedColor, defaultValue: defaultData.secondarySelectedColor));
properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: null)); properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: defaultData.shadowColor));
properties.add(DiagnosticsProperty<TextStyle>('labelStyle', labelStyle, defaultValue: null)); properties.add(ColorProperty('selectedShadowColor', selectedShadowColor, defaultValue: defaultData.selectedShadowColor));
properties.add(DiagnosticsProperty<TextStyle>('secondaryLabelStyle', secondaryLabelStyle, defaultValue: null)); properties.add(ColorProperty('checkMarkColor', checkmarkColor, defaultValue: defaultData.checkmarkColor));
properties.add(EnumProperty<Brightness>('brightness', brightness, defaultValue: null)); properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('labelPadding', labelPadding, defaultValue: defaultData.labelPadding));
properties.add(DoubleProperty('elevation', elevation, defaultValue: null)); properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: defaultData.padding));
properties.add(DoubleProperty('pressElevation', pressElevation, defaultValue: null)); properties.add(DiagnosticsProperty<BorderSide>('side', side, defaultValue: defaultData.side));
properties.add(DiagnosticsProperty<ShapeBorder>('shape', shape, defaultValue: defaultData.shape));
properties.add(DiagnosticsProperty<TextStyle>('labelStyle', labelStyle, defaultValue: defaultData.labelStyle));
properties.add(DiagnosticsProperty<TextStyle>('secondaryLabelStyle', secondaryLabelStyle, defaultValue: defaultData.secondaryLabelStyle));
properties.add(EnumProperty<Brightness>('brightness', brightness, defaultValue: defaultData.brightness));
properties.add(DoubleProperty('elevation', elevation, defaultValue: defaultData.elevation));
properties.add(DoubleProperty('pressElevation', pressElevation, defaultValue: defaultData.pressElevation));
} }
} }
...@@ -472,7 +472,11 @@ class ThemeData with Diagnosticable { ...@@ -472,7 +472,11 @@ class ThemeData with Diagnosticable {
bottomSheetTheme ??= const BottomSheetThemeData(); bottomSheetTheme ??= const BottomSheetThemeData();
buttonBarTheme ??= const ButtonBarThemeData(); buttonBarTheme ??= const ButtonBarThemeData();
cardTheme ??= const CardTheme(); cardTheme ??= const CardTheme();
chipTheme ??= const ChipThemeData(); chipTheme ??= ChipThemeData.fromDefaults(
secondaryColor: isDark ? Colors.tealAccent[200]! : primaryColor,
brightness: colorScheme.brightness,
labelStyle: textTheme.bodyText1!,
);
checkboxTheme ??= const CheckboxThemeData(); checkboxTheme ??= const CheckboxThemeData();
dataTableTheme ??= const DataTableThemeData(); dataTableTheme ??= const DataTableThemeData();
dialogTheme ??= const DialogTheme(); dialogTheme ??= const DialogTheme();
......
...@@ -270,80 +270,6 @@ Finder findTooltipContainer(String tooltipText) { ...@@ -270,80 +270,6 @@ Finder findTooltipContainer(String tooltipText) {
} }
void main() { void main() {
testWidgets('Chip defaults', (WidgetTester tester) async {
Widget buildFrame(Brightness brightness) {
return MaterialApp(
theme: ThemeData(brightness: brightness),
home: Scaffold(
body: Center(
child: Chip(
avatar: const CircleAvatar(child: Text('A')),
label: const Text('Chip A'),
onDeleted: () { },
),
),
),
);
}
await tester.pumpWidget(buildFrame(Brightness.light));
expect(getMaterialBox(tester), paints..path(color: const Color(0x1f000000)));
expect(tester.getSize(find.byType(Chip)), const Size(156.0, 48.0));
expect(getMaterial(tester).color, null);
expect(getMaterial(tester).elevation, 0);
expect(getMaterial(tester).shape, const StadiumBorder());
expect(getIconData(tester).color?.value, 0xffffffff);
expect(getIconData(tester).opacity, null);
expect(getIconData(tester).size, null);
expect(getLabelStyle(tester).style.color?.value, 0xde000000);
await tester.pumpWidget(buildFrame(Brightness.dark));
await tester.pumpAndSettle(); // Theme transition animation
expect(getMaterialBox(tester), paints..path(color: const Color(0x1fffffff)));
expect(tester.getSize(find.byType(Chip)), const Size(156.0, 48.0));
expect(getMaterial(tester).color, null);
expect(getMaterial(tester).elevation, 0);
expect(getMaterial(tester).shape, const StadiumBorder());
expect(getIconData(tester).color?.value, 0xffffffff);
expect(getIconData(tester).opacity, null);
expect(getIconData(tester).size, null);
expect(getLabelStyle(tester).style.color?.value, 0xffffffff);
});
testWidgets('ChoiceChip defaults', (WidgetTester tester) async {
Widget buildFrame(Brightness brightness) {
return MaterialApp(
theme: ThemeData(brightness: brightness),
home: const Scaffold(
body: Center(
child: ChoiceChip(
label: Text('Chip A'),
selected: true,
),
),
),
);
}
await tester.pumpWidget(buildFrame(Brightness.light));
expect(getMaterialBox(tester), paints..path(color: const Color(0x3d000000)));
expect(tester.getSize(find.byType(ChoiceChip)), const Size(108.0, 48.0));
expect(getMaterial(tester).color, null);
expect(getMaterial(tester).elevation, 0);
expect(getMaterial(tester).shape, const StadiumBorder());
expect(getLabelStyle(tester).style.color?.value, 0xde000000);
await tester.pumpWidget(buildFrame(Brightness.dark));
await tester.pumpAndSettle(); // Theme transition animation
expect(getMaterialBox(tester), paints..path(color: const Color(0x3dffffff)));
expect(tester.getSize(find.byType(ChoiceChip)), const Size(108.0, 48.0));
expect(getMaterial(tester).color, null);
expect(getMaterial(tester).elevation, 0);
expect(getMaterial(tester).shape, const StadiumBorder());
expect(getLabelStyle(tester).style.color?.value, 0xdeffffff);
});
testWidgets('Chip control test', (WidgetTester tester) async { testWidgets('Chip control test', (WidgetTester tester) async {
final FeedbackTester feedback = FeedbackTester(); final FeedbackTester feedback = FeedbackTester();
final List<String> deletedChipLabels = <String>[]; final List<String> deletedChipLabels = <String>[];
...@@ -1771,11 +1697,7 @@ void main() { ...@@ -1771,11 +1697,7 @@ void main() {
platform: TargetPlatform.android, platform: TargetPlatform.android,
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
); );
final ChipThemeData defaultChipTheme = ChipThemeData.fromDefaults( final ChipThemeData defaultChipTheme = themeData.chipTheme;
brightness: themeData.brightness,
secondaryColor: Colors.blue,
labelStyle: themeData.textTheme.bodyText1!,
);
bool value = false; bool value = false;
Widget buildApp({ Widget buildApp({
ChipThemeData? chipTheme, ChipThemeData? chipTheme,
......
...@@ -39,267 +39,130 @@ IconThemeData getIconData(WidgetTester tester) { ...@@ -39,267 +39,130 @@ IconThemeData getIconData(WidgetTester tester) {
DefaultTextStyle getLabelStyle(WidgetTester tester) { DefaultTextStyle getLabelStyle(WidgetTester tester) {
return tester.widget( return tester.widget(
find.descendant( find
of: find.byType(RawChip), .descendant(
matching: find.byType(DefaultTextStyle), of: find.byType(RawChip),
).last, matching: find.byType(DefaultTextStyle),
)
.last,
); );
} }
void main() { void main() {
test('ChipThemeData copyWith, ==, hashCode basics', () { testWidgets('Chip theme is built by ThemeData', (WidgetTester tester) async {
expect(const ChipThemeData(), const ChipThemeData().copyWith()); final ThemeData theme = ThemeData(
expect(const ChipThemeData().hashCode, const ChipThemeData().copyWith().hashCode); platform: TargetPlatform.android,
}); primarySwatch: Colors.red,
);
test('ChipThemeData defaults', () { final ChipThemeData chipTheme = theme.chipTheme;
const ChipThemeData themeData = ChipThemeData();
expect(themeData.backgroundColor, null);
expect(themeData.deleteIconColor, null);
expect(themeData.disabledColor, null);
expect(themeData.selectedColor, null);
expect(themeData.secondarySelectedColor, null);
expect(themeData.shadowColor, null);
expect(themeData.selectedShadowColor, null);
expect(themeData.showCheckmark, null);
expect(themeData.checkmarkColor, null);
expect(themeData.labelPadding, null);
expect(themeData.padding, null);
expect(themeData.side, null);
expect(themeData.shape, null);
expect(themeData.labelStyle, null);
expect(themeData.secondaryLabelStyle, null);
expect(themeData.brightness, null);
expect(themeData.elevation, null);
expect(themeData.pressElevation, null);
});
testWidgets('Default ChipThemeData debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const ChipThemeData().debugFillProperties(builder);
final List<String> description = builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString())
.toList();
expect(description, <String>[]); expect(chipTheme.backgroundColor, equals(Colors.black.withAlpha(0x1f)));
expect(chipTheme.selectedColor, equals(Colors.black.withAlpha(0x3d)));
expect(chipTheme.secondarySelectedColor, equals(Colors.red.withAlpha(0x3d)));
expect(chipTheme.deleteIconColor, equals(Colors.black.withAlpha(0xde)));
}); });
testWidgets('ChipThemeData implements debugFillProperties', (WidgetTester tester) async { testWidgets('Chip theme is built by ThemeData with dark mode enabled', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final ThemeData theme = ThemeData(
const ChipThemeData( platform: TargetPlatform.android,
backgroundColor: Color(0xfffffff0),
deleteIconColor: Color(0xfffffff1),
disabledColor: Color(0xfffffff2),
selectedColor: Color(0xfffffff3),
secondarySelectedColor: Color(0xfffffff4),
shadowColor: Color(0xfffffff5),
selectedShadowColor: Color(0xfffffff6),
showCheckmark: true,
checkmarkColor: Color(0xfffffff7),
labelPadding: EdgeInsets.all(1),
padding: EdgeInsets.all(2),
side: BorderSide(width: 10),
shape: RoundedRectangleBorder(),
labelStyle: TextStyle(fontSize: 10),
secondaryLabelStyle: TextStyle(fontSize: 20),
brightness: Brightness.dark, brightness: Brightness.dark,
elevation: 5, );
pressElevation: 6, final ChipThemeData chipTheme = theme.chipTheme;
).debugFillProperties(builder);
expect(chipTheme.backgroundColor, equals(Colors.white.withAlpha(0x1f)));
final List<String> description = builder.properties expect(chipTheme.selectedColor, equals(Colors.white.withAlpha(0x3d)));
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) expect(chipTheme.secondarySelectedColor, equals(Colors.tealAccent[200]!.withAlpha(0x3d)));
.map((DiagnosticsNode node) => node.toString()) expect(chipTheme.deleteIconColor, equals(Colors.white.withAlpha(0xde)));
.toList();
expect(description, <String>[
'backgroundColor: Color(0xfffffff0)',
'deleteIconColor: Color(0xfffffff1)',
'disabledColor: Color(0xfffffff2)',
'selectedColor: Color(0xfffffff3)',
'secondarySelectedColor: Color(0xfffffff4)',
'shadowColor: Color(0xfffffff5)',
'selectedShadowColor: Color(0xfffffff6)',
'checkMarkColor: Color(0xfffffff7)',
'labelPadding: EdgeInsets.all(1.0)',
'padding: EdgeInsets.all(2.0)',
'side: BorderSide(Color(0xff000000), 10.0, BorderStyle.solid)',
'shape: RoundedRectangleBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none), BorderRadius.zero)',
'labelStyle: TextStyle(inherit: true, size: 10.0)',
'secondaryLabelStyle: TextStyle(inherit: true, size: 20.0)',
'brightness: dark',
'elevation: 5.0',
'pressElevation: 6.0',
]);
}); });
testWidgets('Chip uses ThemeData chip theme', (WidgetTester tester) async { testWidgets('Chip uses ThemeData chip theme if present', (WidgetTester tester) async {
const ChipThemeData chipTheme = ChipThemeData( final ThemeData theme = ThemeData(
backgroundColor: Color(0xff112233), platform: TargetPlatform.android,
elevation: 4, primarySwatch: Colors.red,
padding: EdgeInsets.all(50), backgroundColor: Colors.blue,
labelPadding: EdgeInsets.all(25),
shape: RoundedRectangleBorder(),
labelStyle: TextStyle(fontSize: 32),
); );
final ChipThemeData chipTheme = theme.chipTheme;
await tester.pumpWidget( Widget buildChip(ChipThemeData data) {
MaterialApp( return MaterialApp(
theme: ThemeData.light().copyWith( locale: const Locale('en', 'us'),
chipTheme: chipTheme,
),
home: Directionality( home: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Material( child: Material(
child: Center( child: Center(
child: RawChip( child: Theme(
label: const SizedBox(width: 100, height: 100), data: theme,
onSelected: (bool newValue) { }, child: RawChip(
onDeleted: () { },
avatar: const Placeholder(),
deleteIcon: const Placeholder(),
label: const Text('Chip'),
onSelected: (bool newValue) { },
),
), ),
), ),
), ),
), ),
), );
); }
await tester.pumpWidget(buildChip(chipTheme));
await tester.pumpAndSettle();
final RenderBox materialBox = getMaterialBox(tester); final RenderBox materialBox = getMaterialBox(tester);
expect(materialBox, paints..path(color: chipTheme.backgroundColor)); expect(materialBox, paints..path(color: chipTheme.backgroundColor));
expect(getMaterial(tester).elevation, chipTheme.elevation);
expect(tester.getSize(find.byType(RawChip)), const Size(250, 250)); // label + padding + labelPadding
expect(getMaterial(tester).shape, chipTheme.shape);
expect(getLabelStyle(tester).style.fontSize, 32);
}); });
testWidgets('Chip uses ChipTheme', (WidgetTester tester) async { testWidgets('Chip overrides ThemeData theme if ChipTheme present', (WidgetTester tester) async {
const ChipThemeData chipTheme = ChipThemeData( final ThemeData theme = ThemeData(
backgroundColor: Color(0xff112233), platform: TargetPlatform.android,
elevation: 4, primarySwatch: Colors.red,
padding: EdgeInsets.all(50),
labelPadding: EdgeInsets.all(25),
labelStyle: TextStyle(fontSize: 32),
shape: RoundedRectangleBorder(),
); );
final ChipThemeData chipTheme = theme.chipTheme;
const ChipThemeData shadowedChipTheme = ChipThemeData( final ChipThemeData customTheme = chipTheme.copyWith(
backgroundColor: Color(0xff332211), backgroundColor: Colors.purple,
elevation: 3, deleteIconColor: Colors.purple.withAlpha(0x3d),
padding: EdgeInsets.all(5), elevation: 3.0,
labelPadding: EdgeInsets.all(10), shadowColor: Colors.pink,
labelStyle: TextStyle(fontSize: 64),
shape: CircleBorder(),
); );
const bool value = false;
await tester.pumpWidget( Widget buildChip(ChipThemeData data) {
MaterialApp( return MaterialApp(
theme: ThemeData.light().copyWith( home: Directionality(
chipTheme: shadowedChipTheme, textDirection: TextDirection.ltr,
), child: Material(
home: ChipTheme( child: Center(
data: chipTheme, child: Theme(
child: Builder( data: theme,
builder: (BuildContext context) { child: ChipTheme(
return Directionality( data: customTheme,
textDirection: TextDirection.ltr, child: RawChip(
child: Material( onDeleted: () { },
child: Center( avatar: const Placeholder(),
child: RawChip( deleteIcon: const Placeholder(),
label: const SizedBox(width: 100, height: 100), label: const Text('$value'),
onSelected: (bool newValue) { }, onSelected: (bool newValue) { },
),
), ),
), ),
); ),
}, ),
), ),
), ),
), );
); }
final RenderBox materialBox = getMaterialBox(tester);
expect(materialBox, paints..path(color: chipTheme.backgroundColor));
expect(tester.getSize(find.byType(RawChip)), const Size(250, 250)); // label + padding + labelPadding
expect(getMaterial(tester).elevation, chipTheme.elevation);
expect(getMaterial(tester).shape, chipTheme.shape);
expect(getLabelStyle(tester).style.fontSize, 32);
});
testWidgets('Chip uses constructor parameters', (WidgetTester tester) async {
const ChipThemeData shadowedChipTheme = ChipThemeData(
backgroundColor: Color(0xff112233),
elevation: 4,
padding: EdgeInsets.all(5),
labelPadding: EdgeInsets.all(2),
labelStyle: TextStyle(),
shape: RoundedRectangleBorder(),
);
const Color backgroundColor = Color(0xff332211); await tester.pumpWidget(buildChip(chipTheme));
const double elevation = 3; await tester.pumpAndSettle();
const double fontSize = 32;
const OutlinedBorder shape = CircleBorder();
await tester.pumpWidget(
MaterialApp(
home: ChipTheme(
data: shadowedChipTheme,
child: Builder(
builder: (BuildContext context) {
return Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: RawChip(
backgroundColor: backgroundColor,
elevation: elevation,
padding: const EdgeInsets.all(50),
labelPadding:const EdgeInsets.all(25),
labelStyle: const TextStyle(fontSize: fontSize),
shape: shape,
label: const SizedBox(width: 100, height: 100),
onSelected: (bool newValue) { },
),
),
),
);
},
),
),
),
);
final RenderBox materialBox = getMaterialBox(tester); final RenderBox materialBox = getMaterialBox(tester);
expect(materialBox, paints..path(color: backgroundColor)); final Material material = getMaterial(tester);
expect(tester.getSize(find.byType(RawChip)), const Size(250, 250)); // label + padding + labelPadding
expect(getMaterial(tester).elevation, elevation);
expect(getMaterial(tester).shape, shape);
expect(getLabelStyle(tester).style.fontSize, 32);
});
testWidgets('ChipTheme.fromDefaults', (WidgetTester tester) async {
ChipThemeData chipTheme = ChipThemeData.fromDefaults(
brightness: Brightness.light,
secondaryColor: Colors.red,
labelStyle: const TextStyle(),
);
expect(chipTheme.backgroundColor, equals(Colors.black.withAlpha(0x1f)));
expect(chipTheme.selectedColor, equals(Colors.black.withAlpha(0x3d)));
expect(chipTheme.secondarySelectedColor, equals(Colors.red.withAlpha(0x3d)));
expect(chipTheme.deleteIconColor, equals(Colors.black.withAlpha(0xde)));
chipTheme = ChipThemeData.fromDefaults( expect(materialBox, paints..path(color: Color(customTheme.backgroundColor.value)));
brightness: Brightness.dark, expect(material.elevation, customTheme.elevation);
secondaryColor: Colors.tealAccent[200]!, expect(material.shadowColor, customTheme.shadowColor);
labelStyle: const TextStyle(),
);
expect(chipTheme.backgroundColor, equals(Colors.white.withAlpha(0x1f)));
expect(chipTheme.selectedColor, equals(Colors.white.withAlpha(0x3d)));
expect(chipTheme.secondarySelectedColor, equals(Colors.tealAccent[200]!.withAlpha(0x3d)));
expect(chipTheme.deleteIconColor, equals(Colors.white.withAlpha(0xde)));
}); });
testWidgets('ChipThemeData generates correct opacities for defaults', (WidgetTester tester) async { testWidgets('ChipThemeData generates correct opacities for defaults', (WidgetTester tester) async {
const Color customColor1 = Color(0xcafefeed); const Color customColor1 = Color(0xcafefeed);
const Color customColor2 = Color(0xdeadbeef); const Color customColor2 = Color(0xdeadbeef);
...@@ -320,8 +183,8 @@ void main() { ...@@ -320,8 +183,8 @@ void main() {
expect(lightTheme.padding, equals(const EdgeInsets.all(4.0))); expect(lightTheme.padding, equals(const EdgeInsets.all(4.0)));
expect(lightTheme.side, isNull); expect(lightTheme.side, isNull);
expect(lightTheme.shape, isNull); expect(lightTheme.shape, isNull);
expect(lightTheme.labelStyle?.color, equals(Colors.black.withAlpha(0xde))); expect(lightTheme.labelStyle.color, equals(Colors.black.withAlpha(0xde)));
expect(lightTheme.secondaryLabelStyle?.color, equals(customColor1.withAlpha(0xde))); expect(lightTheme.secondaryLabelStyle.color, equals(customColor1.withAlpha(0xde)));
expect(lightTheme.brightness, equals(Brightness.light)); expect(lightTheme.brightness, equals(Brightness.light));
final ChipThemeData darkTheme = ChipThemeData.fromDefaults( final ChipThemeData darkTheme = ChipThemeData.fromDefaults(
...@@ -339,8 +202,8 @@ void main() { ...@@ -339,8 +202,8 @@ void main() {
expect(darkTheme.padding, equals(const EdgeInsets.all(4.0))); expect(darkTheme.padding, equals(const EdgeInsets.all(4.0)));
expect(darkTheme.side, isNull); expect(darkTheme.side, isNull);
expect(darkTheme.shape, isNull); expect(darkTheme.shape, isNull);
expect(darkTheme.labelStyle?.color, equals(Colors.white.withAlpha(0xde))); expect(darkTheme.labelStyle.color, equals(Colors.white.withAlpha(0xde)));
expect(darkTheme.secondaryLabelStyle?.color, equals(customColor1.withAlpha(0xde))); expect(darkTheme.secondaryLabelStyle.color, equals(customColor1.withAlpha(0xde)));
expect(darkTheme.brightness, equals(Brightness.dark)); expect(darkTheme.brightness, equals(Brightness.dark));
final ChipThemeData customTheme = ChipThemeData.fromDefaults( final ChipThemeData customTheme = ChipThemeData.fromDefaults(
...@@ -349,7 +212,7 @@ void main() { ...@@ -349,7 +212,7 @@ void main() {
labelStyle: customStyle, labelStyle: customStyle,
); );
//expect(customTheme.backgroundColor, equals(customColor1.withAlpha(0x1f))); expect(customTheme.backgroundColor, equals(customColor1.withAlpha(0x1f)));
expect(customTheme.deleteIconColor, equals(customColor1.withAlpha(0xde))); expect(customTheme.deleteIconColor, equals(customColor1.withAlpha(0xde)));
expect(customTheme.disabledColor, equals(customColor1.withAlpha(0x0c))); expect(customTheme.disabledColor, equals(customColor1.withAlpha(0x0c)));
expect(customTheme.selectedColor, equals(customColor1.withAlpha(0x3d))); expect(customTheme.selectedColor, equals(customColor1.withAlpha(0x3d)));
...@@ -358,8 +221,8 @@ void main() { ...@@ -358,8 +221,8 @@ void main() {
expect(customTheme.padding, equals(const EdgeInsets.all(4.0))); expect(customTheme.padding, equals(const EdgeInsets.all(4.0)));
expect(customTheme.side, isNull); expect(customTheme.side, isNull);
expect(customTheme.shape, isNull); expect(customTheme.shape, isNull);
expect(customTheme.labelStyle?.color, equals(customColor1.withAlpha(0xde))); expect(customTheme.labelStyle.color, equals(customColor1.withAlpha(0xde)));
expect(customTheme.secondaryLabelStyle?.color, equals(customColor2.withAlpha(0xde))); expect(customTheme.secondaryLabelStyle.color, equals(customColor2.withAlpha(0xde)));
expect(customTheme.brightness, equals(Brightness.light)); expect(customTheme.brightness, equals(Brightness.light));
}); });
...@@ -407,8 +270,8 @@ void main() { ...@@ -407,8 +270,8 @@ void main() {
expect(lerp.padding, equals(const EdgeInsets.all(3.0))); expect(lerp.padding, equals(const EdgeInsets.all(3.0)));
expect(lerp.side!.color, equals(middleGrey)); expect(lerp.side!.color, equals(middleGrey));
expect(lerp.shape, isA<BeveledRectangleBorder>()); expect(lerp.shape, isA<BeveledRectangleBorder>());
expect(lerp.labelStyle?.color, equals(middleGrey.withAlpha(0xde))); expect(lerp.labelStyle.color, equals(middleGrey.withAlpha(0xde)));
expect(lerp.secondaryLabelStyle?.color, equals(middleGrey.withAlpha(0xde))); expect(lerp.secondaryLabelStyle.color, equals(middleGrey.withAlpha(0xde)));
expect(lerp.brightness, equals(Brightness.light)); expect(lerp.brightness, equals(Brightness.light));
expect(lerp.elevation, 3.0); expect(lerp.elevation, 3.0);
expect(lerp.pressElevation, 7.0); expect(lerp.pressElevation, 7.0);
...@@ -428,8 +291,8 @@ void main() { ...@@ -428,8 +291,8 @@ void main() {
expect(lerpANull25.padding, equals(const EdgeInsets.all(0.5))); expect(lerpANull25.padding, equals(const EdgeInsets.all(0.5)));
expect(lerpANull25.side!.color, equals(Colors.white.withAlpha(0x3f))); expect(lerpANull25.side!.color, equals(Colors.white.withAlpha(0x3f)));
expect(lerpANull25.shape, isA<BeveledRectangleBorder>()); expect(lerpANull25.shape, isA<BeveledRectangleBorder>());
expect(lerpANull25.labelStyle?.color, equals(Colors.black.withAlpha(0x38))); expect(lerpANull25.labelStyle.color, equals(Colors.black.withAlpha(0x38)));
expect(lerpANull25.secondaryLabelStyle?.color, equals(Colors.white.withAlpha(0x38))); expect(lerpANull25.secondaryLabelStyle.color, equals(Colors.white.withAlpha(0x38)));
expect(lerpANull25.brightness, equals(Brightness.light)); expect(lerpANull25.brightness, equals(Brightness.light));
expect(lerpANull25.elevation, 1.25); expect(lerpANull25.elevation, 1.25);
expect(lerpANull25.pressElevation, 2.5); expect(lerpANull25.pressElevation, 2.5);
...@@ -447,8 +310,8 @@ void main() { ...@@ -447,8 +310,8 @@ void main() {
expect(lerpANull75.padding, equals(const EdgeInsets.all(1.5))); expect(lerpANull75.padding, equals(const EdgeInsets.all(1.5)));
expect(lerpANull75.side!.color, equals(Colors.white.withAlpha(0xbf))); expect(lerpANull75.side!.color, equals(Colors.white.withAlpha(0xbf)));
expect(lerpANull75.shape, isA<BeveledRectangleBorder>()); expect(lerpANull75.shape, isA<BeveledRectangleBorder>());
expect(lerpANull75.labelStyle?.color, equals(Colors.black.withAlpha(0xa7))); expect(lerpANull75.labelStyle.color, equals(Colors.black.withAlpha(0xa7)));
expect(lerpANull75.secondaryLabelStyle?.color, equals(Colors.white.withAlpha(0xa7))); expect(lerpANull75.secondaryLabelStyle.color, equals(Colors.white.withAlpha(0xa7)));
expect(lerpANull75.brightness, equals(Brightness.light)); expect(lerpANull75.brightness, equals(Brightness.light));
expect(lerpANull75.elevation, 3.75); expect(lerpANull75.elevation, 3.75);
expect(lerpANull75.pressElevation, 7.5); expect(lerpANull75.pressElevation, 7.5);
...@@ -466,8 +329,8 @@ void main() { ...@@ -466,8 +329,8 @@ void main() {
expect(lerpBNull25.padding, equals(const EdgeInsets.all(3.0))); expect(lerpBNull25.padding, equals(const EdgeInsets.all(3.0)));
expect(lerpBNull25.side!.color, equals(Colors.black.withAlpha(0x3f))); expect(lerpBNull25.side!.color, equals(Colors.black.withAlpha(0x3f)));
expect(lerpBNull25.shape, isA<StadiumBorder>()); expect(lerpBNull25.shape, isA<StadiumBorder>());
expect(lerpBNull25.labelStyle?.color, equals(Colors.white.withAlpha(0xa7))); expect(lerpBNull25.labelStyle.color, equals(Colors.white.withAlpha(0xa7)));
expect(lerpBNull25.secondaryLabelStyle?.color, equals(Colors.black.withAlpha(0xa7))); expect(lerpBNull25.secondaryLabelStyle.color, equals(Colors.black.withAlpha(0xa7)));
expect(lerpBNull25.brightness, equals(Brightness.dark)); expect(lerpBNull25.brightness, equals(Brightness.dark));
expect(lerpBNull25.elevation, 0.75); expect(lerpBNull25.elevation, 0.75);
expect(lerpBNull25.pressElevation, 3.0); expect(lerpBNull25.pressElevation, 3.0);
...@@ -485,8 +348,8 @@ void main() { ...@@ -485,8 +348,8 @@ void main() {
expect(lerpBNull75.padding, equals(const EdgeInsets.all(1.0))); expect(lerpBNull75.padding, equals(const EdgeInsets.all(1.0)));
expect(lerpBNull75.side!.color, equals(Colors.black.withAlpha(0xbf))); expect(lerpBNull75.side!.color, equals(Colors.black.withAlpha(0xbf)));
expect(lerpBNull75.shape, isA<StadiumBorder>()); expect(lerpBNull75.shape, isA<StadiumBorder>());
expect(lerpBNull75.labelStyle?.color, equals(Colors.white.withAlpha(0x38))); expect(lerpBNull75.labelStyle.color, equals(Colors.white.withAlpha(0x38)));
expect(lerpBNull75.secondaryLabelStyle?.color, equals(Colors.black.withAlpha(0x38))); expect(lerpBNull75.secondaryLabelStyle.color, equals(Colors.black.withAlpha(0x38)));
expect(lerpBNull75.brightness, equals(Brightness.light)); expect(lerpBNull75.brightness, equals(Brightness.light));
expect(lerpBNull75.elevation, 0.25); expect(lerpBNull75.elevation, 0.25);
expect(lerpBNull75.pressElevation, 1.0); expect(lerpBNull75.pressElevation, 1.0);
...@@ -632,22 +495,20 @@ void main() { ...@@ -632,22 +495,20 @@ void main() {
BorderSide getBorderSide(Set<MaterialState> states) { BorderSide getBorderSide(Set<MaterialState> states) {
Color color = defaultColor; Color color = defaultColor;
if (states.contains(MaterialState.selected)) if (states.contains(MaterialState.selected))
color = selectedColor; color = selectedColor;
return BorderSide(color: color); return BorderSide(color: color);
} }
final ChipThemeData chipTheme = ChipThemeData.fromDefaults(
brightness: Brightness.light,
secondaryColor: Colors.blue,
labelStyle: const TextStyle(),
).copyWith(
side: _MaterialStateBorderSide(getBorderSide),
);
Widget chipWidget({ bool selected = false }) { Widget chipWidget({ bool selected = false }) {
return MaterialApp( return MaterialApp(
theme: ThemeData(chipTheme: chipTheme), theme: ThemeData(
chipTheme: ThemeData.light().chipTheme.copyWith(
side: _MaterialStateBorderSide(getBorderSide),
),
),
home: Scaffold( home: Scaffold(
body: ChoiceChip( body: ChoiceChip(
label: const Text('Chip'), label: const Text('Chip'),
...@@ -675,18 +536,13 @@ void main() { ...@@ -675,18 +536,13 @@ void main() {
return null; return null;
} }
final ChipThemeData chipTheme = ChipThemeData.fromDefaults(
brightness: Brightness.light,
secondaryColor: Colors.blue,
labelStyle: const TextStyle(),
).copyWith(
shape: _MaterialStateOutlinedBorder(getShape),
);
Widget chipWidget({ bool selected = false }) { Widget chipWidget({ bool selected = false }) {
return MaterialApp( return MaterialApp(
theme: ThemeData(chipTheme: chipTheme), theme: ThemeData(
chipTheme: ThemeData.light().chipTheme.copyWith(
shape: _MaterialStateOutlinedBorder(getShape),
),
),
home: Scaffold( home: Scaffold(
body: ChoiceChip( body: ChoiceChip(
label: const Text('Chip'), label: const Text('Chip'),
......
...@@ -51,6 +51,16 @@ void main() { ...@@ -51,6 +51,16 @@ void main() {
expect(darkTheme.primaryTextTheme.headline6!.color, typography.white.headline6!.color); expect(darkTheme.primaryTextTheme.headline6!.color, typography.white.headline6!.color);
}); });
test('Default chip label style gets a default bodyText1 if textTheme.bodyText1 is null', () {
const TextTheme noBodyText1TextTheme = TextTheme();
final ThemeData lightTheme = ThemeData(brightness: Brightness.light, textTheme: noBodyText1TextTheme);
final ThemeData darkTheme = ThemeData(brightness: Brightness.dark, textTheme: noBodyText1TextTheme);
final Typography typography = Typography.material2018(platform: lightTheme.platform);
expect(lightTheme.chipTheme.labelStyle.color, equals(typography.black.bodyText1!.color!.withAlpha(0xde)));
expect(darkTheme.chipTheme.labelStyle.color, equals(typography.white.bodyText1!.color!.withAlpha(0xde)));
});
test('Default icon theme contrasts with brightness', () { test('Default icon theme contrasts with brightness', () {
final ThemeData lightTheme = ThemeData(brightness: Brightness.light); final ThemeData lightTheme = ThemeData(brightness: Brightness.light);
final ThemeData darkTheme = ThemeData(brightness: Brightness.dark); final ThemeData darkTheme = ThemeData(brightness: Brightness.dark);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment