You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TextFormField does not follow Min / Max Line rules as indicated. #80133
My fix is not ideal as I just realized text input formatters don't take into account the existing state of a TextField if we have a textfield that can be saved and edited again. Text input formatter's will only apply rules on the new text and ignore what existing text is present.
The intention of minLines/maxLines is to set the size of the field, not the content, so I think this is working as intended. I admit I haven't thought much about how to limit the number of lines of content though. I think I would do it with an input formatter like you are doing. I think you'll have to manually apply your formatter to any text that is programmatically loaded into the TextField.
Maybe we can update the docs for minLines/maxLines to make this more clear? Is there anything else we should do to make this more straightforward?
Honestly the text input formatter feels pretty hacky I guess a documentation update would help to make it straight forward but ideally if we could bake the logic into the text field itself it would be a much better experience
I'm going to close this as fixed by #85138, but if anyone else is struggling with limiting the number of lines the user can enter, please give a 👍 to this issue or comment. Maybe we can get this line limiting input formatter added to the framework if enough people think it would be useful.
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 flutter doctor -v and a minimal reproduction of the issue.
Activity
zaidkazi commentedon Apr 9, 2021
I have a hack that creates a input formatter with regex replacement... there has to be a better way tho
TahaTesser commentedon Apr 12, 2021
Hi @zaidkazi
Thanks for filing the issue, it does keep scrolling and doesn't stop with following code, while your workaround seems to be fix the issue
Here I created a complete runnable code sample to demonstrate the issue with and without
MaxLineInputFormattercode sample
Preview
Screen.Recording.2021-04-12.at.11.35.40.AM.mov
flutter doctor -v
[✓] Flutter (Channel stable, 2.0.4, on macOS 11.2.3 20D91 darwin-x64, locale en-GB) • Flutter version 2.0.4 at /Users/tahatesser/Code/flutter_stable • Framework revision b1395592de (10 days ago), 2021-04-01 14:25:01 -0700 • Engine revision 2dce47073a • Dart version 2.12.2 [✓] 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.55.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 11.2.3 20D91 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.114 • No issues found![✓] Flutter (Channel master, 2.1.0-13.0.pre.574, on macOS 11.2.3 20D91 darwin-x64, locale en-GB) • Flutter version 2.1.0-13.0.pre.574 at /Users/tahatesser/Code/flutter_master • Framework revision 02efffc134 (2 days ago), 2021-04-10 03:49:01 -0400 • Engine revision 8863afff16 • Dart version 2.13.0 (build 2.13.0-222.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.55.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 11.2.3 20D91 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.114 • No issues found!zaidkazi commentedon Apr 19, 2021
My fix is not ideal as I just realized text input formatters don't take into account the existing state of a TextField if we have a textfield that can be saved and edited again. Text input formatter's will only apply rules on the new text and ignore what existing text is present.
Hence I think this issue is pretty important.
justinmc commentedon Jun 23, 2021
The intention of minLines/maxLines is to set the size of the field, not the content, so I think this is working as intended. I admit I haven't thought much about how to limit the number of lines of content though. I think I would do it with an input formatter like you are doing. I think you'll have to manually apply your formatter to any text that is programmatically loaded into the TextField.
Maybe we can update the docs for minLines/maxLines to make this more clear? Is there anything else we should do to make this more straightforward?
zaidkazi commentedon Jun 24, 2021
Honestly the text input formatter feels pretty hacky I guess a documentation update would help to make it straight forward but ideally if we could bake the logic into the text field itself it would be a much better experience
justinmc commentedon Jun 24, 2021
I'm going to close this as fixed by #85138, but if anyone else is struggling with limiting the number of lines the user can enter, please give a 👍 to this issue or comment. Maybe we can get this line limiting input formatter added to the framework if enough people think it would be useful.
github-actions commentedon Jul 31, 2021
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
flutter doctor -vand a minimal reproduction of the issue.