-
Notifications
You must be signed in to change notification settings - Fork 26.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
hintStyle of InputDecorationTheme not correctly applied #21385
Comments
The InputDecorator's hintStyle appears to be initialized correctly from the InputDecorationTheme in this test case: https://gist.github.com/HansMuller/f41427548f2357931d48c9becbc51e9b If you can provide a test case that fails, I'll be happy to look into it. |
Hi Hans, The problem occurs when you use labelText (instead of hintText) of the InputDecoration. new TextField(
decoration: new InputDecoration(labelText: "Hello 1"),
) On focus the text moves upwards and should adopt the hintStyle, according to the documentation of the InputDecorationTheme's hintStyle (it says: Also used for the [labelText] when the [labelText] is displayed on top of the input field (i.e., at the same location on the screen where text may be entered in the input field).). Hope this helps. Regards, |
Aha! You are correct, the implementation does not match the documentation. And we're not currently testing the floating label's text style. Although it's easy enough to "fix" this issue, it may just be a documentation bug. On the face of it, there doesn't seem to be any reason for the label's style to change when it "floats". It does change color if errorText is (also) specified or if the input decorator is disabled. @willlarche - If a textfield's hint and label styles are different, should the label's style morph to the hint style when the textfield gets the focus and the label floats (moves upwards)? |
Just to make sure I understand the issue:
Question:
|
Right, if the text field is displaying a label, should the label's style morph from the specified label-style to the hint-style when it moves up (upon focus) or back down again upon losing focus. |
I think, Hans, that your documentation didn't mean floating but being inline (not floating).
In which case that means use the hint style when it's not floating and the label style when it is. Certainly you shouldn't use the hint style when floating, period. But we should support having 2 different styles for the label: one for floating and one for not-floating. The other platforms just do color and size since they can't animate font or weight changes. If Flutter can animate font or weight changes, it would be cool to allow that interpolation. Incidentally, this underline style of text field is deprecated. Consider adding a filled background like you find in the current guidelines. Our extensive UX research shows people are vastly more likely to properly interact with a text field that defines its touchable space than the legacy designs! |
So...
|
I believe this is still wrong (and that there was a misunderstanding the thread above). The documentation states: GIVEN
THEN
(The discussion above had it the other way around: labelStyle when raised, hintStyle when in the input box.) This makes sense to me, but currently is not what happens. Is there likely to be a fix? Many thanks. |
Issue still exist flutter doctor -v
|
Any updates on this? I'm still facing this issue flutter doctor -v[✓] Flutter (Channel stable, 1.22.4, on Linux, locale en_GB.UTF-8)
• Flutter version 1.22.4 at /opt/libs/flutter
• Framework revision 1aafb3a8b9 (8 days ago), 2020-11-13 09:59:28 -0800
• Engine revision 2c956a31c0
• Dart version 2.10.4
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /home/fernando/Android/Sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[!] Android Studio
• Android Studio at /opt/android-studio
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] Connected device (1 available)
• ASUS X00QD (mobile) • 192.168.1.39:5555 • android-arm64 • Android 9 (API 28)
! Doctor found issues in 1 category. |
For me the problem was the hint color was not being inherited from the |
code sampleimport 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
theme: ThemeData.dark().copyWith(
inputDecorationTheme: const InputDecorationTheme(
focusedBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.red)),
enabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.yellow)),
labelStyle: TextStyle(color: Colors.yellow),
hintStyle: TextStyle(color: Colors.red),
)),
home: Home(),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: Center(
child: TextField(
decoration: new InputDecoration(labelText: "Hello 1"),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
),
);
}
} flutter doctor -v[✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-x64, locale en-GB)
• Flutter version 1.22.6 at /Users/tahatesser/Code/flutter_stable
• Framework revision 9b2d32b605 (11 days ago), 2021-01-22 14:36:39 -0800
• Engine revision 2f0af37152
• Dart version 2.10.5
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Volumes/Extreme/SDK
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Volumes/Extreme/SDK
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
• Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.19.0
[✓] Connected device (2 available)
• RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 10 (API 29)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
! Doctor found issues in 1 category. [✓] Flutter (Channel master, 1.26.0-18.0.pre.128, on macOS 11.1 20C69 darwin-x64, locale en-GB)
• Flutter version 1.26.0-18.0.pre.128 at /Users/tahatesser/Code/flutter_master
• Framework revision 502ff3dbfe (59 minutes ago), 2021-02-02 05:41:03 -0500
• Engine revision 7334085fc1
• Dart version 2.12.0 (build 2.12.0-281.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Volumes/Extreme/SDK
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Volumes/Extreme/SDK
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• 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
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.19.0
[✓] Connected device (4 available)
• RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 10 (API 29)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• macOS (desktop) • macos • darwin-x64 • macOS 11.1 20C69 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.96
• No issues found! |
It's very obvious behavior in my opinion. labelText serves two purpose,
It should take hintStyle in first state (Hint in the same position where user will enter)and labelStyle in second state (Label vertically above input)Currently, Flutter is not behaving correctly for labelStyle and hintStyle. Please put below code in DartPad and check. Code Sample: [✓] Flutter (Channel stable, 2.0.4, on macOS 11.2.3 20D91 darwin-x64, locale en-AE) |
Document says:
But case doesn't fit when you set |
Yup, still a problem, there's no way to set different styles for the label, while it's inside the input or floating, using the theme constructor 😕 |
@fhuonder, @shinyford, @Sominemo, @ataberkw, @afzalali15, @freitzzz, @fernando-s97 - please take a look at #86389; we're hoping that will resolve this issue. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Hi all,
When having a custom theme with a custom InputDecorationTheme, like
my expectation, according to the documentation of the hintStyle property, is that the label text of a focused text field gets the color of the hint style. Unfortunately it stays the color of the labelStyle. When no custom InputDecorationTheme is in use it works.
With custom theme (expectation: in the focused case the text 'Place' should be red):
Without custom theme (where primary color is cyan and accent color is purple):
Is the configuration wrong or is it really a bug?
Regards,
Florian
The text was updated successfully, but these errors were encountered: