Keep CircleAvatar from scaling the text with textScaleFactor (#12499)
Fixes #12483
This commit is contained in:
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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 }) {
|
||||
|
||||
Reference in New Issue
Block a user