diff --git a/bin/internal/engine.version b/bin/internal/engine.version index 8d3cc9aa26..c9545f49f1 100644 --- a/bin/internal/engine.version +++ b/bin/internal/engine.version @@ -1 +1 @@ -bdfedcc26f78ea332cdac0ed67590157c82c954e +e3404b81a53ba3180c7623a6f2190ebb28518f30 \ No newline at end of file diff --git a/dev/benchmarks/complex_layout/android/app/src/main/AndroidManifest.xml b/dev/benchmarks/complex_layout/android/app/src/main/AndroidManifest.xml index c93aafaa4d..65b3da9050 100644 --- a/dev/benchmarks/complex_layout/android/app/src/main/AndroidManifest.xml +++ b/dev/benchmarks/complex_layout/android/app/src/main/AndroidManifest.xml @@ -7,7 +7,7 @@ diff --git a/dev/benchmarks/microbenchmarks/android/app/src/main/AndroidManifest.xml b/dev/benchmarks/microbenchmarks/android/app/src/main/AndroidManifest.xml index 1c10c5a4b1..a20d0f1f48 100644 --- a/dev/benchmarks/microbenchmarks/android/app/src/main/AndroidManifest.xml +++ b/dev/benchmarks/microbenchmarks/android/app/src/main/AndroidManifest.xml @@ -7,7 +7,7 @@ diff --git a/dev/integration_tests/channels/android/app/src/main/AndroidManifest.xml b/dev/integration_tests/channels/android/app/src/main/AndroidManifest.xml index 199e25e11e..b15d5a5142 100644 --- a/dev/integration_tests/channels/android/app/src/main/AndroidManifest.xml +++ b/dev/integration_tests/channels/android/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ diff --git a/dev/integration_tests/flavors/android/app/src/main/AndroidManifest.xml b/dev/integration_tests/flavors/android/app/src/main/AndroidManifest.xml index 56ee31f678..7df5a4bd25 100644 --- a/dev/integration_tests/flavors/android/app/src/main/AndroidManifest.xml +++ b/dev/integration_tests/flavors/android/app/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ diff --git a/dev/integration_tests/platform_interaction/android/app/src/main/AndroidManifest.xml b/dev/integration_tests/platform_interaction/android/app/src/main/AndroidManifest.xml index 03a3104b70..e255c91186 100644 --- a/dev/integration_tests/platform_interaction/android/app/src/main/AndroidManifest.xml +++ b/dev/integration_tests/platform_interaction/android/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ diff --git a/dev/integration_tests/ui/android/app/src/main/AndroidManifest.xml b/dev/integration_tests/ui/android/app/src/main/AndroidManifest.xml index 571307739b..885a67fbc4 100644 --- a/dev/integration_tests/ui/android/app/src/main/AndroidManifest.xml +++ b/dev/integration_tests/ui/android/app/src/main/AndroidManifest.xml @@ -20,7 +20,7 @@ diff --git a/dev/manual_tests/android/app/src/main/AndroidManifest.xml b/dev/manual_tests/android/app/src/main/AndroidManifest.xml index 03b88c412e..f16215f7bb 100644 --- a/dev/manual_tests/android/app/src/main/AndroidManifest.xml +++ b/dev/manual_tests/android/app/src/main/AndroidManifest.xml @@ -21,7 +21,7 @@ diff --git a/examples/catalog/android/app/src/main/AndroidManifest.xml b/examples/catalog/android/app/src/main/AndroidManifest.xml index d53f899d62..e978e351dc 100644 --- a/examples/catalog/android/app/src/main/AndroidManifest.xml +++ b/examples/catalog/android/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ diff --git a/examples/flutter_gallery/android/app/src/main/AndroidManifest.xml b/examples/flutter_gallery/android/app/src/main/AndroidManifest.xml index feb9111a6e..37ef2f23d5 100644 --- a/examples/flutter_gallery/android/app/src/main/AndroidManifest.xml +++ b/examples/flutter_gallery/android/app/src/main/AndroidManifest.xml @@ -21,7 +21,7 @@ diff --git a/examples/flutter_view/android/app/src/main/AndroidManifest.xml b/examples/flutter_view/android/app/src/main/AndroidManifest.xml index 4b186df838..da18b44e6d 100644 --- a/examples/flutter_view/android/app/src/main/AndroidManifest.xml +++ b/examples/flutter_view/android/app/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ diff --git a/examples/hello_world/android/app/src/main/AndroidManifest.xml b/examples/hello_world/android/app/src/main/AndroidManifest.xml index 2ef9e89bbe..5f530d04f9 100644 --- a/examples/hello_world/android/app/src/main/AndroidManifest.xml +++ b/examples/hello_world/android/app/src/main/AndroidManifest.xml @@ -21,7 +21,7 @@ diff --git a/examples/layers/android/app/src/main/AndroidManifest.xml b/examples/layers/android/app/src/main/AndroidManifest.xml index c6294967e6..0e23193def 100644 --- a/examples/layers/android/app/src/main/AndroidManifest.xml +++ b/examples/layers/android/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ diff --git a/examples/platform_channel/android/app/src/main/AndroidManifest.xml b/examples/platform_channel/android/app/src/main/AndroidManifest.xml index 290a6ce37d..e139fbd4e9 100644 --- a/examples/platform_channel/android/app/src/main/AndroidManifest.xml +++ b/examples/platform_channel/android/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ diff --git a/examples/platform_view/android/app/src/main/AndroidManifest.xml b/examples/platform_view/android/app/src/main/AndroidManifest.xml index 3259eb26b8..5800ad7a54 100644 --- a/examples/platform_view/android/app/src/main/AndroidManifest.xml +++ b/examples/platform_view/android/app/src/main/AndroidManifest.xml @@ -20,7 +20,7 @@ android:name="io.flutter.examples.platform_view.MainActivity" android:launchMode="singleTop" android:theme="@android:style/Theme.Black.NoTitleBar" - android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" + android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> @@ -32,6 +32,6 @@ android:name="io.flutter.examples.platform_view.CountActivity" android:parentActivityName="io.flutter.examples.platform_view.MainActivity" android:theme="@style/Theme.AppCompat.NoActionBar" - android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"> + android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"> diff --git a/examples/stocks/android/app/src/main/AndroidManifest.xml b/examples/stocks/android/app/src/main/AndroidManifest.xml index 77ae740703..d4fda7aabd 100644 --- a/examples/stocks/android/app/src/main/AndroidManifest.xml +++ b/examples/stocks/android/app/src/main/AndroidManifest.xml @@ -21,7 +21,7 @@ diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index c842546fdc..7bcda400b1 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -245,8 +245,14 @@ class TextStyle extends Diagnosticable { /// During painting, the [fontSize] is multiplied by the current /// `textScaleFactor` to let users make it easier to read text by increasing /// its size. + /// + /// [getParagraphStyle] will default to 14 logical pixels if the font size + /// isn't specified here. final double fontSize; + // The default font size if none is specified. + static const double _defaultFontSize = 14.0; + /// The typeface thickness to use when painting the text (e.g., bold). final FontWeight fontWeight; @@ -444,6 +450,9 @@ class TextStyle extends Diagnosticable { /// The `textScaleFactor` argument must not be null. If omitted, it defaults /// to 1.0. The other arguments may be null. The `maxLines` argument, if /// specified and non-null, must be greater than zero. + /// + /// If the font size on this style isn't set, it will default to 14 logical + /// pixels. ui.ParagraphStyle getParagraphStyle({ TextAlign textAlign, TextDirection textDirection, @@ -459,7 +468,7 @@ class TextStyle extends Diagnosticable { fontWeight: fontWeight, fontStyle: fontStyle, fontFamily: fontFamily, - fontSize: fontSize == null ? null : fontSize * textScaleFactor, + fontSize: (fontSize ?? _defaultFontSize) * textScaleFactor, lineHeight: height, maxLines: maxLines, ellipsis: ellipsis, diff --git a/packages/flutter/lib/src/rendering/binding.dart b/packages/flutter/lib/src/rendering/binding.dart index b05d6689a9..782d098716 100644 --- a/packages/flutter/lib/src/rendering/binding.dart +++ b/packages/flutter/lib/src/rendering/binding.dart @@ -36,6 +36,7 @@ abstract class RendererBinding extends BindingBase with SchedulerBinding, Servic ); ui.window ..onMetricsChanged = handleMetricsChanged + ..onTextScaleFactorChanged = handleTextScaleFactorChanged ..onSemanticsEnabledChanged = _handleSemanticsEnabledChanged ..onSemanticsAction = _handleSemanticsAction; initRenderView(); @@ -143,6 +144,11 @@ abstract class RendererBinding extends BindingBase with SchedulerBinding, Servic renderView.configuration = createViewConfiguration(); } + /// Called when the platform text scale factor changes. + /// + /// See [Window.onTextScaleFactorChanged]. + void handleTextScaleFactorChanged() { } + /// Returns a [ViewConfiguration] configured for the [RenderView] based on the /// current environment. /// diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index c3cea17102..997c2ece82 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -398,6 +398,15 @@ class _WidgetsAppState extends State implements WidgetsBindingObserv }); } + @override + void didChangeTextScaleFactor() { + setState(() { + // The textScaleFactor property of ui.window has changed. We reference + // ui.window in our build function, so we need to call setState(), but + // we don't need to cache anything locally. + }); + } + @override void didChangeLocale(Locale locale) { if (locale == _locale) diff --git a/packages/flutter/lib/src/widgets/binding.dart b/packages/flutter/lib/src/widgets/binding.dart index b8e6f7c509..5870784804 100644 --- a/packages/flutter/lib/src/widgets/binding.dart +++ b/packages/flutter/lib/src/widgets/binding.dart @@ -90,7 +90,7 @@ abstract class WidgetsBindingObserver { /// navigator. /// /// Observers are expected to return true if they were able to - /// handle the notification. Observers are notified in registration + /// handle the notification. Observers are notified in registration /// order until one returns true. Future didPushRoute(String route) => new Future.value(false); @@ -133,7 +133,7 @@ abstract class WidgetsBindingObserver { /// /// @override /// Widget build(BuildContext context) { - /// return new Text('Last size: $_lastSize'); + /// return new Text('Current size: $_lastSize'); /// } /// } /// ``` @@ -148,6 +148,55 @@ abstract class WidgetsBindingObserver { /// boilerplate. void didChangeMetrics() { } + /// Called when the platform's text scale factor changes. + /// + /// This typically happens as the result of the user changing system + /// preferences, and it should affect all of the text sizes in the + /// application. + /// + /// ## Sample code + /// + /// ```dart + /// class TextScaleFactorReactor extends StatefulWidget { + /// const TextScaleFactorReactor({ Key key }) : super(key: key); + /// + /// @override + /// _TextScaleFactorReactorState createState() => new _TextScaleFactorReactorState(); + /// } + /// + /// class _TextScaleFactorReactorState extends State with WidgetsBindingObserver { + /// @override + /// void initState() { + /// super.initState(); + /// WidgetsBinding.instance.addObserver(this); + /// } + /// + /// @override + /// void dispose() { + /// WidgetsBinding.instance.removeObserver(this); + /// super.dispose(); + /// } + /// + /// double _lastTextScaleFactor; + /// + /// @override + /// void didChangeTextScaleFactor() { + /// setState(() { _lastTextScaleFactor = ui.window.textScaleFactor; }); + /// } + /// + /// @override + /// Widget build(BuildContext context) { + /// return new Text('Current scale factor: $_lastTextScaleFactor'); + /// } + /// } + /// ``` + /// + /// See also: + /// + /// * [MediaQuery.of], which provides a similar service with less + /// boilerplate. + void didChangeTextScaleFactor() { } + /// Called when the system tells the app that the user's locale has /// changed. For example, if the user changes the system language /// settings. @@ -284,12 +333,6 @@ abstract class WidgetsBinding extends BindingBase with GestureBinding, RendererB /// * [WidgetsBindingObserver], which has an example of using this method. bool removeObserver(WidgetsBindingObserver observer) => _observers.remove(observer); - /// Called when the system metrics change. - /// - /// Notifies all the observers using - /// [WidgetsBindingObserver.didChangeMetrics]. - /// - /// See [Window.onMetricsChanged]. @override void handleMetricsChanged() { super.handleMetricsChanged(); @@ -297,6 +340,13 @@ abstract class WidgetsBinding extends BindingBase with GestureBinding, RendererB observer.didChangeMetrics(); } + @override + void handleTextScaleFactorChanged() { + super.handleTextScaleFactorChanged(); + for (WidgetsBindingObserver observer in _observers) + observer.didChangeTextScaleFactor(); + } + /// Called when the system locale changes. /// /// Calls [dispatchLocaleChanged] to notify the binding observers. diff --git a/packages/flutter/lib/src/widgets/media_query.dart b/packages/flutter/lib/src/widgets/media_query.dart index 12cc7d1b8f..f29e81499d 100644 --- a/packages/flutter/lib/src/widgets/media_query.dart +++ b/packages/flutter/lib/src/widgets/media_query.dart @@ -52,7 +52,7 @@ class MediaQueryData { MediaQueryData.fromWindow(ui.Window window) : size = window.physicalSize / window.devicePixelRatio, devicePixelRatio = window.devicePixelRatio, - textScaleFactor = 1.0, // TODO(abarth): Read this value from window. + textScaleFactor = window.textScaleFactor, padding = new EdgeInsets.fromWindowPadding(window.padding, window.devicePixelRatio); /// The size of the media in logical pixel (e.g, the size of the screen). @@ -147,7 +147,10 @@ class MediaQueryData { int get hashCode => hashValues(size, devicePixelRatio, textScaleFactor, padding); @override - String toString() => '$runtimeType(size: $size, devicePixelRatio: $devicePixelRatio, textScaleFactor: $textScaleFactor, padding: $padding)'; + String toString() { + return '$runtimeType(size: $size, devicePixelRatio: $devicePixelRatio, ' + 'textScaleFactor: $textScaleFactor, padding: $padding)'; + } } /// Establishes a subtree in which media queries resolve to the given data. diff --git a/packages/flutter/lib/src/widgets/text.dart b/packages/flutter/lib/src/widgets/text.dart index 916f148df5..b8165f7671 100644 --- a/packages/flutter/lib/src/widgets/text.dart +++ b/packages/flutter/lib/src/widgets/text.dart @@ -249,7 +249,8 @@ class Text extends StatelessWidget { /// For example, if the text scale factor is 1.5, text will be 50% larger than /// the specified font size. /// - /// Defaults to the [MediaQueryData.textScaleFactor] obtained from the ambient + /// The value given to the constructor as textScaleFactor. If null, will + /// use the [MediaQueryData.textScaleFactor] obtained from the ambient /// [MediaQuery], or 1.0 if there is no [MediaQuery] in scope. final double textScaleFactor; diff --git a/packages/flutter/test/material/app_test.dart b/packages/flutter/test/material/app_test.dart index 34f5c2d094..f17dd54892 100644 --- a/packages/flutter/test/material/app_test.dart +++ b/packages/flutter/test/material/app_test.dart @@ -305,4 +305,16 @@ void main() { expect(tester.takeException(), isFlutterError); expect(log, ['onGenerateRoute /', 'onUnknownRoute /']); }); + + testWidgets('Can get text scale from media query', (WidgetTester tester) async { + double textScaleFactor; + await tester.pumpWidget(new MaterialApp( + home: new Builder(builder:(BuildContext context) { + textScaleFactor = MediaQuery.of(context).textScaleFactor; + return new Container(); + }), + )); + expect(textScaleFactor, isNotNull); + expect(textScaleFactor, equals(1.0)); + }); } diff --git a/packages/flutter/test/material/buttons_test.dart b/packages/flutter/test/material/buttons_test.dart index 213ad330a2..65f673ea6e 100644 --- a/packages/flutter/test/material/buttons_test.dart +++ b/packages/flutter/test/material/buttons_test.dart @@ -44,6 +44,46 @@ void main() { semantics.dispose(); }); + testWidgets('Does FlatButton scale with font scale changes', (WidgetTester tester) async { + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Material( + child: new MediaQuery( + data: const MediaQueryData(textScaleFactor: 1.0), + child: new Center( + child: new FlatButton( + onPressed: () { }, + child: const Text('ABC'), + ), + ), + ), + ), + ), + ); + + expect(tester.getSize(find.byType(FlatButton)), equals(const Size(88.0, 36.0))); + + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new Material( + child: new MediaQuery( + data: const MediaQueryData(textScaleFactor: 1.3), + child: new Center( + child: new FlatButton( + onPressed: () { }, + child: const Text('ABC'), + ), + ), + ), + ), + ), + ); + + expect(tester.getSize(find.byType(FlatButton)), equals(const Size(88.0, 36.0))); + }); + // This test is very similar to the '...explicit splashColor and highlightColor' test // in icon_button_test.dart. If you change this one, you may want to also change that one. testWidgets('MaterialButton with explicit splashColor and highlightColor', (WidgetTester tester) async { diff --git a/packages/flutter/test/painting/text_painter_test.dart b/packages/flutter/test/painting/text_painter_test.dart index 7a86425cb5..cba1a330d4 100644 --- a/packages/flutter/test/painting/text_painter_test.dart +++ b/packages/flutter/test/painting/text_painter_test.dart @@ -57,6 +57,23 @@ void main() { expect(painter.size, const Size(123.0, 123.0)); }); + test('TextPainter textScaleFactor test', () { + final TextPainter painter = new TextPainter( + text: const TextSpan( + text: 'X', + style: const TextStyle( + inherit: false, + fontFamily: 'Ahem', + fontSize: 10.0, + ), + ), + textDirection: TextDirection.ltr, + textScaleFactor: 2.0, + ); + painter.layout(); + expect(painter.size, const Size(20.0, 20.0)); + }); + test('TextPainter default text height is 14 pixels', () { final TextPainter painter = new TextPainter( text: const TextSpan(text: 'x'), diff --git a/packages/flutter/test/painting/text_style_test.dart b/packages/flutter/test/painting/text_style_test.dart index a9d3d3705c..b5f41fd671 100644 --- a/packages/flutter/test/painting/text_style_test.dart +++ b/packages/flutter/test/painting/text_style_test.dart @@ -125,12 +125,12 @@ void main() { test('TextStyle with text direction', () { final ui.ParagraphStyle ps6 = const TextStyle().getParagraphStyle(textDirection: TextDirection.ltr); - expect(ps6, equals(new ui.ParagraphStyle(textDirection: TextDirection.ltr))); - expect(ps6.toString(), 'ParagraphStyle(textAlign: unspecified, textDirection: TextDirection.ltr, fontWeight: unspecified, fontStyle: unspecified, maxLines: unspecified, fontFamily: unspecified, fontSize: unspecified, lineHeight: unspecified, ellipsis: unspecified)'); + expect(ps6, equals(new ui.ParagraphStyle(textDirection: TextDirection.ltr, fontSize: 14.0))); + expect(ps6.toString(), 'ParagraphStyle(textAlign: unspecified, textDirection: TextDirection.ltr, fontWeight: unspecified, fontStyle: unspecified, maxLines: unspecified, fontFamily: unspecified, fontSize: 14.0, lineHeight: unspecified, ellipsis: unspecified)'); final ui.ParagraphStyle ps7 = const TextStyle().getParagraphStyle(textDirection: TextDirection.rtl); - expect(ps7, equals(new ui.ParagraphStyle(textDirection: TextDirection.rtl))); - expect(ps7.toString(), 'ParagraphStyle(textAlign: unspecified, textDirection: TextDirection.rtl, fontWeight: unspecified, fontStyle: unspecified, maxLines: unspecified, fontFamily: unspecified, fontSize: unspecified, lineHeight: unspecified, ellipsis: unspecified)'); + expect(ps7, equals(new ui.ParagraphStyle(textDirection: TextDirection.rtl, fontSize: 14.0))); + expect(ps7.toString(), 'ParagraphStyle(textAlign: unspecified, textDirection: TextDirection.rtl, fontWeight: unspecified, fontStyle: unspecified, maxLines: unspecified, fontFamily: unspecified, fontSize: 14.0, lineHeight: unspecified, ellipsis: unspecified)'); }); test('TextStyle using package font', () { diff --git a/packages/flutter/test/rendering/paragraph_test.dart b/packages/flutter/test/rendering/paragraph_test.dart index 62f3e58ac6..28ddc5e978 100644 --- a/packages/flutter/test/rendering/paragraph_test.dart +++ b/packages/flutter/test/rendering/paragraph_test.dart @@ -222,6 +222,64 @@ void main() { expect(paragraph.debugNeedsPaint, isFalse); }); + test('nested TextSpans in paragraph handle textScaleFactor correctly.', () { + final TextSpan testSpan = const TextSpan( + text: 'a', + style: const TextStyle( + fontSize: 10.0, + ), + children: const [ + const TextSpan( + text: 'b', + children: const [ + const TextSpan(text: 'c'), + ], + style: const TextStyle( + fontSize: 20.0, + ), + ), + const TextSpan( + text: 'd', + ), + ], + ); + final RenderParagraph paragraph = new RenderParagraph( + testSpan, + textDirection: TextDirection.ltr, + textScaleFactor: 1.3 + ); + paragraph.layout(const BoxConstraints()); + // anyOf is needed here because Linux and Mac have different text + // rendering widths in tests. + // TODO(#12357): Figure out why this is, and fix it (if needed) once Blink + // text rendering is replaced. + expect(paragraph.size.width, anyOf(79.0, 78.0)); + expect(paragraph.size.height, 26.0); + + // Test the sizes of nested spans. + final List boxes = []; + final String text = testSpan.toStringDeep(); + for (int i = 0; i < text.length; ++i) { + boxes.addAll(paragraph.getBoxesForSelection( + new TextSelection(baseOffset: i, extentOffset: i + 1) + )); + } + expect(boxes.length, equals(4)); + + // anyOf is needed here and below because Linux and Mac have different text + // rendering widths in tests. + // TODO(#12357): Figure out why this is, and fix it (if needed) once Blink + // text rendering is replaced. + expect(boxes[0].toRect().width, anyOf(14.0, 13.0)); + expect(boxes[0].toRect().height, 13.0); + expect(boxes[1].toRect().width, anyOf(27.0, 26.0)); + expect(boxes[1].toRect().height, 26.0); + expect(boxes[2].toRect().width, anyOf(27.0, 26.0)); + expect(boxes[2].toRect().height, 26.0); + expect(boxes[3].toRect().width, anyOf(14.0, 13.0)); + expect(boxes[3].toRect().height, 13.0); + }); + test('toStringDeep', () { final RenderParagraph paragraph = new RenderParagraph( const TextSpan(text: _kText), diff --git a/packages/flutter/test/widgets/text_test.dart b/packages/flutter/test/widgets/text_test.dart index e82b62b146..b1a2f9c15b 100644 --- a/packages/flutter/test/widgets/text_test.dart +++ b/packages/flutter/test/widgets/text_test.dart @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; void main() { testWidgets('Text respects media query', (WidgetTester tester) async { await tester.pumpWidget(const MediaQuery( - data: const MediaQueryData(textScaleFactor: 1.5), + data: const MediaQueryData(textScaleFactor: 1.3), child: const Center( child: const Text('Hello', textDirection: TextDirection.ltr) ) @@ -16,7 +16,7 @@ void main() { RichText text = tester.firstWidget(find.byType(RichText)); expect(text, isNotNull); - expect(text.textScaleFactor, 1.5); + expect(text.textScaleFactor, 1.3); await tester.pumpWidget(const Center( child: const Text('Hello', textDirection: TextDirection.ltr) @@ -25,14 +25,58 @@ void main() { text = tester.firstWidget(find.byType(RichText)); expect(text, isNotNull); expect(text.textScaleFactor, 1.0); + }); + + testWidgets('Text respects textScaleFactor with default font size', (WidgetTester tester) async { + await tester.pumpWidget( + const Center(child: const Text('Hello', textDirection: TextDirection.ltr)) + ); + + RichText text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaleFactor, 1.0); + final Size baseSize = tester.getSize(find.byType(RichText)); + expect(baseSize.width, equals(70.0)); + expect(baseSize.height, equals(14.0)); await tester.pumpWidget(const Center( - child: const Text('Hello', textScaleFactor: 3.0, textDirection: TextDirection.ltr) + child: const Text('Hello', textScaleFactor: 1.5, textDirection: TextDirection.ltr) )); text = tester.firstWidget(find.byType(RichText)); expect(text, isNotNull); - expect(text.textScaleFactor, 3.0); + expect(text.textScaleFactor, 1.5); + final Size largeSize = tester.getSize(find.byType(RichText)); + expect(largeSize.width, 105.0); + expect(largeSize.height, equals(21.0)); + }); + + testWidgets('Text respects textScaleFactor with explicit font size', (WidgetTester tester) async { + await tester.pumpWidget(const Center( + child: const Text('Hello', + style: const TextStyle(fontSize: 20.0), textDirection: TextDirection.ltr) + )); + + RichText text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaleFactor, 1.0); + final Size baseSize = tester.getSize(find.byType(RichText)); + expect(baseSize.width, equals(100.0)); + expect(baseSize.height, equals(20.0)); + + await tester.pumpWidget(const Center( + child: const Text('Hello', + style: const TextStyle(fontSize: 20.0), + textScaleFactor: 1.3, + textDirection: TextDirection.ltr) + )); + + text = tester.firstWidget(find.byType(RichText)); + expect(text, isNotNull); + expect(text.textScaleFactor, 1.3); + final Size largeSize = tester.getSize(find.byType(RichText)); + expect(largeSize.width, anyOf(131.0, 130.0)); + expect(largeSize.height, equals(26.0)); }); testWidgets('Text throws a nice error message if there\'s no Directionality', (WidgetTester tester) async { diff --git a/packages/flutter_tools/templates/create/android.tmpl/app/src/main/AndroidManifest.xml.tmpl b/packages/flutter_tools/templates/create/android.tmpl/app/src/main/AndroidManifest.xml.tmpl index 875dcca639..fd9a139bdd 100644 --- a/packages/flutter_tools/templates/create/android.tmpl/app/src/main/AndroidManifest.xml.tmpl +++ b/packages/flutter_tools/templates/create/android.tmpl/app/src/main/AndroidManifest.xml.tmpl @@ -20,7 +20,7 @@ android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" - android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" + android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">