Commit 500981fe authored by lequem's avatar lequem Committed by Adam Barth

make dialog background color configurable (#7320) (#7323)

parent 2bb93db2
...@@ -13,3 +13,4 @@ Raju Bitter <rajubitter@gmail.com> ...@@ -13,3 +13,4 @@ Raju Bitter <rajubitter@gmail.com>
Michael Beckler <mcbeckler@gmail.com> Michael Beckler <mcbeckler@gmail.com>
Alexandre Ardhuin <alexandre.ardhuin@gmail.com> Alexandre Ardhuin <alexandre.ardhuin@gmail.com>
Luke Freeman <luke@goposse.com> Luke Freeman <luke@goposse.com>
Vincent Le Quéméner <eu.lequem@gmail.com>
...@@ -37,15 +37,7 @@ class Dialog extends StatelessWidget { ...@@ -37,15 +37,7 @@ class Dialog extends StatelessWidget {
final Widget child; final Widget child;
Color _getColor(BuildContext context) { Color _getColor(BuildContext context) {
Brightness brightness = Theme.of(context).brightness; return Theme.of(context).dialogBackgroundColor;
assert(brightness != null);
switch (brightness) {
case Brightness.light:
return Colors.white;
case Brightness.dark:
return Colors.grey[800];
}
return null;
} }
@override @override
......
...@@ -89,6 +89,7 @@ class ThemeData { ...@@ -89,6 +89,7 @@ class ThemeData {
Color textSelectionColor, Color textSelectionColor,
Color textSelectionHandleColor, Color textSelectionHandleColor,
Color backgroundColor, Color backgroundColor,
Color dialogBackgroundColor,
Color indicatorColor, Color indicatorColor,
Color hintColor, Color hintColor,
Color errorColor, Color errorColor,
...@@ -124,6 +125,7 @@ class ThemeData { ...@@ -124,6 +125,7 @@ class ThemeData {
textSelectionColor ??= isDark ? accentColor : primarySwatch[200]; textSelectionColor ??= isDark ? accentColor : primarySwatch[200];
textSelectionHandleColor ??= isDark ? Colors.tealAccent[400] : primarySwatch[300]; textSelectionHandleColor ??= isDark ? Colors.tealAccent[400] : primarySwatch[300];
backgroundColor ??= isDark ? Colors.grey[700] : primarySwatch[200]; backgroundColor ??= isDark ? Colors.grey[700] : primarySwatch[200];
dialogBackgroundColor ??= isDark ? Colors.grey[800] : Colors.white;
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);
errorColor ??= Colors.red[700]; errorColor ??= Colors.red[700];
...@@ -155,6 +157,7 @@ class ThemeData { ...@@ -155,6 +157,7 @@ class ThemeData {
textSelectionColor: textSelectionColor, textSelectionColor: textSelectionColor,
textSelectionHandleColor: textSelectionHandleColor, textSelectionHandleColor: textSelectionHandleColor,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
dialogBackgroundColor: dialogBackgroundColor,
indicatorColor: indicatorColor, indicatorColor: indicatorColor,
hintColor: hintColor, hintColor: hintColor,
errorColor: errorColor, errorColor: errorColor,
...@@ -194,6 +197,7 @@ class ThemeData { ...@@ -194,6 +197,7 @@ class ThemeData {
this.textSelectionColor, this.textSelectionColor,
this.textSelectionHandleColor, this.textSelectionHandleColor,
this.backgroundColor, this.backgroundColor,
this.dialogBackgroundColor,
this.indicatorColor, this.indicatorColor,
this.hintColor, this.hintColor,
this.errorColor, this.errorColor,
...@@ -212,6 +216,7 @@ class ThemeData { ...@@ -212,6 +216,7 @@ class ThemeData {
assert(accentColorBrightness != null); assert(accentColorBrightness != null);
assert(canvasColor != null); assert(canvasColor != null);
assert(scaffoldBackgroundColor != null); assert(scaffoldBackgroundColor != null);
assert(dialogBackgroundColor != null);
assert(cardColor != null); assert(cardColor != null);
assert(dividerColor != null); assert(dividerColor != null);
assert(highlightColor != null); assert(highlightColor != null);
...@@ -327,6 +332,9 @@ class ThemeData { ...@@ -327,6 +332,9 @@ class ThemeData {
/// remaining part of a progress bar. /// remaining part of a progress bar.
final Color backgroundColor; final Color backgroundColor;
/// The background color of [Dialog] elements.
final Color dialogBackgroundColor;
/// The color of the selected tab indicator in a tab bar. /// The color of the selected tab indicator in a tab bar.
final Color indicatorColor; final Color indicatorColor;
...@@ -381,6 +389,7 @@ class ThemeData { ...@@ -381,6 +389,7 @@ class ThemeData {
Color textSelectionColor, Color textSelectionColor,
Color textSelectionHandleColor, Color textSelectionHandleColor,
Color backgroundColor, Color backgroundColor,
Color dialogBackgroundColor,
Color indicatorColor, Color indicatorColor,
Color hintColor, Color hintColor,
Color errorColor, Color errorColor,
...@@ -412,6 +421,7 @@ class ThemeData { ...@@ -412,6 +421,7 @@ class ThemeData {
textSelectionColor: textSelectionColor ?? this.textSelectionColor, textSelectionColor: textSelectionColor ?? this.textSelectionColor,
textSelectionHandleColor: textSelectionHandleColor ?? this.textSelectionHandleColor, textSelectionHandleColor: textSelectionHandleColor ?? this.textSelectionHandleColor,
backgroundColor: backgroundColor ?? this.backgroundColor, backgroundColor: backgroundColor ?? this.backgroundColor,
dialogBackgroundColor: dialogBackgroundColor ?? this.dialogBackgroundColor,
indicatorColor: indicatorColor ?? this.indicatorColor, indicatorColor: indicatorColor ?? this.indicatorColor,
hintColor: hintColor ?? this.hintColor, hintColor: hintColor ?? this.hintColor,
errorColor: errorColor ?? this.errorColor, errorColor: errorColor ?? this.errorColor,
...@@ -445,6 +455,7 @@ class ThemeData { ...@@ -445,6 +455,7 @@ class ThemeData {
textSelectionColor: Color.lerp(begin.textSelectionColor, end.textSelectionColor, t), textSelectionColor: Color.lerp(begin.textSelectionColor, end.textSelectionColor, t),
textSelectionHandleColor: Color.lerp(begin.textSelectionHandleColor, end.textSelectionHandleColor, t), textSelectionHandleColor: Color.lerp(begin.textSelectionHandleColor, end.textSelectionHandleColor, t),
backgroundColor: Color.lerp(begin.backgroundColor, end.backgroundColor, t), backgroundColor: Color.lerp(begin.backgroundColor, end.backgroundColor, t),
dialogBackgroundColor: Color.lerp(begin.dialogBackgroundColor, end.dialogBackgroundColor, t),
accentColor: Color.lerp(begin.accentColor, end.accentColor, t), accentColor: Color.lerp(begin.accentColor, end.accentColor, t),
accentColorBrightness: t < 0.5 ? begin.accentColorBrightness : end.accentColorBrightness, accentColorBrightness: t < 0.5 ? begin.accentColorBrightness : end.accentColorBrightness,
indicatorColor: Color.lerp(begin.indicatorColor, end.indicatorColor, t), indicatorColor: Color.lerp(begin.indicatorColor, end.indicatorColor, t),
...@@ -482,6 +493,7 @@ class ThemeData { ...@@ -482,6 +493,7 @@ class ThemeData {
(otherData.textSelectionColor == textSelectionColor) && (otherData.textSelectionColor == textSelectionColor) &&
(otherData.textSelectionHandleColor == textSelectionHandleColor) && (otherData.textSelectionHandleColor == textSelectionHandleColor) &&
(otherData.backgroundColor == backgroundColor) && (otherData.backgroundColor == backgroundColor) &&
(otherData.dialogBackgroundColor == dialogBackgroundColor) &&
(otherData.accentColor == accentColor) && (otherData.accentColor == accentColor) &&
(otherData.accentColorBrightness == accentColorBrightness) && (otherData.accentColorBrightness == accentColorBrightness) &&
(otherData.indicatorColor == indicatorColor) && (otherData.indicatorColor == indicatorColor) &&
...@@ -520,6 +532,7 @@ class ThemeData { ...@@ -520,6 +532,7 @@ class ThemeData {
accentColorBrightness, accentColorBrightness,
hashValues( // Too many values. hashValues( // Too many values.
indicatorColor, indicatorColor,
dialogBackgroundColor,
hintColor, hintColor,
errorColor, errorColor,
textTheme, textTheme,
......
...@@ -55,4 +55,45 @@ void main() { ...@@ -55,4 +55,45 @@ void main() {
await tester.tap(find.text('OK')); await tester.tap(find.text('OK'));
expect(didPressOk, true); expect(didPressOk, true);
}); });
testWidgets('Dialog background color', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
theme: new ThemeData(brightness: Brightness.dark),
home: new Material(
child: new Builder(
builder: (BuildContext context) {
return new Center(
child: new RaisedButton(
child: new Text('X'),
onPressed: () {
showDialog(
context: context,
child: new AlertDialog(
content: new Text('Y'),
actions: <Widget>[
]
)
);
}
)
);
}
)
)
)
);
await tester.tap(find.text('X'));
await tester.pump(); // start animation
await tester.pump(const Duration(seconds: 1));
StatefulElement widget = tester.element(find.byType(Material).last);
Material materialconfig = widget.state.config;
//first and second expect check that the material is the dialog's one
expect(materialconfig.type, MaterialType.card);
expect(materialconfig.elevation, 24);
expect(materialconfig.color, Colors.grey[800]);
});
} }
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