Unverified Commit 4dbbf678 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Adding ChipTheme, ChipThemeData, and some more tests. (#16447)

This converts the chips to use a ChipThemeData to get most of their customization values from (if not overridden by specific arguments to the chip constructors), and to have the base ThemeData contain one of these. It also adds the ChipTheme widget that will allow overriding the theme for a particular subtree in the widget hierarchy.

Added tests for both, and just more tests in general for the Chips.
parent c31706f9
......@@ -30,6 +30,7 @@ export 'src/material/card.dart';
export 'src/material/checkbox.dart';
export 'src/material/checkbox_list_tile.dart';
export 'src/material/chip.dart';
export 'src/material/chip_theme.dart';
export 'src/material/circle_avatar.dart';
export 'src/material/colors.dart';
export 'src/material/constants.dart';
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'button_theme.dart';
import 'chip_theme.dart';
import 'colors.dart';
import 'ink_splash.dart';
import 'ink_well.dart' show InteractiveInkFeatureFactory;
......@@ -113,6 +114,7 @@ class ThemeData extends Diagnosticable {
IconThemeData primaryIconTheme,
IconThemeData accentIconTheme,
SliderThemeData sliderTheme,
ChipThemeData chipTheme,
TargetPlatform platform,
}) {
brightness ??= Brightness.light;
......@@ -168,6 +170,11 @@ class ThemeData extends Diagnosticable {
primaryColorDark: primaryColorDark,
valueIndicatorTextStyle: accentTextTheme.body2,
);
chipTheme ??= new ChipThemeData.fromDefaults(
secondaryColor: primaryColor,
brightness: brightness,
labelStyle: textTheme.body2,
);
return new ThemeData.raw(
brightness: brightness,
primaryColor: primaryColor,
......@@ -205,6 +212,7 @@ class ThemeData extends Diagnosticable {
primaryIconTheme: primaryIconTheme,
accentIconTheme: accentIconTheme,
sliderTheme: sliderTheme,
chipTheme: chipTheme,
platform: platform,
);
}
......@@ -252,6 +260,7 @@ class ThemeData extends Diagnosticable {
@required this.primaryIconTheme,
@required this.accentIconTheme,
@required this.sliderTheme,
@required this.chipTheme,
@required this.platform,
}) : assert(brightness != null),
assert(primaryColor != null),
......@@ -287,7 +296,8 @@ class ThemeData extends Diagnosticable {
assert(iconTheme != null),
assert(primaryIconTheme != null),
assert(accentIconTheme != null),
assert(sliderTheme != null),
assert(sliderTheme != null),
assert(chipTheme != null),
assert(platform != null);
/// A default light blue theme.
......@@ -463,6 +473,11 @@ class ThemeData extends Diagnosticable {
/// This is the value returned from [SliderTheme.of].
final SliderThemeData sliderTheme;
/// The colors and styles used to render [Chip], [
///
/// This is the value returned from [ChipTheme.of].
final ChipThemeData chipTheme;
/// The platform the material widgets should adapt to target.
///
/// Defaults to the current platform.
......@@ -506,6 +521,7 @@ class ThemeData extends Diagnosticable {
IconThemeData primaryIconTheme,
IconThemeData accentIconTheme,
SliderThemeData sliderTheme,
ChipThemeData chipTheme,
TargetPlatform platform,
}) {
return new ThemeData.raw(
......@@ -545,6 +561,7 @@ class ThemeData extends Diagnosticable {
primaryIconTheme: primaryIconTheme ?? this.primaryIconTheme,
accentIconTheme: accentIconTheme ?? this.accentIconTheme,
sliderTheme: sliderTheme ?? this.sliderTheme,
chipTheme: chipTheme ?? this.chipTheme,
platform: platform ?? this.platform,
);
}
......@@ -670,6 +687,7 @@ class ThemeData extends Diagnosticable {
primaryIconTheme: IconThemeData.lerp(a.primaryIconTheme, b.primaryIconTheme, t),
accentIconTheme: IconThemeData.lerp(a.accentIconTheme, b.accentIconTheme, t),
sliderTheme: SliderThemeData.lerp(a.sliderTheme, b.sliderTheme, t),
chipTheme: ChipThemeData.lerp(a.chipTheme, b.chipTheme, t),
platform: t < 0.5 ? a.platform : b.platform,
);
}
......@@ -713,6 +731,7 @@ class ThemeData extends Diagnosticable {
(otherData.primaryIconTheme == primaryIconTheme) &&
(otherData.accentIconTheme == accentIconTheme) &&
(otherData.sliderTheme == sliderTheme) &&
(otherData.chipTheme == chipTheme) &&
(otherData.platform == platform);
}
......@@ -754,6 +773,7 @@ class ThemeData extends Diagnosticable {
primaryIconTheme,
accentIconTheme,
sliderTheme,
chipTheme,
platform,
),
);
......@@ -797,6 +817,7 @@ class ThemeData extends Diagnosticable {
properties.add(new DiagnosticsProperty<IconThemeData>('primaryIconTheme', primaryIconTheme));
properties.add(new DiagnosticsProperty<IconThemeData>('accentIconTheme', accentIconTheme));
properties.add(new DiagnosticsProperty<SliderThemeData>('sliderTheme', sliderTheme));
properties.add(new DiagnosticsProperty<ChipThemeData>('chipTheme', chipTheme));
}
}
......
......@@ -504,17 +504,58 @@ class TextStyle extends Diagnosticable {
/// Values for `t` are usually obtained from an [Animation<double>], such as
/// an [AnimationController].
static TextStyle lerp(TextStyle a, TextStyle b, double t) {
assert(a != null);
assert(b != null);
assert(t != null);
assert(a.inherit == b.inherit);
assert(a == null || b == null || a.inherit == b.inherit);
if (a == null && b == null) {
return null;
}
String lerpDebugLabel;
assert(() {
lerpDebugLabel = 'lerp(${a.debugLabel ?? _kDefaultDebugLabel}${t.toStringAsFixed(1)}${b.debugLabel ?? _kDefaultDebugLabel})';
lerpDebugLabel = 'lerp(${a?.debugLabel ?? _kDefaultDebugLabel}${t.toStringAsFixed(1)}${b?.debugLabel ?? _kDefaultDebugLabel})';
return true;
}());
if (a == null) {
return new TextStyle(
inherit: b.inherit,
color: Color.lerp(null, b.color, t),
fontFamily: t < 0.5 ? null : b.fontFamily,
fontSize: t < 0.5 ? null : b.fontSize,
fontWeight: FontWeight.lerp(null, b.fontWeight, t),
fontStyle: t < 0.5 ? null : b.fontStyle,
letterSpacing: t < 0.5 ? null : b.letterSpacing,
wordSpacing: t < 0.5 ? null : b.wordSpacing,
textBaseline: t < 0.5 ? null : b.textBaseline,
height: t < 0.5 ? null : b.height,
locale: t < 0.5 ? null : b.locale,
decoration: t < 0.5 ? null : b.decoration,
decorationColor: Color.lerp(null, b.decorationColor, t),
decorationStyle: t < 0.5 ? null : b.decorationStyle,
debugLabel: lerpDebugLabel,
);
}
if (b == null) {
return new TextStyle(
inherit: a.inherit,
color: Color.lerp(a.color, null, t),
fontFamily: t < 0.5 ? a.fontFamily : null,
fontSize: t < 0.5 ? a.fontSize : null,
fontWeight: FontWeight.lerp(a.fontWeight, null, t),
fontStyle: t < 0.5 ? a.fontStyle : null,
letterSpacing: t < 0.5 ? a.letterSpacing : null,
wordSpacing: t < 0.5 ? a.wordSpacing : null,
textBaseline: t < 0.5 ? a.textBaseline : null,
height: t < 0.5 ? a.height : null,
locale: t < 0.5 ? a.locale : null,
decoration: t < 0.5 ? a.decoration : null,
decorationColor: Color.lerp(a.decorationColor, null, t),
decorationStyle: t < 0.5 ? a.decorationStyle : null,
debugLabel: lerpDebugLabel,
);
}
return new TextStyle(
inherit: b.inherit,
color: Color.lerp(a.color, b.color, t),
......
This diff is collapsed.
......@@ -100,7 +100,7 @@ void main() {
expect(sliderBox, paints..rect(color: customTheme.disabledActiveRailColor)..rect(color: customTheme.disabledInactiveRailColor));
});
testWidgets('SliderThemeData generates correct opacities for materialDefaults', (WidgetTester tester) async {
testWidgets('SliderThemeData generates correct opacities for fromPrimaryColors', (WidgetTester tester) async {
const Color customColor1 = const Color(0xcafefeed);
const Color customColor2 = const Color(0xdeadbeef);
const Color customColor3 = const Color(0xdecaface);
......
......@@ -107,6 +107,60 @@ void main() {
expect(s5.height, 123.0);
expect(s5.color, isNull);
expect(TextStyle.lerp(null, null, 0.5), isNull);
final TextStyle s6 = TextStyle.lerp(null, s3, 0.25);
expect(s3.fontFamily, isNull);
expect(s3.fontSize, 18.0);
expect(s3.fontWeight, FontWeight.w400);
expect(s3.height, 123.0);
expect(s3.color, isNull);
expect(s3, isNot(equals(s6)));
expect(s6.fontFamily, isNull);
expect(s6.fontSize, isNull);
expect(s6.fontWeight, FontWeight.w400);
expect(s6.height, isNull);
expect(s6.color, isNull);
final TextStyle s7 = TextStyle.lerp(null, s3, 0.75);
expect(s3.fontFamily, isNull);
expect(s3.fontSize, 18.0);
expect(s3.fontWeight, FontWeight.w400);
expect(s3.height, 123.0);
expect(s3.color, isNull);
expect(s3, equals(s7));
expect(s7.fontFamily, isNull);
expect(s7.fontSize, 18.0);
expect(s7.fontWeight, FontWeight.w400);
expect(s7.height, 123.0);
expect(s7.color, isNull);
final TextStyle s8 = TextStyle.lerp(s3, null, 0.25);
expect(s3.fontFamily, isNull);
expect(s3.fontSize, 18.0);
expect(s3.fontWeight, FontWeight.w400);
expect(s3.height, 123.0);
expect(s3.color, isNull);
expect(s3, equals(s8));
expect(s8.fontFamily, isNull);
expect(s8.fontSize, 18.0);
expect(s8.fontWeight, FontWeight.w400);
expect(s8.height, 123.0);
expect(s8.color, isNull);
final TextStyle s9 = TextStyle.lerp(s3, null, 0.75);
expect(s3.fontFamily, isNull);
expect(s3.fontSize, 18.0);
expect(s3.fontWeight, FontWeight.w400);
expect(s3.height, 123.0);
expect(s3.color, isNull);
expect(s3, isNot(equals(s9)));
expect(s9.fontFamily, isNull);
expect(s9.fontSize, isNull);
expect(s9.fontWeight, FontWeight.w400);
expect(s9.height, isNull);
expect(s9.color, isNull);
final ui.TextStyle ts5 = s5.getTextStyle();
expect(ts5, equals(new ui.TextStyle(fontWeight: FontWeight.w700, fontSize: 12.0, height: 123.0)));
expect(ts5.toString(), 'TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, fontWeight: FontWeight.w700, fontStyle: unspecified, textBaseline: unspecified, fontFamily: unspecified, fontSize: 12.0, letterSpacing: unspecified, wordSpacing: unspecified, height: 123.0x, locale: unspecified)');
......
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