Commit 7e09649c authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Override just the textScaleFactor (#12530)

Hixie pointed out that what I had before was resetting all of the MediaQuery values, not just textScaleFactor. This should fix that.
parent c05da1e2
...@@ -91,6 +91,7 @@ class CircleAvatar extends StatelessWidget { ...@@ -91,6 +91,7 @@ class CircleAvatar extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMediaQuery(context));
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
TextStyle textStyle = theme.primaryTextTheme.title; TextStyle textStyle = theme.primaryTextTheme.title;
if (foregroundColor != null) { if (foregroundColor != null) {
...@@ -120,7 +121,7 @@ class CircleAvatar extends StatelessWidget { ...@@ -120,7 +121,7 @@ class CircleAvatar extends StatelessWidget {
child: new MediaQuery( child: new MediaQuery(
// Need to reset the textScaleFactor here so that the // Need to reset the textScaleFactor here so that the
// text doesn't escape the avatar when the textScaleFactor is large. // 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( child: new DefaultTextStyle(
style: textStyle.copyWith(color: foregroundColor), style: textStyle.copyWith(color: foregroundColor),
child: child, child: child,
......
...@@ -118,10 +118,26 @@ void main() { ...@@ -118,10 +118,26 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
wrap( wrap(
child: new MediaQuery( 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( child: new CircleAvatar(
foregroundColor: foregroundColor, child: new Builder(
child: const Text('Z'), 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() { ...@@ -133,6 +149,9 @@ void main() {
Widget wrap({ Widget child }) { Widget wrap({ Widget child }) {
return new Directionality( return new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(),
child: new Center(child: child), child: new Center(child: 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