diff --git a/packages/flutter/lib/src/material/circle_avatar.dart b/packages/flutter/lib/src/material/circle_avatar.dart index 4d39580066..9bd196ade0 100644 --- a/packages/flutter/lib/src/material/circle_avatar.dart +++ b/packages/flutter/lib/src/material/circle_avatar.dart @@ -91,6 +91,7 @@ class CircleAvatar extends StatelessWidget { @override Widget build(BuildContext context) { + assert(debugCheckHasMediaQuery(context)); final ThemeData theme = Theme.of(context); TextStyle textStyle = theme.primaryTextTheme.title; if (foregroundColor != null) { @@ -120,7 +121,7 @@ class CircleAvatar extends StatelessWidget { 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), + data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), child: new DefaultTextStyle( style: textStyle.copyWith(color: foregroundColor), child: child, diff --git a/packages/flutter/test/material/circle_avatar_test.dart b/packages/flutter/test/material/circle_avatar_test.dart index 17a1f6342e..4f71c552ba 100644 --- a/packages/flutter/test/material/circle_avatar_test.dart +++ b/packages/flutter/test/material/circle_avatar_test.dart @@ -118,10 +118,26 @@ void main() { await tester.pumpWidget( wrap( child: new MediaQuery( - data: const MediaQueryData(textScaleFactor: 2.0), + data: const MediaQueryData( + textScaleFactor: 2.0, + size: const Size(111.0, 111.0), + devicePixelRatio: 1.1, + padding: const EdgeInsets.all(11.0)), child: new CircleAvatar( - foregroundColor: foregroundColor, - child: const Text('Z'), + child: new Builder( + builder: (BuildContext context) { + final MediaQueryData data = MediaQuery.of(context); + + // These should not change. + expect(data.size, equals(const Size(111.0, 111.0))); + expect(data.devicePixelRatio, equals(1.1)); + expect(data.padding, equals(const EdgeInsets.all(11.0))); + + // This should be overridden to 1.0. + expect(data.textScaleFactor, equals(1.0)); + return const Text('Z'); + } + ), ), ), ), @@ -133,6 +149,9 @@ void main() { Widget wrap({ Widget child }) { return new Directionality( textDirection: TextDirection.ltr, - child: new Center(child: child), + child: new MediaQuery( + data: const MediaQueryData(), + child: new Center(child: child), + ), ); }