@@ -4158,4 +4158,64 @@ void main() {
4158
4158
4159
4159
expect(tester.getTopLeft(find.text(hintText)).dy, topPosition);
4160
4160
});
4161
+
4162
+ testWidgets("InputDecorator label width isn't affected by prefix or suffix", (WidgetTester tester) async {
4163
+ const String labelText = 'My Label';
4164
+ const String prefixText = 'The five boxing wizards jump quickly.';
4165
+ const String suffixText = 'Suffix';
4166
+
4167
+ Widget getLabeledInputDecorator(bool showFix) {
4168
+ return MaterialApp(
4169
+ home: Material(
4170
+ child: Builder(
4171
+ builder: (BuildContext context) {
4172
+ return Theme(
4173
+ data: Theme.of(context),
4174
+ child: Align(
4175
+ alignment: Alignment.topLeft,
4176
+ child: TextField(
4177
+ decoration: InputDecoration(
4178
+ icon: const Icon(Icons.assistant),
4179
+ prefixText: showFix ? prefixText : null,
4180
+ suffixText: showFix ? suffixText : null,
4181
+ suffixIcon: const Icon(Icons.threesixty),
4182
+ labelText: labelText,
4183
+ ),
4184
+ ),
4185
+ ),
4186
+ );
4187
+ },
4188
+ ),
4189
+ ),
4190
+ );
4191
+ }
4192
+
4193
+ // Build with no prefix or suffix.
4194
+ await tester.pumpWidget(getLabeledInputDecorator(false));
4195
+
4196
+ // Get the width of the label when there is no prefix/suffix.
4197
+ expect(find.text(prefixText), findsNothing);
4198
+ expect(find.text(suffixText), findsNothing);
4199
+ final double labelWidth = tester.getSize(find.text(labelText)).width;
4200
+
4201
+ // Build with a prefix and suffix.
4202
+ await tester.pumpWidget(getLabeledInputDecorator(true));
4203
+
4204
+ // The prefix and suffix exist but aren't visible. They have not affected
4205
+ // the width of the label.
4206
+ expect(find.text(prefixText), findsOneWidget);
4207
+ expect(getOpacity(tester, prefixText), 0.0);
4208
+ expect(find.text(suffixText), findsOneWidget);
4209
+ expect(getOpacity(tester, suffixText), 0.0);
4210
+ expect(tester.getSize(find.text(labelText)).width, labelWidth);
4211
+
4212
+ // Tap to focus.
4213
+ await tester.tap(find.byType(TextField));
4214
+ await tester.pumpAndSettle();
4215
+
4216
+ // The prefix and suffix are visible, and the label is floating and still
4217
+ // hasn't had its width affected.
4218
+ expect(tester.getSize(find.text(labelText)).width, labelWidth);
4219
+ expect(getOpacity(tester, prefixText), 1.0);
4220
+ });
4161
4221
}
0 commit comments