Commit f5cc816c authored by gspencergoog's avatar gspencergoog Committed by GitHub

Keep CircleAvatar from scaling the text with textScaleFactor (#12499)

Fixes #12483
parent c3d56b1d
...@@ -117,9 +117,14 @@ class CircleAvatar extends StatelessWidget { ...@@ -117,9 +117,14 @@ class CircleAvatar extends StatelessWidget {
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
child: child != null ? new Center( child: child != null ? new Center(
child: new DefaultTextStyle( child: new MediaQuery(
style: textStyle.copyWith(color: foregroundColor), // Need to reset the textScaleFactor here so that the
child: child, // text doesn't escape the avatar when the textScaleFactor is large.
data: const MediaQueryData(textScaleFactor: 1.0),
child: new DefaultTextStyle(
style: textStyle.copyWith(color: foregroundColor),
child: child,
),
) )
) : null, ) : null,
); );
......
...@@ -101,6 +101,33 @@ void main() { ...@@ -101,6 +101,33 @@ void main() {
final RenderParagraph paragraph = tester.renderObject(find.text('Z')); final RenderParagraph paragraph = tester.renderObject(find.text('Z'));
expect(paragraph.text.style.color, equals(theme.primaryTextTheme.title.color)); expect(paragraph.text.style.color, equals(theme.primaryTextTheme.title.color));
}); });
testWidgets('CircleAvatar text does not expand with textScaleFactor', (WidgetTester tester) async {
final Color foregroundColor = Colors.red.shade100;
await tester.pumpWidget(
wrap(
child: new CircleAvatar(
foregroundColor: foregroundColor,
child: const Text('Z'),
),
),
);
expect(tester.getSize(find.text('Z')), equals(const Size(20.0, 20.0)));
await tester.pumpWidget(
wrap(
child: new MediaQuery(
data: const MediaQueryData(textScaleFactor: 2.0),
child: new CircleAvatar(
foregroundColor: foregroundColor,
child: const Text('Z'),
),
),
),
);
expect(tester.getSize(find.text('Z')), equals(const Size(20.0, 20.0)));
});
} }
Widget wrap({ Widget child }) { Widget wrap({ Widget child }) {
......
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