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

Fixes #12483
This commit is contained in:
gspencergoog
2017-10-12 08:21:28 -07:00
committed by GitHub
parent c3d56b1dad
commit f5cc816c54
2 changed files with 35 additions and 3 deletions

View File

@@ -117,9 +117,14 @@ class CircleAvatar extends StatelessWidget {
shape: BoxShape.circle,
),
child: child != null ? new Center(
child: new DefaultTextStyle(
style: textStyle.copyWith(color: foregroundColor),
child: child,
child: new MediaQuery(
// Need to reset the textScaleFactor here so that the
// 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,
);

View File

@@ -101,6 +101,33 @@ void main() {
final RenderParagraph paragraph = tester.renderObject(find.text('Z'));
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 }) {