@@ -3422,7 +3422,7 @@ void main() {
34223422 expect (tester.widget <Text >(find.text ('suffix' )).style! .color, suffixStyle.color);
34233423 expect (tester.widget <Text >(find.text ('helper' )).style! .color, helperStyle.color);
34243424 expect (tester.widget <Text >(find.text ('counter' )).style! .color, counterStyle.color);
3425- expect (getLabelStyle (tester).color, labelStyle .color);
3425+ expect (getLabelStyle (tester).color, hintStyle .color);
34263426 });
34273427
34283428 testWidgets ('InputDecorationTheme style overrides (focused)' , (WidgetTester tester) async {
@@ -5244,4 +5244,66 @@ void main() {
52445244 // Verify that the styles were passed along
52455245 expect (getLabelStyle (tester).color, labelStyle.color);
52465246 });
5247+
5248+ testWidgets ('hintStyle is used for labelText when labelText is on top of the input field and labelStyle is used for labelText when labelText moves above widget' , (WidgetTester tester) async {
5249+ const TextStyle style16 = TextStyle (fontFamily: 'Ahem' , fontSize: 16.0 );
5250+ final TextStyle labelStyle = style16.merge (const TextStyle (color: Colors .purple));
5251+ final TextStyle hintStyle = style16.merge (const TextStyle (color: Colors .red));
5252+
5253+ await tester.pumpWidget (
5254+ buildInputDecorator (
5255+ isEmpty: true ,
5256+ isFocused: false , // Label appears inline, on top of the input field.
5257+ decoration: InputDecoration (
5258+ labelText: 'label' ,
5259+ labelStyle: labelStyle,
5260+ hintStyle: hintStyle,
5261+ ),
5262+ ),
5263+ );
5264+
5265+ // Overall height for this InputDecorator is 56dps:
5266+ // 12 - top padding
5267+ // 12 - floating label (ahem font size 16dps * 0.75 = 12)
5268+ // 4 - floating label / input text gap
5269+ // 16 - input text (ahem font size 16dps)
5270+ // 12 - bottom padding
5271+ expect (tester.getSize (find.byType (InputDecorator )), const Size (800.0 , 56.0 ));
5272+ expect (tester.getTopLeft (find.text ('label' )).dy, 20.0 );
5273+ expect (tester.getBottomLeft (find.text ('label' )).dy, 36.0 );
5274+ expect (getBorderBottom (tester), 56.0 );
5275+ expect (getBorderWeight (tester), 1.0 );
5276+
5277+ // Verify that the hintStyle was used
5278+ expect (getLabelStyle (tester).color, hintStyle.color);
5279+
5280+ await tester.pumpWidget (
5281+ buildInputDecorator (
5282+ isEmpty: true ,
5283+ isFocused: true , // Label moves above (i.e., vertically adjacent to) the input field
5284+ decoration: InputDecoration (
5285+ labelText: 'label' ,
5286+ labelStyle: labelStyle,
5287+ hintStyle: hintStyle,
5288+ ),
5289+ ),
5290+ );
5291+
5292+ await tester.pumpAndSettle ();
5293+
5294+ // Overall height for this InputDecorator is 56dps:
5295+ // 12 - top padding
5296+ // 12 - floating label (ahem font size 16dps * 0.75 = 12)
5297+ // 4 - floating label / input text gap
5298+ // 16 - input text (ahem font size 16dps)
5299+ // 12 - bottom padding
5300+ expect (tester.getSize (find.byType (InputDecorator )), const Size (800.0 , 56.0 ));
5301+ expect (tester.getTopLeft (find.text ('label' )).dy, 12.0 );
5302+ expect (tester.getBottomLeft (find.text ('label' )).dy, 24.0 );
5303+ expect (getBorderBottom (tester), 56.0 );
5304+ expect (getBorderWeight (tester), 2.0 );
5305+
5306+ // Verify that the labelStyle was used
5307+ expect (getLabelStyle (tester).color, labelStyle.color);
5308+ });
52475309}
0 commit comments