Commit 5f3b2d48 authored by Adam Barth's avatar Adam Barth

Add errorColor to ThemeData

That way folks can customize it if they want (and it makes the code a
bit more self-documenting).
parent 7faee3e1
...@@ -185,7 +185,7 @@ class _InputState extends State<Input> { ...@@ -185,7 +185,7 @@ class _InputState extends State<Input> {
double borderWidth = focused ? 2.0 : 1.0; double borderWidth = focused ? 2.0 : 1.0;
if (config.errorText != null) { if (config.errorText != null) {
borderColor = Colors.red[700]; borderColor = themeData.errorColor;
borderWidth = 2.0; borderWidth = 2.0;
if (!config.isDense) { if (!config.isDense) {
margin = const EdgeDims.only(bottom: 15.0); margin = const EdgeDims.only(bottom: 15.0);
...@@ -216,7 +216,7 @@ class _InputState extends State<Input> { ...@@ -216,7 +216,7 @@ class _InputState extends State<Input> {
)); ));
if (config.errorText != null && !config.isDense) { if (config.errorText != null && !config.isDense) {
TextStyle errorStyle = themeData.text.caption.copyWith(color: Colors.red[700]); TextStyle errorStyle = themeData.text.caption.copyWith(color: themeData.errorColor);
stackChildren.add(new Positioned( stackChildren.add(new Positioned(
left: 0.0, left: 0.0,
bottom: 0.0, bottom: 0.0,
......
...@@ -46,6 +46,7 @@ class ThemeData { ...@@ -46,6 +46,7 @@ class ThemeData {
this.indicatorColor, this.indicatorColor,
this.hintColor, this.hintColor,
this.hintOpacity, this.hintOpacity,
this.errorColor,
this.text, this.text,
this.primaryTextTheme, this.primaryTextTheme,
this.primaryIconTheme this.primaryIconTheme
...@@ -66,6 +67,7 @@ class ThemeData { ...@@ -66,6 +67,7 @@ class ThemeData {
assert(indicatorColor != null); assert(indicatorColor != null);
assert(hintColor != null); assert(hintColor != null);
assert(hintOpacity != null); assert(hintOpacity != null);
assert(errorColor != null);
assert(text != null); assert(text != null);
assert(primaryTextTheme != null); assert(primaryTextTheme != null);
assert(primaryIconTheme != null); assert(primaryIconTheme != null);
...@@ -88,6 +90,7 @@ class ThemeData { ...@@ -88,6 +90,7 @@ class ThemeData {
Color indicatorColor, Color indicatorColor,
Color hintColor, Color hintColor,
double hintOpacity, double hintOpacity,
Color errorColor,
TextTheme text, TextTheme text,
TextTheme primaryTextTheme, TextTheme primaryTextTheme,
IconThemeData primaryIconTheme IconThemeData primaryIconTheme
...@@ -108,6 +111,7 @@ class ThemeData { ...@@ -108,6 +111,7 @@ class ThemeData {
indicatorColor ??= accentColor == primaryColor ? Colors.white : accentColor; indicatorColor ??= accentColor == primaryColor ? Colors.white : accentColor;
hintColor ??= isDark ? const Color(0x42FFFFFF) : const Color(0x4C000000); hintColor ??= isDark ? const Color(0x42FFFFFF) : const Color(0x4C000000);
hintOpacity ??= hintColor != null ? hintColor.alpha / 0xFF : isDark ? 0.26 : 0.30; hintOpacity ??= hintColor != null ? hintColor.alpha / 0xFF : isDark ? 0.26 : 0.30;
errorColor ??= Colors.red[700];
text ??= isDark ? Typography.white : Typography.black; text ??= isDark ? Typography.white : Typography.black;
primaryTextTheme ??= primaryColorBrightness == ThemeBrightness.dark ? Typography.white : Typography.black; primaryTextTheme ??= primaryColorBrightness == ThemeBrightness.dark ? Typography.white : Typography.black;
primaryIconTheme ??= primaryColorBrightness == ThemeBrightness.dark ? const IconThemeData(color: IconThemeColor.white) : const IconThemeData(color: IconThemeColor.black); primaryIconTheme ??= primaryColorBrightness == ThemeBrightness.dark ? const IconThemeData(color: IconThemeColor.white) : const IconThemeData(color: IconThemeColor.black);
...@@ -128,6 +132,7 @@ class ThemeData { ...@@ -128,6 +132,7 @@ class ThemeData {
indicatorColor: indicatorColor, indicatorColor: indicatorColor,
hintColor: hintColor, hintColor: hintColor,
hintOpacity: hintOpacity, hintOpacity: hintOpacity,
errorColor: errorColor,
text: text, text: text,
primaryTextTheme: primaryTextTheme, primaryTextTheme: primaryTextTheme,
primaryIconTheme: primaryIconTheme primaryIconTheme: primaryIconTheme
...@@ -182,6 +187,9 @@ class ThemeData { ...@@ -182,6 +187,9 @@ class ThemeData {
final Color hintColor; final Color hintColor;
final double hintOpacity; final double hintOpacity;
/// The color to use for input validation errors.
final Color errorColor;
/// Text with a color that contrasts with the card and canvas colors. /// Text with a color that contrasts with the card and canvas colors.
final TextTheme text; final TextTheme text;
...@@ -217,6 +225,7 @@ class ThemeData { ...@@ -217,6 +225,7 @@ class ThemeData {
indicatorColor: Color.lerp(begin.indicatorColor, end.indicatorColor, t), indicatorColor: Color.lerp(begin.indicatorColor, end.indicatorColor, t),
hintColor: Color.lerp(begin.hintColor, end.hintColor, t), hintColor: Color.lerp(begin.hintColor, end.hintColor, t),
hintOpacity: lerpDouble(begin.hintOpacity, end.hintOpacity, t), hintOpacity: lerpDouble(begin.hintOpacity, end.hintOpacity, t),
errorColor: Color.lerp(begin.errorColor, end.errorColor, t),
text: TextTheme.lerp(begin.text, end.text, t), text: TextTheme.lerp(begin.text, end.text, t),
primaryTextTheme: TextTheme.lerp(begin.primaryTextTheme, end.primaryTextTheme, t), primaryTextTheme: TextTheme.lerp(begin.primaryTextTheme, end.primaryTextTheme, t),
primaryIconTheme: IconThemeData.lerp(begin.primaryIconTheme, end.primaryIconTheme, t) primaryIconTheme: IconThemeData.lerp(begin.primaryIconTheme, end.primaryIconTheme, t)
...@@ -243,6 +252,7 @@ class ThemeData { ...@@ -243,6 +252,7 @@ class ThemeData {
(otherData.indicatorColor == indicatorColor) && (otherData.indicatorColor == indicatorColor) &&
(otherData.hintColor == hintColor) && (otherData.hintColor == hintColor) &&
(otherData.hintOpacity == hintOpacity) && (otherData.hintOpacity == hintOpacity) &&
(otherData.errorColor == errorColor) &&
(otherData.text == text) && (otherData.text == text) &&
(otherData.primaryTextTheme == primaryTextTheme) && (otherData.primaryTextTheme == primaryTextTheme) &&
(otherData.primaryIconTheme == primaryIconTheme); (otherData.primaryIconTheme == primaryIconTheme);
...@@ -263,12 +273,15 @@ class ThemeData { ...@@ -263,12 +273,15 @@ class ThemeData {
disabledColor, disabledColor,
accentColor, accentColor,
accentColorBrightness, accentColorBrightness,
indicatorColor, hashValues( // Too many values.
hintColor, indicatorColor,
hintOpacity, hintColor,
text, hintOpacity,
primaryTextTheme, errorColor,
primaryIconTheme text,
primaryTextTheme,
primaryIconTheme
)
); );
} }
......
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