Commit 21899ce6 authored by Ian Hickson's avatar Ian Hickson Committed by Todd Volkert

Honor more of the Theme for CircleAvatar with backgroundColor (#12333)

parent f40d09e1
......@@ -5,9 +5,10 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'colors.dart';
import 'constants.dart';
import 'theme.dart';
import 'typography.dart';
import 'theme_data.dart';
// Examples can assume:
// String userAvatarUrl;
......@@ -91,9 +92,19 @@ class CircleAvatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle textStyle = backgroundColor != null ?
new Typography(platform: theme.platform).white.title :
theme.primaryTextTheme.title;
TextStyle textStyle = theme.primaryTextTheme.title;
if (foregroundColor != null) {
textStyle = textStyle.copyWith(color: foregroundColor);
} else if (backgroundColor != null) {
switch (ThemeData.estimateBrightnessForColor(backgroundColor)) {
case Brightness.dark:
textStyle = textStyle.copyWith(color: Colors.white);
break;
case Brightness.light:
textStyle = textStyle.copyWith(color: Colors.black);
break;
}
}
return new AnimatedContainer(
width: radius * 2.0,
height: radius * 2.0,
......
......@@ -7,8 +7,8 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CircleAvatar with background color', (WidgetTester tester) async {
final Color backgroundColor = Colors.blue.shade400;
testWidgets('CircleAvatar with dark background color', (WidgetTester tester) async {
final Color backgroundColor = Colors.blue.shade900;
await tester.pumpWidget(
wrap(
child: new CircleAvatar(
......@@ -30,6 +30,29 @@ void main() {
expect(paragraph.text.style.color, equals(Colors.white));
});
testWidgets('CircleAvatar with light background color', (WidgetTester tester) async {
final Color backgroundColor = Colors.blue.shade100;
await tester.pumpWidget(
wrap(
child: new CircleAvatar(
backgroundColor: backgroundColor,
radius: 50.0,
child: const Text('Z'),
),
),
);
final RenderConstrainedBox box = tester.renderObject(find.byType(CircleAvatar));
expect(box.size.width, equals(100.0));
expect(box.size.height, equals(100.0));
final RenderDecoratedBox child = box.child;
final BoxDecoration decoration = child.decoration;
expect(decoration.color, equals(backgroundColor));
final RenderParagraph paragraph = tester.renderObject(find.text('Z'));
expect(paragraph.text.style.color, equals(Colors.black));
});
testWidgets('CircleAvatar with foreground color', (WidgetTester tester) async {
final Color foregroundColor = Colors.red.shade100;
await tester.pumpWidget(
......
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