@@ -144,36 +144,8 @@ void main() {
144
144
expect (paragraph.text.style! .color, equals (foregroundColor));
145
145
});
146
146
147
- testWidgets ('CircleAvatar with light theme' , (WidgetTester tester) async {
148
- final ThemeData theme = ThemeData (
149
- primaryColor: Colors .grey.shade100,
150
- primaryColorBrightness: Brightness .light,
151
- );
152
- await tester.pumpWidget (
153
- wrap (
154
- child: Theme (
155
- data: theme,
156
- child: const CircleAvatar (
157
- child: Text ('Z' ),
158
- ),
159
- ),
160
- ),
161
- );
162
-
163
- final RenderConstrainedBox box = tester.renderObject (find.byType (CircleAvatar ));
164
- final RenderDecoratedBox child = box.child! as RenderDecoratedBox ;
165
- final BoxDecoration decoration = child.decoration as BoxDecoration ;
166
- expect (decoration.color, equals (theme.primaryColorLight));
167
-
168
- final RenderParagraph paragraph = tester.renderObject (find.text ('Z' ));
169
- expect (paragraph.text.style! .color, equals (theme.primaryTextTheme.titleLarge! .color));
170
- });
171
-
172
- testWidgets ('CircleAvatar with dark theme' , (WidgetTester tester) async {
173
- final ThemeData theme = ThemeData (
174
- primaryColor: Colors .grey.shade800,
175
- primaryColorBrightness: Brightness .dark,
176
- );
147
+ testWidgets ('CircleAvatar default colors' , (WidgetTester tester) async {
148
+ final ThemeData theme = ThemeData (useMaterial3: true );
177
149
await tester.pumpWidget (
178
150
wrap (
179
151
child: Theme (
@@ -188,10 +160,10 @@ void main() {
188
160
final RenderConstrainedBox box = tester.renderObject (find.byType (CircleAvatar ));
189
161
final RenderDecoratedBox child = box.child! as RenderDecoratedBox ;
190
162
final BoxDecoration decoration = child.decoration as BoxDecoration ;
191
- expect (decoration.color, equals (theme.primaryColorDark ));
163
+ expect (decoration.color, equals (theme.colorScheme.primaryContainer ));
192
164
193
165
final RenderParagraph paragraph = tester.renderObject (find.text ('Z' ));
194
- expect (paragraph.text.style! .color, equals (theme.primaryTextTheme.titleLarge ! .color ));
166
+ expect (paragraph.text.style! .color, equals (theme.colorScheme.onPrimaryContainer ));
195
167
});
196
168
197
169
testWidgets ('CircleAvatar text does not expand with textScaleFactor' , (WidgetTester tester) async {
@@ -306,6 +278,61 @@ void main() {
306
278
final RenderParagraph paragraph = tester.renderObject (find.text ('Z' ));
307
279
expect (paragraph.text.style! .color, equals (ThemeData .fallback ().primaryColorLight));
308
280
});
281
+
282
+ group ('Material 2' , () {
283
+ // Tests that are only relevant for Material 2. Once ThemeData.useMaterial3
284
+ // is turned on by default, these tests can be removed.
285
+
286
+ testWidgets ('CircleAvatar default colors with light theme' , (WidgetTester tester) async {
287
+ final ThemeData theme = ThemeData (
288
+ primaryColor: Colors .grey.shade100,
289
+ primaryColorBrightness: Brightness .light,
290
+ );
291
+ await tester.pumpWidget (
292
+ wrap (
293
+ child: Theme (
294
+ data: theme,
295
+ child: const CircleAvatar (
296
+ child: Text ('Z' ),
297
+ ),
298
+ ),
299
+ ),
300
+ );
301
+
302
+ final RenderConstrainedBox box = tester.renderObject (find.byType (CircleAvatar ));
303
+ final RenderDecoratedBox child = box.child! as RenderDecoratedBox ;
304
+ final BoxDecoration decoration = child.decoration as BoxDecoration ;
305
+ expect (decoration.color, equals (theme.primaryColorLight));
306
+
307
+ final RenderParagraph paragraph = tester.renderObject (find.text ('Z' ));
308
+ expect (paragraph.text.style! .color, equals (theme.primaryTextTheme.titleLarge! .color));
309
+ });
310
+
311
+ testWidgets ('CircleAvatar default colors with dark theme' , (WidgetTester tester) async {
312
+ final ThemeData theme = ThemeData (
313
+ primaryColor: Colors .grey.shade800,
314
+ primaryColorBrightness: Brightness .dark,
315
+ );
316
+ await tester.pumpWidget (
317
+ wrap (
318
+ child: Theme (
319
+ data: theme,
320
+ child: const CircleAvatar (
321
+ child: Text ('Z' ),
322
+ ),
323
+ ),
324
+ ),
325
+ );
326
+
327
+ final RenderConstrainedBox box = tester.renderObject (find.byType (CircleAvatar ));
328
+ final RenderDecoratedBox child = box.child! as RenderDecoratedBox ;
329
+ final BoxDecoration decoration = child.decoration as BoxDecoration ;
330
+ expect (decoration.color, equals (theme.primaryColorDark));
331
+
332
+ final RenderParagraph paragraph = tester.renderObject (find.text ('Z' ));
333
+ expect (paragraph.text.style! .color, equals (theme.primaryTextTheme.titleLarge! .color));
334
+ });
335
+ });
309
336
}
310
337
311
338
Widget wrap ({ required Widget child }) {
0 commit comments