1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('BAB theme overrides color', (WidgetTester tester) async {
const Color themedColor = Colors.black87;
const BottomAppBarTheme theme = BottomAppBarTheme(color: themedColor);
await tester.pumpWidget(_withTheme(theme));
final PhysicalShape widget = _getBabRenderObject(tester);
expect(widget.color, themedColor);
});
testWidgets('BAB color - Widget', (WidgetTester tester) async {
const Color themeColor = Colors.white10;
const Color babThemeColor = Colors.black87;
const Color babColor = Colors.pink;
const BottomAppBarTheme theme = BottomAppBarTheme(color: babThemeColor);
await tester.pumpWidget(MaterialApp(
theme: ThemeData(bottomAppBarTheme: theme, bottomAppBarColor: themeColor),
home: const Scaffold(body: BottomAppBar(color: babColor)),
));
final PhysicalShape widget = _getBabRenderObject(tester);
expect(widget.color, babColor);
});
testWidgets('BAB color - BabTheme', (WidgetTester tester) async {
const Color themeColor = Colors.white10;
const Color babThemeColor = Colors.black87;
const BottomAppBarTheme theme = BottomAppBarTheme(color: babThemeColor);
await tester.pumpWidget(MaterialApp(
theme: ThemeData(bottomAppBarTheme: theme, bottomAppBarColor: themeColor),
home: const Scaffold(body: BottomAppBar()),
));
final PhysicalShape widget = _getBabRenderObject(tester);
expect(widget.color, babThemeColor);
});
testWidgets('BAB color - Theme', (WidgetTester tester) async {
const Color themeColor = Colors.white10;
await tester.pumpWidget(MaterialApp(
theme: ThemeData(bottomAppBarColor: themeColor),
home: const Scaffold(body: BottomAppBar()),
));
final PhysicalShape widget = _getBabRenderObject(tester);
expect(widget.color, themeColor);
});
testWidgets('BAB color - Default', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
theme: ThemeData(),
home: const Scaffold(body: BottomAppBar()),
));
final PhysicalShape widget = _getBabRenderObject(tester);
expect(widget.color, Colors.white);
});
testWidgets('BAB theme customizes shape', (WidgetTester tester) async {
const BottomAppBarTheme theme = BottomAppBarTheme(
color: Colors.white30,
shape: CircularNotchedRectangle(),
elevation: 1.0,
);
await tester.pumpWidget(_withTheme(theme));
await expectLater(
find.byKey(_painterKey),
matchesGoldenFile('bottom_app_bar_theme.custom_shape.png'),
);
}, skip: isBrowser);
testWidgets('BAB theme does not affect defaults', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(body: BottomAppBar()),
));
final PhysicalShape widget = _getBabRenderObject(tester);
expect(widget.color, Colors.white);
expect(widget.elevation, equals(8.0));
});
}
PhysicalShape _getBabRenderObject(WidgetTester tester) {
return tester.widget<PhysicalShape>(
find.descendant(
of: find.byType(BottomAppBar),
matching: find.byType(PhysicalShape),
),
);
}
final Key _painterKey = UniqueKey();
Widget _withTheme(BottomAppBarTheme theme) {
return MaterialApp(
theme: ThemeData(bottomAppBarTheme: theme),
home: Scaffold(
floatingActionButton: const FloatingActionButton(onPressed: null),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: RepaintBoundary(
key: _painterKey,
child: BottomAppBar(
child: Row(
children: const <Widget>[
Icon(Icons.add),
Expanded(child: SizedBox()),
Icon(Icons.add),
],
),
),
),
),
);
}