Chip theme label style is merged with the provided label style (#70687)

This commit is contained in:
David Martos
2020-12-09 20:28:05 +01:00
committed by GitHub
parent d553aa06c7
commit 56716f61a2
2 changed files with 27 additions and 1 deletions

View File

@@ -1929,7 +1929,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
final Color? checkmarkColor = widget.checkmarkColor ?? chipTheme.checkmarkColor;
final bool showCheckmark = widget.showCheckmark ?? chipTheme.showCheckmark ?? true;
final TextStyle effectiveLabelStyle = widget.labelStyle ?? chipTheme.labelStyle;
final TextStyle effectiveLabelStyle = chipTheme.labelStyle.merge(widget.labelStyle);
final Color? resolvedLabelColor = MaterialStateProperty.resolveAs<Color?>(effectiveLabelStyle.color, _states);
final TextStyle resolvedLabelStyle = effectiveLabelStyle.copyWith(color: resolvedLabelColor);
final EdgeInsetsGeometry labelPadding = widget.labelPadding ?? chipTheme.labelPadding ?? _defaultLabelPadding;

View File

@@ -1440,6 +1440,32 @@ void main() {
expect(materialBox, paints..path(color: chipTheme.disabledColor));
});
testWidgets('Chip merges ChipThemeData label style with the provided label style', (WidgetTester tester) async {
// The font family should be preserved even if the chip overrides some label style properties
final ThemeData theme = ThemeData(
fontFamily: 'MyFont'
);
Widget buildChip() {
return _wrapForChip(
textDirection: TextDirection.ltr,
child: Theme(
data: theme,
child: const Chip(
label: Text('Label'),
labelStyle: TextStyle(fontWeight: FontWeight.w200),
),
),
);
}
await tester.pumpWidget(buildChip());
final TextStyle labelStyle = getLabelStyle(tester).style;
expect(labelStyle.fontFamily, 'MyFont');
expect(labelStyle.fontWeight, FontWeight.w200);
});
testWidgets('Chip size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
final Key key1 = UniqueKey();
await tester.pumpWidget(