@@ -26,6 +26,7 @@ Widget buildInputDecorator({
2626 bool isFocused = false ,
2727 bool isHovering = false ,
2828 bool useMaterial3 = false ,
29+ bool useIntrinsicWidth = false ,
2930 TextStyle ? baseStyle,
3031 TextAlignVertical ? textAlignVertical,
3132 VisualDensity ? visualDensity,
@@ -34,6 +35,21 @@ Widget buildInputDecorator({
3435 style: TextStyle (fontSize: 16.0 ),
3536 ),
3637}) {
38+ Widget widget = InputDecorator (
39+ expands: expands,
40+ decoration: decoration,
41+ isEmpty: isEmpty,
42+ isFocused: isFocused,
43+ isHovering: isHovering,
44+ baseStyle: baseStyle,
45+ textAlignVertical: textAlignVertical,
46+ child: child,
47+ );
48+
49+ if (useIntrinsicWidth) {
50+ widget = IntrinsicWidth (child: widget);
51+ }
52+
3753 return MaterialApp (
3854 theme: ThemeData (useMaterial3: false ),
3955 home: Material (
@@ -50,16 +66,7 @@ Widget buildInputDecorator({
5066 alignment: Alignment .topLeft,
5167 child: Directionality (
5268 textDirection: textDirection,
53- child: InputDecorator (
54- expands: expands,
55- decoration: decoration,
56- isEmpty: isEmpty,
57- isFocused: isFocused,
58- isHovering: isHovering,
59- baseStyle: baseStyle,
60- textAlignVertical: textAlignVertical,
61- child: child,
62- ),
69+ child: widget,
6370 ),
6471 ),
6572 );
@@ -6890,6 +6897,48 @@ testWidgetsWithLeakTracking('OutlineInputBorder with BorderRadius.zero should dr
68906897 expect (decoratorRight, lessThanOrEqualTo (prefixRight));
68916898 });
68926899
6900+ testWidgetsWithLeakTracking ('instrinic width with prefixIcon/suffixIcon' , (WidgetTester tester) async {
6901+ // Regression test for https://github.com/flutter/flutter/issues/137937
6902+ for (final TextDirection direction in TextDirection .values) {
6903+ Future <Size > measureText (InputDecoration decoration) async {
6904+ await tester.pumpWidget (
6905+ buildInputDecorator (
6906+ useMaterial3: useMaterial3,
6907+ // isEmpty: false (default)
6908+ // isFocused: false (default)
6909+ decoration: decoration,
6910+ useIntrinsicWidth: true ,
6911+ textDirection: direction,
6912+ ),
6913+ );
6914+ await tester.pumpAndSettle ();
6915+
6916+ expect (find.text ('text' ), findsOneWidget);
6917+
6918+ return tester.renderObject <RenderBox >(find.text ('text' )).size;
6919+ }
6920+
6921+ const EdgeInsetsGeometry padding = EdgeInsetsDirectional .only (end: 24 , start: 12 );
6922+
6923+ final Size textSizeWithoutIcons = await measureText (const InputDecoration (
6924+ contentPadding: padding,
6925+ ));
6926+
6927+ final Size textSizeWithPrefixIcon = await measureText (const InputDecoration (
6928+ contentPadding: padding,
6929+ prefixIcon: Focus (child: Icon (Icons .search)),
6930+ ));
6931+
6932+ final Size textSizeWithSuffixIcon = await measureText (const InputDecoration (
6933+ contentPadding: padding,
6934+ suffixIcon: Focus (child: Icon (Icons .search)),
6935+ ));
6936+
6937+ expect (textSizeWithPrefixIcon.width, equals (textSizeWithoutIcons.width), reason: 'text width is different with prefixIcon and $direction ' );
6938+ expect (textSizeWithSuffixIcon.width, equals (textSizeWithoutIcons.width), reason: 'text width is different with prefixIcon and $direction ' );
6939+ }
6940+ });
6941+
68936942 testWidgetsWithLeakTracking ('InputDecorator with counter does not crash when given a 0 size' , (WidgetTester tester) async {
68946943 // Regression test for https://github.com/flutter/flutter/issues/129611
68956944 const InputDecoration decoration = InputDecoration (
0 commit comments