Unverified Commit c8f867b5 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Chip theme cleanup (#106384)

- Added complete support for showCheckmark to ChipThemeData.
- Removed build method checks for ThemeData.chipTheme, as that is
  already handled by ChipTheme.of().
parent ac8329ae
...@@ -1094,10 +1094,6 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1094,10 +1094,6 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
); );
} }
static const double _defaultElevation = 0.0;
static const double _defaultPressElevation = 8.0;
static const Color _defaultShadowColor = Colors.black;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context)); assert(debugCheckHasMaterial(context));
...@@ -1128,37 +1124,31 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid ...@@ -1128,37 +1124,31 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
final double elevation = widget.elevation final double elevation = widget.elevation
?? chipTheme.elevation ?? chipTheme.elevation
?? theme.chipTheme.elevation ?? chipDefaults.elevation!;
?? _defaultElevation;
final double pressElevation = widget.pressElevation final double pressElevation = widget.pressElevation
?? chipTheme.pressElevation ?? chipTheme.pressElevation
?? theme.chipTheme.pressElevation ?? chipDefaults.pressElevation!;
?? _defaultPressElevation;
final Color shadowColor = widget.shadowColor final Color shadowColor = widget.shadowColor
?? chipTheme.shadowColor ?? chipTheme.shadowColor
?? theme.chipTheme.shadowColor ?? chipDefaults.shadowColor!;
?? _defaultShadowColor;
final Color selectedShadowColor = widget.selectedShadowColor final Color selectedShadowColor = widget.selectedShadowColor
?? chipTheme.selectedShadowColor ?? chipTheme.selectedShadowColor
?? theme.chipTheme.selectedShadowColor ?? chipDefaults.selectedShadowColor!;
?? _defaultShadowColor;
final Color? checkmarkColor = widget.checkmarkColor final Color? checkmarkColor = widget.checkmarkColor
?? chipTheme.checkmarkColor ?? chipTheme.checkmarkColor
?? theme.chipTheme.checkmarkColor; ?? chipDefaults.checkmarkColor;
final bool showCheckmark = widget.showCheckmark final bool showCheckmark = widget.showCheckmark
?? chipTheme.showCheckmark ?? chipTheme.showCheckmark
?? theme.chipTheme.showCheckmark ?? chipDefaults.showCheckmark!;
?? true;
final EdgeInsetsGeometry padding = widget.padding final EdgeInsetsGeometry padding = widget.padding
?? chipTheme.padding ?? chipTheme.padding
?? theme.chipTheme.padding
?? chipDefaults.padding!; ?? chipDefaults.padding!;
// Widget's label style is merged with this below.
final TextStyle labelStyle = chipTheme.labelStyle final TextStyle labelStyle = chipTheme.labelStyle
?? theme.chipTheme.labelStyle
?? chipDefaults.labelStyle!; ?? chipDefaults.labelStyle!;
final EdgeInsetsGeometry labelPadding = widget.labelPadding final EdgeInsetsGeometry labelPadding = widget.labelPadding
?? chipTheme.labelPadding ?? chipTheme.labelPadding
?? theme.chipTheme.labelPadding ?? chipDefaults.labelPadding
?? defaultLabelPadding; ?? defaultLabelPadding;
final TextStyle effectiveLabelStyle = labelStyle.merge(widget.labelStyle); final TextStyle effectiveLabelStyle = labelStyle.merge(widget.labelStyle);
......
...@@ -256,10 +256,15 @@ class ChipThemeData with Diagnosticable { ...@@ -256,10 +256,15 @@ class ChipThemeData with Diagnosticable {
disabledColor: disabledColor, disabledColor: disabledColor,
selectedColor: selectedColor, selectedColor: selectedColor,
secondarySelectedColor: secondarySelectedColor, secondarySelectedColor: secondarySelectedColor,
shadowColor: Colors.black,
selectedShadowColor: Colors.black,
showCheckmark: true,
padding: padding, padding: padding,
labelStyle: labelStyle, labelStyle: labelStyle,
secondaryLabelStyle: secondaryLabelStyle, secondaryLabelStyle: secondaryLabelStyle,
brightness: brightness, brightness: brightness,
elevation: 0.0,
pressElevation: 8.0,
); );
} }
...@@ -420,6 +425,7 @@ class ChipThemeData with Diagnosticable { ...@@ -420,6 +425,7 @@ class ChipThemeData with Diagnosticable {
Color? secondarySelectedColor, Color? secondarySelectedColor,
Color? shadowColor, Color? shadowColor,
Color? selectedShadowColor, Color? selectedShadowColor,
bool? showCheckmark,
Color? checkmarkColor, Color? checkmarkColor,
EdgeInsetsGeometry? labelPadding, EdgeInsetsGeometry? labelPadding,
EdgeInsetsGeometry? padding, EdgeInsetsGeometry? padding,
...@@ -439,6 +445,7 @@ class ChipThemeData with Diagnosticable { ...@@ -439,6 +445,7 @@ class ChipThemeData with Diagnosticable {
secondarySelectedColor: secondarySelectedColor ?? this.secondarySelectedColor, secondarySelectedColor: secondarySelectedColor ?? this.secondarySelectedColor,
shadowColor: shadowColor ?? this.shadowColor, shadowColor: shadowColor ?? this.shadowColor,
selectedShadowColor: selectedShadowColor ?? this.selectedShadowColor, selectedShadowColor: selectedShadowColor ?? this.selectedShadowColor,
showCheckmark: showCheckmark ?? this.showCheckmark,
checkmarkColor: checkmarkColor ?? this.checkmarkColor, checkmarkColor: checkmarkColor ?? this.checkmarkColor,
labelPadding: labelPadding ?? this.labelPadding, labelPadding: labelPadding ?? this.labelPadding,
padding: padding ?? this.padding, padding: padding ?? this.padding,
...@@ -470,6 +477,7 @@ class ChipThemeData with Diagnosticable { ...@@ -470,6 +477,7 @@ class ChipThemeData with Diagnosticable {
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),
showCheckmark: t < 0.5 ? a?.showCheckmark ?? true : b?.showCheckmark ?? true,
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),
...@@ -514,6 +522,7 @@ class ChipThemeData with Diagnosticable { ...@@ -514,6 +522,7 @@ class ChipThemeData with Diagnosticable {
secondarySelectedColor, secondarySelectedColor,
shadowColor, shadowColor,
selectedShadowColor, selectedShadowColor,
showCheckmark,
checkmarkColor, checkmarkColor,
labelPadding, labelPadding,
padding, padding,
...@@ -542,6 +551,7 @@ class ChipThemeData with Diagnosticable { ...@@ -542,6 +551,7 @@ class ChipThemeData with Diagnosticable {
&& other.secondarySelectedColor == secondarySelectedColor && other.secondarySelectedColor == secondarySelectedColor
&& other.shadowColor == shadowColor && other.shadowColor == shadowColor
&& other.selectedShadowColor == selectedShadowColor && other.selectedShadowColor == selectedShadowColor
&& other.showCheckmark == showCheckmark
&& other.checkmarkColor == checkmarkColor && other.checkmarkColor == checkmarkColor
&& other.labelPadding == labelPadding && other.labelPadding == labelPadding
&& other.padding == padding && other.padding == padding
...@@ -564,6 +574,7 @@ class ChipThemeData with Diagnosticable { ...@@ -564,6 +574,7 @@ class ChipThemeData with Diagnosticable {
properties.add(ColorProperty('secondarySelectedColor', secondarySelectedColor, defaultValue: null)); properties.add(ColorProperty('secondarySelectedColor', secondarySelectedColor, defaultValue: null));
properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null)); properties.add(ColorProperty('shadowColor', shadowColor, defaultValue: null));
properties.add(ColorProperty('selectedShadowColor', selectedShadowColor, defaultValue: null)); properties.add(ColorProperty('selectedShadowColor', selectedShadowColor, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('showCheckmark', showCheckmark, defaultValue: null));
properties.add(ColorProperty('checkMarkColor', checkmarkColor, defaultValue: null)); properties.add(ColorProperty('checkMarkColor', checkmarkColor, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('labelPadding', labelPadding, defaultValue: null)); properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('labelPadding', labelPadding, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null)); properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: null));
......
...@@ -112,6 +112,7 @@ void main() { ...@@ -112,6 +112,7 @@ void main() {
'secondarySelectedColor: Color(0xfffffff4)', 'secondarySelectedColor: Color(0xfffffff4)',
'shadowColor: Color(0xfffffff5)', 'shadowColor: Color(0xfffffff5)',
'selectedShadowColor: Color(0xfffffff6)', 'selectedShadowColor: Color(0xfffffff6)',
'showCheckmark: true',
'checkMarkColor: Color(0xfffffff7)', 'checkMarkColor: Color(0xfffffff7)',
'labelPadding: EdgeInsets.all(1.0)', 'labelPadding: EdgeInsets.all(1.0)',
'padding: EdgeInsets.all(2.0)', 'padding: EdgeInsets.all(2.0)',
...@@ -268,25 +269,54 @@ void main() { ...@@ -268,25 +269,54 @@ void main() {
}); });
testWidgets('ChipTheme.fromDefaults', (WidgetTester tester) async { testWidgets('ChipTheme.fromDefaults', (WidgetTester tester) async {
const TextStyle labelStyle = TextStyle();
ChipThemeData chipTheme = ChipThemeData.fromDefaults( ChipThemeData chipTheme = ChipThemeData.fromDefaults(
brightness: Brightness.light, brightness: Brightness.light,
secondaryColor: Colors.red, secondaryColor: Colors.red,
labelStyle: const TextStyle(), labelStyle: labelStyle,
); );
expect(chipTheme.backgroundColor, equals(Colors.black.withAlpha(0x1f))); expect(chipTheme.backgroundColor, Colors.black.withAlpha(0x1f));
expect(chipTheme.selectedColor, equals(Colors.black.withAlpha(0x3d))); expect(chipTheme.deleteIconColor, Colors.black.withAlpha(0xde));
expect(chipTheme.secondarySelectedColor, equals(Colors.red.withAlpha(0x3d))); expect(chipTheme.disabledColor, Colors.black.withAlpha(0x0c));
expect(chipTheme.deleteIconColor, equals(Colors.black.withAlpha(0xde))); expect(chipTheme.selectedColor, Colors.black.withAlpha(0x3d));
expect(chipTheme.secondarySelectedColor, Colors.red.withAlpha(0x3d));
expect(chipTheme.shadowColor, Colors.black);
expect(chipTheme.selectedShadowColor, Colors.black);
expect(chipTheme.showCheckmark, true);
expect(chipTheme.checkmarkColor, null);
expect(chipTheme.labelPadding, null);
expect(chipTheme.padding, const EdgeInsets.all(4.0));
expect(chipTheme.side, null);
expect(chipTheme.shape, null);
expect(chipTheme.labelStyle, labelStyle.copyWith(color: Colors.black.withAlpha(0xde)));
expect(chipTheme.secondaryLabelStyle, labelStyle.copyWith(color: Colors.red.withAlpha(0xde)));
expect(chipTheme.brightness, Brightness.light);
expect(chipTheme.elevation, 0.0);
expect(chipTheme.pressElevation, 8.0);
chipTheme = ChipThemeData.fromDefaults( chipTheme = ChipThemeData.fromDefaults(
brightness: Brightness.dark, brightness: Brightness.dark,
secondaryColor: Colors.tealAccent[200]!, secondaryColor: Colors.tealAccent[200]!,
labelStyle: const TextStyle(), labelStyle: const TextStyle(),
); );
expect(chipTheme.backgroundColor, equals(Colors.white.withAlpha(0x1f))); expect(chipTheme.backgroundColor, Colors.white.withAlpha(0x1f));
expect(chipTheme.selectedColor, equals(Colors.white.withAlpha(0x3d))); expect(chipTheme.deleteIconColor, Colors.white.withAlpha(0xde));
expect(chipTheme.secondarySelectedColor, equals(Colors.tealAccent[200]!.withAlpha(0x3d))); expect(chipTheme.disabledColor, Colors.white.withAlpha(0x0c));
expect(chipTheme.deleteIconColor, equals(Colors.white.withAlpha(0xde))); expect(chipTheme.selectedColor, Colors.white.withAlpha(0x3d));
expect(chipTheme.secondarySelectedColor, Colors.tealAccent[200]!.withAlpha(0x3d));
expect(chipTheme.shadowColor, Colors.black);
expect(chipTheme.selectedShadowColor, Colors.black);
expect(chipTheme.showCheckmark, true);
expect(chipTheme.checkmarkColor, null);
expect(chipTheme.labelPadding, null);
expect(chipTheme.padding, const EdgeInsets.all(4.0));
expect(chipTheme.side, null);
expect(chipTheme.shape, null);
expect(chipTheme.labelStyle, labelStyle.copyWith(color: Colors.white.withAlpha(0xde)));
expect(chipTheme.secondaryLabelStyle, labelStyle.copyWith(color: Colors.tealAccent[200]!.withAlpha(0xde)));
expect(chipTheme.brightness, Brightness.dark);
expect(chipTheme.elevation, 0.0);
expect(chipTheme.pressElevation, 8.0);
}); });
...@@ -366,6 +396,7 @@ void main() { ...@@ -366,6 +396,7 @@ void main() {
pressElevation: 4.0, pressElevation: 4.0,
shadowColor: Colors.black, shadowColor: Colors.black,
selectedShadowColor: Colors.black, selectedShadowColor: Colors.black,
showCheckmark: false,
checkmarkColor: Colors.black, checkmarkColor: Colors.black,
); );
final ChipThemeData chipThemeWhite = ChipThemeData.fromDefaults( final ChipThemeData chipThemeWhite = ChipThemeData.fromDefaults(
...@@ -381,6 +412,7 @@ void main() { ...@@ -381,6 +412,7 @@ void main() {
pressElevation: 10.0, pressElevation: 10.0,
shadowColor: Colors.white, shadowColor: Colors.white,
selectedShadowColor: Colors.white, selectedShadowColor: Colors.white,
showCheckmark: true,
checkmarkColor: Colors.white, checkmarkColor: Colors.white,
); );
...@@ -393,6 +425,7 @@ void main() { ...@@ -393,6 +425,7 @@ void main() {
expect(lerp.secondarySelectedColor, equals(middleGrey.withAlpha(0x3d))); expect(lerp.secondarySelectedColor, equals(middleGrey.withAlpha(0x3d)));
expect(lerp.shadowColor, equals(middleGrey)); expect(lerp.shadowColor, equals(middleGrey));
expect(lerp.selectedShadowColor, equals(middleGrey)); expect(lerp.selectedShadowColor, equals(middleGrey));
expect(lerp.showCheckmark, equals(true));
expect(lerp.labelPadding, equals(const EdgeInsets.all(4.0))); expect(lerp.labelPadding, equals(const EdgeInsets.all(4.0)));
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));
...@@ -414,6 +447,7 @@ void main() { ...@@ -414,6 +447,7 @@ void main() {
expect(lerpANull25.secondarySelectedColor, equals(Colors.white.withAlpha(0x0f))); expect(lerpANull25.secondarySelectedColor, equals(Colors.white.withAlpha(0x0f)));
expect(lerpANull25.shadowColor, equals(Colors.white.withAlpha(0x40))); expect(lerpANull25.shadowColor, equals(Colors.white.withAlpha(0x40)));
expect(lerpANull25.selectedShadowColor, equals(Colors.white.withAlpha(0x40))); expect(lerpANull25.selectedShadowColor, equals(Colors.white.withAlpha(0x40)));
expect(lerpANull25.showCheckmark, equals(true));
expect(lerpANull25.labelPadding, equals(const EdgeInsets.only(top: 2.0, bottom: 2.0))); expect(lerpANull25.labelPadding, equals(const EdgeInsets.only(top: 2.0, bottom: 2.0)));
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)));
...@@ -433,6 +467,7 @@ void main() { ...@@ -433,6 +467,7 @@ void main() {
expect(lerpANull75.secondarySelectedColor, equals(Colors.white.withAlpha(0x2e))); expect(lerpANull75.secondarySelectedColor, equals(Colors.white.withAlpha(0x2e)));
expect(lerpANull75.shadowColor, equals(Colors.white.withAlpha(0xbf))); expect(lerpANull75.shadowColor, equals(Colors.white.withAlpha(0xbf)));
expect(lerpANull75.selectedShadowColor, equals(Colors.white.withAlpha(0xbf))); expect(lerpANull75.selectedShadowColor, equals(Colors.white.withAlpha(0xbf)));
expect(lerpANull75.showCheckmark, equals(true));
expect(lerpANull75.labelPadding, equals(const EdgeInsets.only(top: 6.0, bottom: 6.0))); expect(lerpANull75.labelPadding, equals(const EdgeInsets.only(top: 6.0, bottom: 6.0)));
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)));
...@@ -452,6 +487,7 @@ void main() { ...@@ -452,6 +487,7 @@ void main() {
expect(lerpBNull25.secondarySelectedColor, equals(Colors.black.withAlpha(0x2e))); expect(lerpBNull25.secondarySelectedColor, equals(Colors.black.withAlpha(0x2e)));
expect(lerpBNull25.shadowColor, equals(Colors.black.withAlpha(0xbf))); expect(lerpBNull25.shadowColor, equals(Colors.black.withAlpha(0xbf)));
expect(lerpBNull25.selectedShadowColor, equals(Colors.black.withAlpha(0xbf))); expect(lerpBNull25.selectedShadowColor, equals(Colors.black.withAlpha(0xbf)));
expect(lerpBNull25.showCheckmark, equals(false));
expect(lerpBNull25.labelPadding, equals(const EdgeInsets.only(left: 6.0, right: 6.0))); expect(lerpBNull25.labelPadding, equals(const EdgeInsets.only(left: 6.0, right: 6.0)));
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)));
...@@ -471,6 +507,7 @@ void main() { ...@@ -471,6 +507,7 @@ void main() {
expect(lerpBNull75.secondarySelectedColor, equals(Colors.black.withAlpha(0x0f))); expect(lerpBNull75.secondarySelectedColor, equals(Colors.black.withAlpha(0x0f)));
expect(lerpBNull75.shadowColor, equals(Colors.black.withAlpha(0x40))); expect(lerpBNull75.shadowColor, equals(Colors.black.withAlpha(0x40)));
expect(lerpBNull75.selectedShadowColor, equals(Colors.black.withAlpha(0x40))); expect(lerpBNull75.selectedShadowColor, equals(Colors.black.withAlpha(0x40)));
expect(lerpBNull75.showCheckmark, equals(true));
expect(lerpBNull75.labelPadding, equals(const EdgeInsets.only(left: 2.0, right: 2.0))); expect(lerpBNull75.labelPadding, equals(const EdgeInsets.only(left: 2.0, right: 2.0)));
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)));
......
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