在 TextField 小部件中从下方剪切文本:Flutter

Ank*_*dik 3 flutter flutter-layout

TextField 小部件在文本较少的情况下工作正常,但是当我添加长文本时,它开始从底部剪切。

没有文字。

在此处输入图片说明

文字较少

在此处输入图片说明

问题从长文本开始

在此处输入图片说明

我的小部件代码。

Opacity(
      opacity: 0.5600000023841858,
      child: Container(
        padding: EdgeInsets.only(left: 10),
        width: 213,
        height: 36,
        decoration: BoxDecoration(
          color: boxShadowCreamColor,
          borderRadius: BorderRadius.circular(48),
          boxShadow: [BoxShadow(color: boxShadowColor, offset: Offset(0, 0), blurRadius: 8, spreadRadius: 0)],
        ),
        child: TextField(
          keyboardType: TextInputType.text,
          textAlign: TextAlign.left,
          maxLines: 1,
          textAlignVertical: TextAlignVertical.center,
          style: TextStyle(color: Colors.white,fontSize: fontMedium,fontWeight: fontWeightRegular),
          decoration: InputDecoration(
            hintText: "Search",
            border: InputBorder.none,
            hintStyle: TextStyle(color: Colors.white,fontSize: fontMedium,fontWeight: fontWeightRegular),
            suffixIcon: Icon(
              Icons.search,
              color: Colors.white,
            ),
          ),
        ),
      ),
    );
Run Code Online (Sandbox Code Playgroud)

Dar*_*han 10

使用isDense里面的属性decoration并将其设置为true,这应该可以解决您的问题。

isDense 属性有助于减少垂直空间。

decoration: InputDecoration(
            isDense: true,
            hintText: "Search",
            border: InputBorder.none,
            hintStyle: TextStyle(color: Colors.white),
            suffixIcon: Icon(
              Icons.search,
              color: Colors.white,
            ),
          ),
Run Code Online (Sandbox Code Playgroud)