@@ -26,6 +26,7 @@ Widget buildInputDecorator({
26
26
bool isFocused = false ,
27
27
bool isHovering = false ,
28
28
bool useMaterial3 = false ,
29
+ bool useIntrinsicWidth = false ,
29
30
TextStyle ? baseStyle,
30
31
TextAlignVertical ? textAlignVertical,
31
32
VisualDensity ? visualDensity,
@@ -34,6 +35,21 @@ Widget buildInputDecorator({
34
35
style: TextStyle (fontSize: 16.0 ),
35
36
),
36
37
}) {
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
+
37
53
return MaterialApp (
38
54
theme: ThemeData (useMaterial3: false ),
39
55
home: Material (
@@ -50,16 +66,7 @@ Widget buildInputDecorator({
50
66
alignment: Alignment .topLeft,
51
67
child: Directionality (
52
68
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,
63
70
),
64
71
),
65
72
);
@@ -6890,6 +6897,48 @@ testWidgetsWithLeakTracking('OutlineInputBorder with BorderRadius.zero should dr
6890
6897
expect (decoratorRight, lessThanOrEqualTo (prefixRight));
6891
6898
});
6892
6899
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
+
6893
6942
testWidgetsWithLeakTracking ('InputDecorator with counter does not crash when given a 0 size' , (WidgetTester tester) async {
6894
6943
// Regression test for https://github.com/flutter/flutter/issues/129611
6895
6944
const InputDecoration decoration = InputDecoration (
0 commit comments