简体   繁体   English

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

[英]Text cutting from below in TextField widget: Flutter

TextField widget works fine with less text but when i adding long text it starts to cut from bottom. TextField 小部件在文本较少的情况下工作正常,但是当我添加长文本时,它开始从底部剪切。

Without text.没有文字。

在此处输入图像描述

With less text用更少的文字

在此处输入图像描述

Problem starts here with long text问题从长文本开始

在此处输入图像描述

My widget code.我的小部件代码。

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,
            ),
          ),
        ),
      ),
    );

Use isDense property inside decoration and set it to true , which should resolve your issue.decoration中使用isDense属性并将其设置为true ,这应该可以解决您的问题。

isDense property helps to take less vertical space. isDense属性有助于减少垂直空间。

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

It happens just because of your height which you have given your Container.它的发生只是因为你给了你的 Container 的高度。 Just increase that it will be fine for you.只是增加它对你来说会很好。

try height: 42, // -- its because textfield shrink the size of Textfield when its growing. try height: 42, // -- 因为 textfield 在其增长时会缩小 Textfield 的大小。

OR或者

Add isDense: true // inside InputDecoration添加isDense: true // inside InputDecoration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM