flutter icon indicating copy to clipboard operation
flutter copied to clipboard

Always relies on floatingLabelStyle when FloatingLabelBehavior.always

Open bleroux opened this issue 10 months ago • 4 comments

Description

With this PR, when InputDecorator.floatingLabelBehavior is set to FloatingLabelBehavior.always the label style is always set to InputDecorator.floatingLabelStyle, previously InputDecorator.labelStyle was used when the field was not focused or was empty.

Related Issue

Fixes https://github.com/flutter/flutter/issues/147231

Tests

Adds 1 test for this particular issue and several missing tests.

bleroux avatar Apr 25 '24 14:04 bleroux

I'll check on the google testing issues @bleroux.

Renzo-Olivares avatar Apr 26 '24 21:04 Renzo-Olivares

@bleroux There is one test failure that i'm not too sure is expected or not. Before this change the prefix/prefixText would not show when the floatingLabelBehavior is set to FloatingLabelBehavior.always, and we unfocus the TextField. After this change the prefix/prefixText always shows when floatingLabelBehavior is set to FloatingLabelBehavior.always. Something similar also happens with suffix/suffixText. The main culprit is this block of code that builds the prefix and suffix https://github.com/flutter/flutter/blob/3b2bfc740f0dab7e8652bff80a9eadc87338c030/packages/flutter/lib/src/material/input_decorator.dart#L2178-L2198 . _AffixText depends on whether the label is floating to decide whether or not to visually show the prefix/suffix. Should the prefix/suffix always be displayed in this case? Let me know if this explanation was clear enough or if I can provide more context. I'm leaning towards the new behavior being the correct one, since I don't see a reason not to show the prefix if the label is floating.

Renzo-Olivares avatar Apr 30 '24 01:04 Renzo-Olivares

@Renzo-Olivares Many thanks for the detailed information.

I'm leaning towards the new behavior being the correct one, since I don't see a reason not to show the prefix if the label is floating.

I agree with you. I'm currently working on the M3 tests migration for prefix/suffix, I started looking closer at this behavior and I will post an update tomorrow to let you if I found anything that we missed.

bleroux avatar Apr 30 '24 13:04 bleroux

@Renzo-Olivares I had a closer look and I still fully agree with you on "since I don't see a reason not to show the prefix if the label is floating."

I have updated the PR with two tests related to that behavior (and I will probably add more on the PR I'm working on which goals is to migrate M3 tests related to prefix/suffix).

bleroux avatar May 01 '24 19:05 bleroux