颤振文本字段labeltext未显示

时间:2020-05-16 12:49:20

标签: flutter dart

我无法显示文本字段labeltext。有人可以帮忙吗?以及如何在单击文本字段时使边框始终显示而不消失。

 @override
  Widget build(BuildContext context) {
    return TextFormField(
      controller: _controller,
      decoration: InputDecoration(
        border: new OutlineInputBorder(
          borderSide: new BorderSide(width: 1)
        ),
        // hintText: _hintText,
        labelText: "Label Text",
        contentPadding: EdgeInsets.only(left: 15),
        // suffixText: _nameLength.toString() + "/ " + _maxLength.toString(),
        // suffixStyle: TextStyle(fontSize: 12),
        // suffixStyle: TextStyle(color: Theme.of(context).textTheme.bodyText2.color),
        // counterText: "",
      ),
      maxLines: _maxLines,
      textCapitalization: TextCapitalization.sentences,
      cursorRadius: Radius.circular(10),
      keyboardType: TextInputType.text,
      autofocus: true,
      maxLength: _showTextCount ? _maxLength : null,
      style: TextStyle(color: AppSetting.textColor1),
      validator: (val) {
        // if (val.isEmpty) {
        //   return 'Please enter text.';
        // } 
        // return null;
      },
      onChanged: (val) {
        _onChanged(val);
        setState(() {
          _inputFieldText = val;
          _nameLength = _inputFieldText.length;
        });
      },
      onTap: () => AppSetting.hapticFeeback(),
    );
  }
}

enter image description here

2 个答案:

答案 0 :(得分:1)

只需确保输入装饰的 labelColor 的默认值与背景不同(在我的情况下,默认标签颜色为白色)。为了在点击时显示边框,请设置 focusedBorder 属性。

答案 1 :(得分:0)

您应该添加

                                      errorBorder: OutlineInputBorder(
                                        borderSide: BorderSide(
                                          color: Colors.redAccent,
                                          width: 2.0,
                                        ),
                                      ),
                                      focusedBorder: OutlineInputBorder(
                                        borderSide: BorderSide(
                                          color: primaryColor,
                                          width: 2.0,
                                        ),
                                      ),
                                      enabledBorder: OutlineInputBorder(
                                        borderSide: BorderSide(
                                          color: Colors.black54,
                                          width: 2.0,
                                        ),
                                      ),
                                    ),