RTL InputDecoration fix (#129661)
Fixes InputDecoration (TextField) layout when 1. RTL 2. prefixIcon and 3. left/right contentPadding is asymmetric.
diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart
index c54ba8a..d957c7a 100644
--- a/packages/flutter/lib/src/material/input_decorator.dart
+++ b/packages/flutter/lib/src/material/input_decorator.dart
@@ -1410,7 +1410,7 @@
double start = right - _boxSize(icon).width;
double end = left;
if (prefixIcon != null) {
- start += contentPadding.left;
+ start += contentPadding.right;
start -= centerLayout(prefixIcon!, start - prefixIcon!.size.width);
}
if (label != null) {
diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart
index 4d543a8..7755053 100644
--- a/packages/flutter/test/material/input_decorator_test.dart
+++ b/packages/flutter/test/material/input_decorator_test.dart
@@ -6516,5 +6516,35 @@
final Text hintTextWidget = tester.widget(hintTextFinder);
expect(hintTextWidget.style!.overflow, decoration.hintStyle!.overflow);
});
+
+ testWidgets('prefixIcon in RTL with asymmetric padding', (WidgetTester tester) async {
+ // Regression test for https://github.com/flutter/flutter/issues/129591
+ const InputDecoration decoration = InputDecoration(
+ contentPadding: EdgeInsetsDirectional.only(end: 24),
+ prefixIcon: Focus(child: Icon(Icons.search)),
+ );
+
+ await tester.pumpWidget(
+ buildInputDecorator(
+ useMaterial3: useMaterial3,
+ // isEmpty: false (default)
+ // isFocused: false (default)
+ decoration: decoration,
+ textDirection: TextDirection.rtl,
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ expect(find.byType(InputDecorator), findsOneWidget);
+ expect(find.byType(Icon), findsOneWidget);
+
+ final Offset(dx: double decoratorRight) =
+ tester.getTopRight(find.byType(InputDecorator));
+ final Offset(dx: double prefixRight) =
+ tester.getTopRight(find.byType(Icon));
+
+ // The prefix is inside the decorator.
+ expect(decoratorRight, lessThanOrEqualTo(prefixRight));
+ });
}
}