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
TextField labelText doesn't use floatingLabelStyle when unfocused #147231
Comments
Thanks for the report. I'm also able to see the issue. The current workaround is to apply the same text style for labelStyle: Theme.of(context).textTheme.labelLarge!,
floatingLabelStyle: Theme.of(context).textTheme.labelLarge!, flutter doctor -v (stable and master)[✓] Flutter (Channel stable, 3.19.6, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.19.6 on channel stable at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 54e66469a9 (31 hours ago), 2024-04-17 13:08:03 -0700
• Engine revision c4cd48e186
• Dart version 3.3.4
• DevTools version 2.31.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
• Xcode at /Applications/Xcode15.3.app/Contents/Developer
• Build 15E204a
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.88.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.86.0
[✓] Connected device (3 available)
• RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 11 (API 30)
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.124
[✓] Network resources
• All expected network resources are available.
• No issues found! [!] Flutter (Channel master, 3.22.0-16.0.pre.39, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.22.0-16.0.pre.39 on channel master at /Users/huynq/Documents/GitHub/flutter_master
! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 49770cd929 (24 minutes ago), 2024-04-23 22:55:10 -0400
• Engine revision d4f63383d3
• Dart version 3.5.0 (build 3.5.0-92.0.dev)
• DevTools version 2.35.0-dev.8
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
• Xcode at /Applications/Xcode15.3.app/Contents/Developer
• Build 15E204a
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.88.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.86.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.79
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category. |
@huycozy My OP might have been a bit unclear, as the video shows the main issue but not the very small bump I mentioned here:
Here is a second video to show this behavior: Screen.Recording.2024-04-24.at.09.39.45.mov |
@theodelrieu Thanks for the detailed report. About the small animation you pointed in #147231 (comment). Code sampleimport 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
maxLines: 1,
decoration: InputDecoration(
floatingLabelBehavior: FloatingLabelBehavior.always,
labelText: 'label',
floatingLabelStyle: Theme.of(context).textTheme.labelLarge!,
labelStyle: Theme.of(context).textTheme.labelLarge!,
),
),
),
);
}
}
Can you try this code sample and see if you still get this animation? If not can you point out the difference with your own repro? |
Hello, I think I reproduced the issue with your code sample: Screen.Recording.2024-04-25.at.09.36.00.movIt might be an iOS-specific issue? I'm on macOS Sonoma (14.2.1), on a M1 chip. |
Thanks for the recording. 🙏 I will fill a PR to make |
@bleroux Thanks, apparently the animation fix was merged on Jan 24, how comes I still have the issue on the stable channel? Here's my Flutter 3.19.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 54e66469a9 (8 days ago) • 2024-04-17 13:08:03 -0700
Engine • revision c4cd48e186
Tools • Dart 3.3.4 • DevTools 2.31.1 |
@theodelrieu This wiki page explains how to find out which releases contain a particular commit. Another interesting page is the 3.19 changelog where one can see all the commits that were part of the stable release: https://docs.flutter.dev/release/release-notes/release-notes-3.19.0 |
Oh of course, thanks for the explanation! |
…#147374) ## 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 #147231 ## Tests Adds 1 test for this particular issue and several missing tests.
Steps to reproduce
Hello,
I've been trying to force my TextField to always use a floating label, by setting
InputDecoration
'sfloatingLabelBehavior
toFloatingLabelBehavior.always
.However, when the field is not focused, or is empty,
labelStyle
is used.By digging through the code, I found this line in
InputDecorator
.Looking at the definition of
_labelShouldWithdraw
explains why I get this behavior. I then tried to set the same style for bothlabelStyle
andfloatingLabelStyle
, but there is a very small animation when I focus/unfocus the text field.By using
FloatingLabelBehavior.always
, I expected the label to stick to its position no matter in which state theTextField
was.Have I missed something?
Expected results
The label always stays in place, only applying
floatingLabelStyle
.Actual results
The label alternates between
floatingLabelStyle
andlabelStyle
, even thoughFloatingLabelBehavior.always
is used.Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
Screen.Recording.2024-04-23.at.13.53.40.mov
Logs
Logs
[Paste your logs here]
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: