diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index d75e878f89..44ae7e39d7 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -1835,7 +1835,7 @@ class _InputDecoratorState extends State with TickerProviderStat contentPadding = decorationContentPadding ?? EdgeInsets.zero; } else if (!border.isOutline) { // 4.0: the vertical gap between the inline elements and the floating label. - floatingLabelHeight = 4.0 + 0.75 * inlineLabelStyle.fontSize; + floatingLabelHeight = (4.0 + 0.75 * inlineLabelStyle.fontSize) * MediaQuery.textScaleFactorOf(context); if (decoration.filled == true) { // filled == null same as filled == false contentPadding = decorationContentPadding ?? (decorationIsDense ? const EdgeInsets.fromLTRB(12.0, 8.0, 12.0, 8.0) diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 34f2394ae8..813055e085 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'dart:io' show Platform; +import 'dart:ui' as ui show window; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -2942,4 +2943,30 @@ void main() { semantics.dispose(); }); + + testWidgets('floating label does not overlap with value at large textScaleFactors', (WidgetTester tester) async { + final TextEditingController controller = TextEditingController(text: 'Just some text'); + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: DefaultTextStyle( + style: const TextStyle(fontSize: 12.0, fontFamily: 'Ahem'), + child: MediaQuery( + data: MediaQueryData.fromWindow(ui.window).copyWith(textScaleFactor: 4.0), + child: Center( + child: TextField( + decoration: const InputDecoration(labelText: 'Label', border: UnderlineInputBorder()), + controller: controller, + ), + ), + ), + ), + ), + ), + ); + await tester.tap(find.byType(TextField)); + final Rect labelRect = tester.getRect(find.text('Label')); + final Rect fieldRect = tester.getRect(find.text('Just some text')); + expect(labelRect.bottom, lessThanOrEqualTo(fieldRect.top)); + }); }