Skip to content

Commit ed84fb9

Browse files
authored
add a bottomAppBarColor to ThemeData (flutter#14859)
1 parent 761cb82 commit ed84fb9

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

packages/flutter/lib/src/material/bottom_app_bar.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import 'package:flutter/foundation.dart';
66
import 'package:flutter/rendering.dart';
77
import 'package:flutter/widgets.dart';
88

9-
import 'colors.dart';
109
import 'material.dart';
1110
import 'scaffold.dart';
11+
import 'theme.dart';
1212

1313
// Examples can assume:
1414
// Widget bottomAppBarContents;
@@ -61,6 +61,8 @@ class BottomAppBar extends StatefulWidget {
6161
final Widget child;
6262

6363
/// The bottom app bar's background color.
64+
///
65+
/// When null defaults to [ThemeData.bottomAppBarColor].
6466
final Color color;
6567

6668
/// The z-coordinate at which to place this bottom app bar. This controls the
@@ -101,8 +103,7 @@ class _BottomAppBarState extends State<BottomAppBar> {
101103
return new PhysicalShape(
102104
clipper: clipper,
103105
elevation: widget.elevation,
104-
// TODO(amirh): use a default color from the theme.
105-
color: widget.color ?? Colors.white,
106+
color: widget.color ?? Theme.of(context).bottomAppBarColor,
106107
child: new Material(
107108
type: MaterialType.transparency,
108109
child: widget.child,

packages/flutter/lib/src/material/theme_data.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class ThemeData {
8282
Brightness accentColorBrightness,
8383
Color canvasColor,
8484
Color scaffoldBackgroundColor,
85+
Color bottomAppBarColor,
8586
Color cardColor,
8687
Color dividerColor,
8788
Color highlightColor,
@@ -121,6 +122,7 @@ class ThemeData {
121122
final bool accentIsDark = accentColorBrightness == Brightness.dark;
122123
canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50];
123124
scaffoldBackgroundColor ??= canvasColor;
125+
bottomAppBarColor ??= isDark ? Colors.grey[800] : Colors.white;
124126
cardColor ??= isDark ? Colors.grey[800] : Colors.white;
125127
dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000);
126128
highlightColor ??= isDark ? _kDarkThemeHighlightColor : _kLightThemeHighlightColor;
@@ -162,6 +164,7 @@ class ThemeData {
162164
accentColorBrightness: accentColorBrightness,
163165
canvasColor: canvasColor,
164166
scaffoldBackgroundColor: scaffoldBackgroundColor,
167+
bottomAppBarColor: bottomAppBarColor,
165168
cardColor: cardColor,
166169
dividerColor: dividerColor,
167170
highlightColor: highlightColor,
@@ -205,6 +208,7 @@ class ThemeData {
205208
@required this.accentColorBrightness,
206209
@required this.canvasColor,
207210
@required this.scaffoldBackgroundColor,
211+
@required this.bottomAppBarColor,
208212
@required this.cardColor,
209213
@required this.dividerColor,
210214
@required this.highlightColor,
@@ -238,6 +242,7 @@ class ThemeData {
238242
assert(accentColorBrightness != null),
239243
assert(canvasColor != null),
240244
assert(scaffoldBackgroundColor != null),
245+
assert(bottomAppBarColor != null),
241246
assert(cardColor != null),
242247
assert(dividerColor != null),
243248
assert(highlightColor != null),
@@ -321,6 +326,11 @@ class ThemeData {
321326
/// background color for a typical material app or a page within the app.
322327
final Color scaffoldBackgroundColor;
323328

329+
/// The default color of the [BottomAppBar].
330+
///
331+
/// This can be overriden by specifying [BottomAppBar.color].
332+
final Color bottomAppBarColor;
333+
324334
/// The color of [Material] when it is used as a [Card].
325335
final Color cardColor;
326336

@@ -432,6 +442,7 @@ class ThemeData {
432442
Brightness accentColorBrightness,
433443
Color canvasColor,
434444
Color scaffoldBackgroundColor,
445+
Color bottomAppBarColor,
435446
Color cardColor,
436447
Color dividerColor,
437448
Color highlightColor,
@@ -467,6 +478,7 @@ class ThemeData {
467478
accentColorBrightness: accentColorBrightness ?? this.accentColorBrightness,
468479
canvasColor: canvasColor ?? this.canvasColor,
469480
scaffoldBackgroundColor: scaffoldBackgroundColor ?? this.scaffoldBackgroundColor,
481+
bottomAppBarColor: bottomAppBarColor ?? this.bottomAppBarColor,
470482
cardColor: cardColor ?? this.cardColor,
471483
dividerColor: dividerColor ?? this.dividerColor,
472484
highlightColor: highlightColor ?? this.highlightColor,
@@ -585,6 +597,7 @@ class ThemeData {
585597
primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness,
586598
canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t),
587599
scaffoldBackgroundColor: Color.lerp(a.scaffoldBackgroundColor, b.scaffoldBackgroundColor, t),
600+
bottomAppBarColor: Color.lerp(a.bottomAppBarColor, b.bottomAppBarColor, t),
588601
cardColor: Color.lerp(a.cardColor, b.cardColor, t),
589602
dividerColor: Color.lerp(a.dividerColor, b.dividerColor, t),
590603
highlightColor: Color.lerp(a.highlightColor, b.highlightColor, t),
@@ -626,6 +639,7 @@ class ThemeData {
626639
(otherData.primaryColorBrightness == primaryColorBrightness) &&
627640
(otherData.canvasColor == canvasColor) &&
628641
(otherData.scaffoldBackgroundColor == scaffoldBackgroundColor) &&
642+
(otherData.bottomAppBarColor == bottomAppBarColor) &&
629643
(otherData.cardColor == cardColor) &&
630644
(otherData.dividerColor == dividerColor) &&
631645
(otherData.highlightColor == highlightColor) &&
@@ -664,6 +678,7 @@ class ThemeData {
664678
primaryColorBrightness,
665679
canvasColor,
666680
scaffoldBackgroundColor,
681+
bottomAppBarColor,
667682
cardColor,
668683
dividerColor,
669684
highlightColor,
@@ -677,8 +692,8 @@ class ThemeData {
677692
secondaryHeaderColor,
678693
textSelectionColor,
679694
textSelectionHandleColor,
680-
backgroundColor,
681695
hashValues( // Too many values.
696+
backgroundColor,
682697
accentColor,
683698
accentColorBrightness,
684699
indicatorColor,

packages/flutter/test/material/bottom_app_bar_test.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,58 @@ void main() {
3434
);
3535
});
3636

37+
testWidgets('color defaults to Theme.bottomAppBarColor', (WidgetTester tester) async {
38+
await tester.pumpWidget(
39+
new MaterialApp(
40+
home: new Builder(
41+
builder: (BuildContext context) {
42+
return new Theme(
43+
data: Theme.of(context).copyWith(bottomAppBarColor: const Color(0xffffff00)),
44+
child: const Scaffold(
45+
floatingActionButton: const FloatingActionButton(
46+
onPressed: null,
47+
),
48+
bottomNavigationBar: const BottomAppBar(),
49+
),
50+
);
51+
}
52+
),
53+
),
54+
);
55+
56+
final PhysicalShape physicalShape =
57+
tester.widget(find.byType(PhysicalShape).at(0));
58+
59+
expect(physicalShape.color, const Color(0xffffff00));
60+
});
61+
62+
testWidgets('color overrides theme color', (WidgetTester tester) async {
63+
await tester.pumpWidget(
64+
new MaterialApp(
65+
home: new Builder(
66+
builder: (BuildContext context) {
67+
return new Theme(
68+
data: Theme.of(context).copyWith(bottomAppBarColor: const Color(0xffffff00)),
69+
child: const Scaffold(
70+
floatingActionButton: const FloatingActionButton(
71+
onPressed: null,
72+
),
73+
bottomNavigationBar: const BottomAppBar(
74+
color: const Color(0xff0000ff)
75+
),
76+
),
77+
);
78+
}
79+
),
80+
),
81+
);
82+
83+
final PhysicalShape physicalShape =
84+
tester.widget(find.byType(PhysicalShape).at(0));
85+
86+
expect(physicalShape.color, const Color(0xff0000ff));
87+
});
88+
3789
// TODO(amirh): test a BottomAppBar with hasNotch=false and an overlapping
3890
// FAB.
3991
//

0 commit comments

Comments
 (0)