Skip to content

Text Field obscure text cannot be used with expands to true #89502

@bahricanyesil

Description

@bahricanyesil

Putting an assert to check whether the text is a single line if it is obscured is a good idea when we think first. However, when we do like that we also avoid the use of "expands" property. For example, if I create a login screen with a password text form field wrapped with an expanded widget, I cannot fill the full size inside of the expanded with a text form field. The reason why I can't do it is the fact that obscured texts cannot be multiline and max lines should be null (cannot be 1) when expands is true. These two asserts lead to the problem and this problem leads to significant design issues especially when we are dealing with websites developed with Flutter Web since their size can be any.

Like it is mentioned in:

"the problem is that if i try to use a text field (obscure) that occupies the entire space of a container using Expands: true and max Lines: null, it will not work, only the text without obscure now.. :/"
Originally posted by @FilipeAG in #41853 (comment)

Use this code piece in any project to reproduce the issue:

Expanded(
        child: TextFormField(
        controller: controller, // Declare above
        obscureText: true,
      ),
      );

When you use the above code, TextFormField doesn't fill the all space of its parent since the obscured text form fields are forced to be "one" line. If we want to use the "expands" parameter of TextFormField as true, it doesn't pass the following assert:

 assert(
         !expands || (maxLines == null && minLines == null),
         'minLines and maxLines must be null when expands is true.',
       ),

If we try to set minLines and maxLines as null, then it doesn't pass the following assert:
assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'),

So each assert leads to failure in another assert like the links of a chain.
In short: "How can we create an obscured TextFormField that expands the parent widget?"

flutter doctor -v

[√] Flutter (Channel stable, 2.5.1, on Microsoft Windows [Version 10.0.19042.1237], locale tr-TR)
    • Flutter version 2.5.1 at D:\Programs\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffb2ecea52 (10 days ago), 2021-09-17 15:26:33 -0400
    • Engine revision b3af521a05
    • Dart version 2.14.2

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at D:\Programs\Android
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = D:\Programs\Android
    • Java binary at: D:\Programs\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.2)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31624.102
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop
      development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK

[√] Android Studio (version 4.0)
    • Android Studio at D:\Programs\Android Studio
    • Flutter plugin version 50.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code
    • VS Code at C:\Users\Bahrican\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.24.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsfound in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions