-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always relies on floatingLabelStyle when FloatingLabelBehavior.always #147374
Always relies on floatingLabelStyle when FloatingLabelBehavior.always #147374
Conversation
@@ -2155,7 +2155,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat | |||
child: AnimatedDefaultTextStyle( | |||
duration:_kTransitionDuration, | |||
curve: _kTransitionCurve, | |||
style: widget._labelShouldWithdraw | |||
style: widget._labelShouldWithdraw || decoration.floatingLabelBehavior == FloatingLabelBehavior.always |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if _labelShouldWithdraw
should just take into account decoration.floatingLabelBehavior == FloatingLabelBehavior.always
. I looked through the usages in this file and it is almost always used along with decoration.floatingLabelBehavior == FloatingLabelBehavior.always
so it seems reasonable. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my first thinking.
Then I saw the _labelShouldWithdraw
usage related to Semantics and prefix/suffix and I was not sure of the consequences.
See
flutter/packages/flutter/lib/src/material/input_decorator.dart
Lines 2176 to 2200 in 5f0628d
final bool needsSemanticsSortOrder = widget._labelShouldWithdraw && (input != null ? (hasPrefix || hasSuffix) : (hasPrefix && hasSuffix)); | |
final Widget? prefix = hasPrefix | |
? _AffixText( | |
labelIsFloating: widget._labelShouldWithdraw, | |
text: decoration.prefixText, | |
style: MaterialStateProperty.resolveAs(decoration.prefixStyle, materialState) ?? hintStyle, | |
semanticsSortKey: needsSemanticsSortOrder ? _kPrefixSemanticsSortOrder : null, | |
semanticsTag: _kPrefixSemanticsTag, | |
child: decoration.prefix, | |
) | |
: null; | |
final Widget? suffix = hasSuffix | |
? _AffixText( | |
labelIsFloating: widget._labelShouldWithdraw, | |
text: decoration.suffixText, | |
style: MaterialStateProperty.resolveAs(decoration.suffixStyle, materialState) ?? hintStyle, | |
semanticsSortKey: needsSemanticsSortOrder ? _kSuffixSemanticsSortOrder : null, | |
semanticsTag: _kSuffixSemanticsTag, | |
child: decoration.suffix, | |
) | |
: null; | |
if (input != null && needsSemanticsSortOrder) { |
But reconsidering this, moving the check to _labelShouldWithdraw
makes sense and improve readibility because it simplifies several clauses.
I will push an update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think it makes sense to change this even in the semantics case, since its depending on whether the label is floating. I'll keep an eye out if this causes any issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution @bleroux, and for all the tests!
a0ae9c4
to
11d9fad
Compare
@@ -1789,8 +1789,11 @@ class InputDecorator extends StatefulWidget { | |||
/// Whether the label needs to get out of the way of the input, either by | |||
/// floating or disappearing. | |||
/// | |||
/// Will withdraw when not empty, or when focused while enabled. | |||
bool get _labelShouldWithdraw => !isEmpty || (isFocused && decoration.enabled); | |||
/// Will withdraw when not empty, or when focused while enabled, or when |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think you can get rid of the first or
in this sentence.
11d9fad
to
6cd69f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM w/ small nit. Thanks for the contribution!
I'll check on the google testing issues @bleroux. |
6cd69f2
to
9533a27
Compare
@bleroux There is one test failure that i'm not too sure is expected or not. Before this change the flutter/packages/flutter/lib/src/material/input_decorator.dart Lines 2178 to 2198 in 3b2bfc7
_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 Many thanks for the detailed information.
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. |
9533a27
to
7be6c58
Compare
7be6c58
to
bed083b
Compare
@Renzo-Olivares 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). |
flutter/flutter@f1037a0...04424e1 2024-05-06 [email protected] Roll Flutter Engine from f2bfea5fdecd to a30ae7729c95 (1 revision) (flutter/flutter#147865) 2024-05-06 [email protected] Fix Tooltip.decoration comment (flutter/flutter#147858) 2024-05-06 [email protected] Roll Flutter Engine from e2b828f368f6 to f2bfea5fdecd (1 revision) (flutter/flutter#147854) 2024-05-06 [email protected] Roll Flutter Engine from c73fd390d10e to e2b828f368f6 (1 revision) (flutter/flutter#147853) 2024-05-06 [email protected] Roll Flutter Engine from 624dcb987f39 to c73fd390d10e (1 revision) (flutter/flutter#147852) 2024-05-05 [email protected] Roll Flutter Engine from 900322f23375 to 624dcb987f39 (1 revision) (flutter/flutter#147845) 2024-05-05 [email protected] Roll Flutter Engine from 9080957cd6a0 to 900322f23375 (1 revision) (flutter/flutter#147842) 2024-05-05 [email protected] Roll Flutter Engine from 66d08d55d788 to 9080957cd6a0 (1 revision) (flutter/flutter#147841) 2024-05-05 [email protected] Fix test. (flutter/flutter#147813) 2024-05-05 [email protected] Fix memory leaks in `CupertinoSwitch` (flutter/flutter#147821) 2024-05-05 [email protected] Reland fix memory leaks for tab selector (flutter/flutter#147689) 2024-05-05 [email protected] Fix memory leak in ExpansionTile. (flutter/flutter#147596) 2024-05-04 [email protected] Roll Flutter Engine from 135acd5a689a to 66d08d55d788 (2 revisions) (flutter/flutter#147834) 2024-05-04 [email protected] Roll Flutter Engine from c937a02c6eb0 to 135acd5a689a (2 revisions) (flutter/flutter#147818) 2024-05-04 [email protected] Roll Flutter Engine from 1d484e57ce2c to c937a02c6eb0 (2 revisions) (flutter/flutter#147812) 2024-05-03 [email protected] Roll Flutter Engine from 2561636602ed to 1d484e57ce2c (1 revision) (flutter/flutter#147808) 2024-05-03 [email protected] Roll Flutter Engine from 484574426120 to 2561636602ed (1 revision) (flutter/flutter#147805) 2024-05-03 [email protected] Roll Flutter Engine from d701f407c8ea to 484574426120 (1 revision) (flutter/flutter#147802) 2024-05-03 [email protected] Roll Flutter Engine from 250536888a91 to d701f407c8ea (2 revisions) (flutter/flutter#147800) 2024-05-03 [email protected] Roll Flutter Engine from 3eadfd5284c0 to 250536888a91 (1 revision) (flutter/flutter#147796) 2024-05-03 [email protected] Roll Flutter Engine from 837914f3788b to 3eadfd5284c0 (1 revision) (flutter/flutter#147791) 2024-05-03 [email protected] fixes `SearchAnchor` leak (flutter/flutter#147652) 2024-05-03 [email protected] Roll Flutter Engine from 8cce00433073 to 837914f3788b (1 revision) (flutter/flutter#147780) 2024-05-03 [email protected] Roll Packages from aea93d2 to f4719ca (5 revisions) (flutter/flutter#147782) 2024-05-03 [email protected] Always relies on floatingLabelStyle when FloatingLabelBehavior.always (flutter/flutter#147374) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/flutter@f1037a0...04424e1 2024-05-06 [email protected] Roll Flutter Engine from f2bfea5fdecd to a30ae7729c95 (1 revision) (flutter/flutter#147865) 2024-05-06 [email protected] Fix Tooltip.decoration comment (flutter/flutter#147858) 2024-05-06 [email protected] Roll Flutter Engine from e2b828f368f6 to f2bfea5fdecd (1 revision) (flutter/flutter#147854) 2024-05-06 [email protected] Roll Flutter Engine from c73fd390d10e to e2b828f368f6 (1 revision) (flutter/flutter#147853) 2024-05-06 [email protected] Roll Flutter Engine from 624dcb987f39 to c73fd390d10e (1 revision) (flutter/flutter#147852) 2024-05-05 [email protected] Roll Flutter Engine from 900322f23375 to 624dcb987f39 (1 revision) (flutter/flutter#147845) 2024-05-05 [email protected] Roll Flutter Engine from 9080957cd6a0 to 900322f23375 (1 revision) (flutter/flutter#147842) 2024-05-05 [email protected] Roll Flutter Engine from 66d08d55d788 to 9080957cd6a0 (1 revision) (flutter/flutter#147841) 2024-05-05 [email protected] Fix test. (flutter/flutter#147813) 2024-05-05 [email protected] Fix memory leaks in `CupertinoSwitch` (flutter/flutter#147821) 2024-05-05 [email protected] Reland fix memory leaks for tab selector (flutter/flutter#147689) 2024-05-05 [email protected] Fix memory leak in ExpansionTile. (flutter/flutter#147596) 2024-05-04 [email protected] Roll Flutter Engine from 135acd5a689a to 66d08d55d788 (2 revisions) (flutter/flutter#147834) 2024-05-04 [email protected] Roll Flutter Engine from c937a02c6eb0 to 135acd5a689a (2 revisions) (flutter/flutter#147818) 2024-05-04 [email protected] Roll Flutter Engine from 1d484e57ce2c to c937a02c6eb0 (2 revisions) (flutter/flutter#147812) 2024-05-03 [email protected] Roll Flutter Engine from 2561636602ed to 1d484e57ce2c (1 revision) (flutter/flutter#147808) 2024-05-03 [email protected] Roll Flutter Engine from 484574426120 to 2561636602ed (1 revision) (flutter/flutter#147805) 2024-05-03 [email protected] Roll Flutter Engine from d701f407c8ea to 484574426120 (1 revision) (flutter/flutter#147802) 2024-05-03 [email protected] Roll Flutter Engine from 250536888a91 to d701f407c8ea (2 revisions) (flutter/flutter#147800) 2024-05-03 [email protected] Roll Flutter Engine from 3eadfd5284c0 to 250536888a91 (1 revision) (flutter/flutter#147796) 2024-05-03 [email protected] Roll Flutter Engine from 837914f3788b to 3eadfd5284c0 (1 revision) (flutter/flutter#147791) 2024-05-03 [email protected] fixes `SearchAnchor` leak (flutter/flutter#147652) 2024-05-03 [email protected] Roll Flutter Engine from 8cce00433073 to 837914f3788b (1 revision) (flutter/flutter#147780) 2024-05-03 [email protected] Roll Packages from aea93d2 to f4719ca (5 revisions) (flutter/flutter#147782) 2024-05-03 [email protected] Always relies on floatingLabelStyle when FloatingLabelBehavior.always (flutter/flutter#147374) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/flutter@f1037a0...04424e1 2024-05-06 [email protected] Roll Flutter Engine from f2bfea5fdecd to a30ae7729c95 (1 revision) (flutter/flutter#147865) 2024-05-06 [email protected] Fix Tooltip.decoration comment (flutter/flutter#147858) 2024-05-06 [email protected] Roll Flutter Engine from e2b828f368f6 to f2bfea5fdecd (1 revision) (flutter/flutter#147854) 2024-05-06 [email protected] Roll Flutter Engine from c73fd390d10e to e2b828f368f6 (1 revision) (flutter/flutter#147853) 2024-05-06 [email protected] Roll Flutter Engine from 624dcb987f39 to c73fd390d10e (1 revision) (flutter/flutter#147852) 2024-05-05 [email protected] Roll Flutter Engine from 900322f23375 to 624dcb987f39 (1 revision) (flutter/flutter#147845) 2024-05-05 [email protected] Roll Flutter Engine from 9080957cd6a0 to 900322f23375 (1 revision) (flutter/flutter#147842) 2024-05-05 [email protected] Roll Flutter Engine from 66d08d55d788 to 9080957cd6a0 (1 revision) (flutter/flutter#147841) 2024-05-05 [email protected] Fix test. (flutter/flutter#147813) 2024-05-05 [email protected] Fix memory leaks in `CupertinoSwitch` (flutter/flutter#147821) 2024-05-05 [email protected] Reland fix memory leaks for tab selector (flutter/flutter#147689) 2024-05-05 [email protected] Fix memory leak in ExpansionTile. (flutter/flutter#147596) 2024-05-04 [email protected] Roll Flutter Engine from 135acd5a689a to 66d08d55d788 (2 revisions) (flutter/flutter#147834) 2024-05-04 [email protected] Roll Flutter Engine from c937a02c6eb0 to 135acd5a689a (2 revisions) (flutter/flutter#147818) 2024-05-04 [email protected] Roll Flutter Engine from 1d484e57ce2c to c937a02c6eb0 (2 revisions) (flutter/flutter#147812) 2024-05-03 [email protected] Roll Flutter Engine from 2561636602ed to 1d484e57ce2c (1 revision) (flutter/flutter#147808) 2024-05-03 [email protected] Roll Flutter Engine from 484574426120 to 2561636602ed (1 revision) (flutter/flutter#147805) 2024-05-03 [email protected] Roll Flutter Engine from d701f407c8ea to 484574426120 (1 revision) (flutter/flutter#147802) 2024-05-03 [email protected] Roll Flutter Engine from 250536888a91 to d701f407c8ea (2 revisions) (flutter/flutter#147800) 2024-05-03 [email protected] Roll Flutter Engine from 3eadfd5284c0 to 250536888a91 (1 revision) (flutter/flutter#147796) 2024-05-03 [email protected] Roll Flutter Engine from 837914f3788b to 3eadfd5284c0 (1 revision) (flutter/flutter#147791) 2024-05-03 [email protected] fixes `SearchAnchor` leak (flutter/flutter#147652) 2024-05-03 [email protected] Roll Flutter Engine from 8cce00433073 to 837914f3788b (1 revision) (flutter/flutter#147780) 2024-05-03 [email protected] Roll Packages from aea93d2 to f4719ca (5 revisions) (flutter/flutter#147782) 2024-05-03 [email protected] Always relies on floatingLabelStyle when FloatingLabelBehavior.always (flutter/flutter#147374) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Description
With this PR, when
InputDecorator.floatingLabelBehavior
is set toFloatingLabelBehavior.always
the label style is always set toInputDecorator.floatingLabelStyle
, previouslyInputDecorator.labelStyle
was used when the field was not focused or was empty.Related Issue
Fixes #147231
Tests
Adds 1 test for this particular issue and several missing tests.