Unverified Commit ed84fb96 authored by amirh's avatar amirh Committed by GitHub

add a bottomAppBarColor to ThemeData (#14859)

parent 761cb82c
...@@ -6,9 +6,9 @@ import 'package:flutter/foundation.dart'; ...@@ -6,9 +6,9 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'colors.dart';
import 'material.dart'; import 'material.dart';
import 'scaffold.dart'; import 'scaffold.dart';
import 'theme.dart';
// Examples can assume: // Examples can assume:
// Widget bottomAppBarContents; // Widget bottomAppBarContents;
...@@ -61,6 +61,8 @@ class BottomAppBar extends StatefulWidget { ...@@ -61,6 +61,8 @@ class BottomAppBar extends StatefulWidget {
final Widget child; final Widget child;
/// The bottom app bar's background color. /// The bottom app bar's background color.
///
/// When null defaults to [ThemeData.bottomAppBarColor].
final Color color; final Color color;
/// The z-coordinate at which to place this bottom app bar. This controls the /// The z-coordinate at which to place this bottom app bar. This controls the
...@@ -101,8 +103,7 @@ class _BottomAppBarState extends State<BottomAppBar> { ...@@ -101,8 +103,7 @@ class _BottomAppBarState extends State<BottomAppBar> {
return new PhysicalShape( return new PhysicalShape(
clipper: clipper, clipper: clipper,
elevation: widget.elevation, elevation: widget.elevation,
// TODO(amirh): use a default color from the theme. color: widget.color ?? Theme.of(context).bottomAppBarColor,
color: widget.color ?? Colors.white,
child: new Material( child: new Material(
type: MaterialType.transparency, type: MaterialType.transparency,
child: widget.child, child: widget.child,
......
...@@ -82,6 +82,7 @@ class ThemeData { ...@@ -82,6 +82,7 @@ class ThemeData {
Brightness accentColorBrightness, Brightness accentColorBrightness,
Color canvasColor, Color canvasColor,
Color scaffoldBackgroundColor, Color scaffoldBackgroundColor,
Color bottomAppBarColor,
Color cardColor, Color cardColor,
Color dividerColor, Color dividerColor,
Color highlightColor, Color highlightColor,
...@@ -121,6 +122,7 @@ class ThemeData { ...@@ -121,6 +122,7 @@ class ThemeData {
final bool accentIsDark = accentColorBrightness == Brightness.dark; final bool accentIsDark = accentColorBrightness == Brightness.dark;
canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50]; canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50];
scaffoldBackgroundColor ??= canvasColor; scaffoldBackgroundColor ??= canvasColor;
bottomAppBarColor ??= isDark ? Colors.grey[800] : Colors.white;
cardColor ??= isDark ? Colors.grey[800] : Colors.white; cardColor ??= isDark ? Colors.grey[800] : Colors.white;
dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000); dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000);
highlightColor ??= isDark ? _kDarkThemeHighlightColor : _kLightThemeHighlightColor; highlightColor ??= isDark ? _kDarkThemeHighlightColor : _kLightThemeHighlightColor;
...@@ -162,6 +164,7 @@ class ThemeData { ...@@ -162,6 +164,7 @@ class ThemeData {
accentColorBrightness: accentColorBrightness, accentColorBrightness: accentColorBrightness,
canvasColor: canvasColor, canvasColor: canvasColor,
scaffoldBackgroundColor: scaffoldBackgroundColor, scaffoldBackgroundColor: scaffoldBackgroundColor,
bottomAppBarColor: bottomAppBarColor,
cardColor: cardColor, cardColor: cardColor,
dividerColor: dividerColor, dividerColor: dividerColor,
highlightColor: highlightColor, highlightColor: highlightColor,
...@@ -205,6 +208,7 @@ class ThemeData { ...@@ -205,6 +208,7 @@ class ThemeData {
@required this.accentColorBrightness, @required this.accentColorBrightness,
@required this.canvasColor, @required this.canvasColor,
@required this.scaffoldBackgroundColor, @required this.scaffoldBackgroundColor,
@required this.bottomAppBarColor,
@required this.cardColor, @required this.cardColor,
@required this.dividerColor, @required this.dividerColor,
@required this.highlightColor, @required this.highlightColor,
...@@ -238,6 +242,7 @@ class ThemeData { ...@@ -238,6 +242,7 @@ class ThemeData {
assert(accentColorBrightness != null), assert(accentColorBrightness != null),
assert(canvasColor != null), assert(canvasColor != null),
assert(scaffoldBackgroundColor != null), assert(scaffoldBackgroundColor != null),
assert(bottomAppBarColor != null),
assert(cardColor != null), assert(cardColor != null),
assert(dividerColor != null), assert(dividerColor != null),
assert(highlightColor != null), assert(highlightColor != null),
...@@ -321,6 +326,11 @@ class ThemeData { ...@@ -321,6 +326,11 @@ class ThemeData {
/// background color for a typical material app or a page within the app. /// background color for a typical material app or a page within the app.
final Color scaffoldBackgroundColor; final Color scaffoldBackgroundColor;
/// The default color of the [BottomAppBar].
///
/// This can be overriden by specifying [BottomAppBar.color].
final Color bottomAppBarColor;
/// The color of [Material] when it is used as a [Card]. /// The color of [Material] when it is used as a [Card].
final Color cardColor; final Color cardColor;
...@@ -432,6 +442,7 @@ class ThemeData { ...@@ -432,6 +442,7 @@ class ThemeData {
Brightness accentColorBrightness, Brightness accentColorBrightness,
Color canvasColor, Color canvasColor,
Color scaffoldBackgroundColor, Color scaffoldBackgroundColor,
Color bottomAppBarColor,
Color cardColor, Color cardColor,
Color dividerColor, Color dividerColor,
Color highlightColor, Color highlightColor,
...@@ -467,6 +478,7 @@ class ThemeData { ...@@ -467,6 +478,7 @@ class ThemeData {
accentColorBrightness: accentColorBrightness ?? this.accentColorBrightness, accentColorBrightness: accentColorBrightness ?? this.accentColorBrightness,
canvasColor: canvasColor ?? this.canvasColor, canvasColor: canvasColor ?? this.canvasColor,
scaffoldBackgroundColor: scaffoldBackgroundColor ?? this.scaffoldBackgroundColor, scaffoldBackgroundColor: scaffoldBackgroundColor ?? this.scaffoldBackgroundColor,
bottomAppBarColor: bottomAppBarColor ?? this.bottomAppBarColor,
cardColor: cardColor ?? this.cardColor, cardColor: cardColor ?? this.cardColor,
dividerColor: dividerColor ?? this.dividerColor, dividerColor: dividerColor ?? this.dividerColor,
highlightColor: highlightColor ?? this.highlightColor, highlightColor: highlightColor ?? this.highlightColor,
...@@ -585,6 +597,7 @@ class ThemeData { ...@@ -585,6 +597,7 @@ class ThemeData {
primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness, primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness,
canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t), canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t),
scaffoldBackgroundColor: Color.lerp(a.scaffoldBackgroundColor, b.scaffoldBackgroundColor, t), scaffoldBackgroundColor: Color.lerp(a.scaffoldBackgroundColor, b.scaffoldBackgroundColor, t),
bottomAppBarColor: Color.lerp(a.bottomAppBarColor, b.bottomAppBarColor, t),
cardColor: Color.lerp(a.cardColor, b.cardColor, t), cardColor: Color.lerp(a.cardColor, b.cardColor, t),
dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t), dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t),
highlightColor: Color.lerp(a.highlightColor, b.highlightColor, t), highlightColor: Color.lerp(a.highlightColor, b.highlightColor, t),
...@@ -626,6 +639,7 @@ class ThemeData { ...@@ -626,6 +639,7 @@ class ThemeData {
(otherData.primaryColorBrightness == primaryColorBrightness) && (otherData.primaryColorBrightness == primaryColorBrightness) &&
(otherData.canvasColor == canvasColor) && (otherData.canvasColor == canvasColor) &&
(otherData.scaffoldBackgroundColor == scaffoldBackgroundColor) && (otherData.scaffoldBackgroundColor == scaffoldBackgroundColor) &&
(otherData.bottomAppBarColor == bottomAppBarColor) &&
(otherData.cardColor == cardColor) && (otherData.cardColor == cardColor) &&
(otherData.dividerColor == dividerColor) && (otherData.dividerColor == dividerColor) &&
(otherData.highlightColor == highlightColor) && (otherData.highlightColor == highlightColor) &&
...@@ -664,6 +678,7 @@ class ThemeData { ...@@ -664,6 +678,7 @@ class ThemeData {
primaryColorBrightness, primaryColorBrightness,
canvasColor, canvasColor,
scaffoldBackgroundColor, scaffoldBackgroundColor,
bottomAppBarColor,
cardColor, cardColor,
dividerColor, dividerColor,
highlightColor, highlightColor,
...@@ -677,8 +692,8 @@ class ThemeData { ...@@ -677,8 +692,8 @@ class ThemeData {
secondaryHeaderColor, secondaryHeaderColor,
textSelectionColor, textSelectionColor,
textSelectionHandleColor, textSelectionHandleColor,
backgroundColor,
hashValues( // Too many values. hashValues( // Too many values.
backgroundColor,
accentColor, accentColor,
accentColorBrightness, accentColorBrightness,
indicatorColor, indicatorColor,
......
...@@ -34,6 +34,58 @@ void main() { ...@@ -34,6 +34,58 @@ void main() {
); );
}); });
testWidgets('color defaults to Theme.bottomAppBarColor', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new Builder(
builder: (BuildContext context) {
return new Theme(
data: Theme.of(context).copyWith(bottomAppBarColor: const Color(0xffffff00)),
child: const Scaffold(
floatingActionButton: const FloatingActionButton(
onPressed: null,
),
bottomNavigationBar: const BottomAppBar(),
),
);
}
),
),
);
final PhysicalShape physicalShape =
tester.widget(find.byType(PhysicalShape).at(0));
expect(physicalShape.color, const Color(0xffffff00));
});
testWidgets('color overrides theme color', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new Builder(
builder: (BuildContext context) {
return new Theme(
data: Theme.of(context).copyWith(bottomAppBarColor: const Color(0xffffff00)),
child: const Scaffold(
floatingActionButton: const FloatingActionButton(
onPressed: null,
),
bottomNavigationBar: const BottomAppBar(
color: const Color(0xff0000ff)
),
),
);
}
),
),
);
final PhysicalShape physicalShape =
tester.widget(find.byType(PhysicalShape).at(0));
expect(physicalShape.color, const Color(0xff0000ff));
});
// TODO(amirh): test a BottomAppBar with hasNotch=false and an overlapping // TODO(amirh): test a BottomAppBar with hasNotch=false and an overlapping
// FAB. // FAB.
// //
......
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