如何禁用 TextFormField 默认动画

Joã*_*dro 5 flutter

当用户关注文本字段时,我想禁用默认行为,其中标签文本变小并停靠在左上角:文本表单字段

我想禁用此行为并仅使标签文本消失,我该怎么做?

Fer*_*han 6

使用FloatingLabelBehavior.neverinsideInputDecoration将帮助您隐藏标签,而不是labelText您可以使用它hintText,这样当您键入内容时标签就会消失。

TextFormField(
    decoration: InputDecoration(
        hintText: "Search",
        floatingLabelBehavior: FloatingLabelBehavior.never,
        border: InputBorder.none,
        suffixIcon: Icon(
            Icons.search,
        ),
    ),
),
Run Code Online (Sandbox Code Playgroud)


Jah*_*lam 1

试试这个

TextFormField(
              cursorColor: Colors.black,
              keyboardType: TextInputType.text,
              decoration: new InputDecoration(
                  border: InputBorder.none,
                  focusedBorder: InputBorder.none,
                  enabledBorder: InputBorder.none,
                  errorBorder: InputBorder.none,
                  disabledBorder: InputBorder.none,
                  contentPadding:
                  EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15),
                  hintText: "Hints"),
            )
And customize textfield decoration as you desired.
Run Code Online (Sandbox Code Playgroud)