如何使Textfield Hinttext垂直中心?

发布于 2025-01-17 17:41:30 字数 1174 浏览 3 评论 0原文

我尝试了很多方法。

  • textAlign:TextAlign.Center

  • contentPadding: const EdgeInsets.all(20.0)

但它们没有用。

在此处输入图片说明

Expanded(
          child: Container(
            height: 30.0,
            decoration: BoxDecoration(
              color: Colors.grey[100],
              borderRadius: BorderRadius.circular(18),
            ),
            margin: const EdgeInsets.symmetric(vertical: 0, horizontal: 10.0),
            child: const TextField(
              style: TextStyle(fontSize: 14.0),
              decoration: InputDecoration(
                border: InputBorder.none,
                hintText: '请输入搜索词',
                hintStyle: TextStyle(fontSize: 13.0),
                prefixIcon: Icon(
                  Icons.search,
                  size: 18.0,
                  color: Colors.grey,
                ),
                suffixIcon: Icon(
                  Icons.clear,
                  size: 18.0,
                  color: Colors.grey,
                ),
              ),
            ),
          ),
        ),

i tried many methods.

  • textAlign: TextAlign.Center

  • contentPadding: const EdgeInsets.all(20.0)

but they are useless.

enter image description here

Expanded(
          child: Container(
            height: 30.0,
            decoration: BoxDecoration(
              color: Colors.grey[100],
              borderRadius: BorderRadius.circular(18),
            ),
            margin: const EdgeInsets.symmetric(vertical: 0, horizontal: 10.0),
            child: const TextField(
              style: TextStyle(fontSize: 14.0),
              decoration: InputDecoration(
                border: InputBorder.none,
                hintText: '请输入搜索词',
                hintStyle: TextStyle(fontSize: 13.0),
                prefixIcon: Icon(
                  Icons.search,
                  size: 18.0,
                  color: Colors.grey,
                ),
                suffixIcon: Icon(
                  Icons.clear,
                  size: 18.0,
                  color: Colors.grey,
                ),
              ),
            ),
          ),
        ),

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

套路撩心 2025-01-24 17:41:30

尝试以下代码,使用textAlign:textalign.center,

TextField(
  textAlign: TextAlign.center,
  style: TextStyle(fontSize: 14.0),
  decoration: InputDecoration(
    border: InputBorder.none,
    hintText: '请输入搜索词',
    hintStyle: TextStyle(fontSize: 13.0),
    prefixIcon: Icon(
      Icons.search,
      size: 18.0,
      color: Colors.grey,
    ),
    suffixIcon: Icon(
      Icons.clear,
      size: 18.0,
      color: Colors.grey,
    ),
  ),
),

结果屏幕 - >

Try below code, use textAlign: TextAlign.center,

TextField(
  textAlign: TextAlign.center,
  style: TextStyle(fontSize: 14.0),
  decoration: InputDecoration(
    border: InputBorder.none,
    hintText: '请输入搜索词',
    hintStyle: TextStyle(fontSize: 13.0),
    prefixIcon: Icon(
      Icons.search,
      size: 18.0,
      color: Colors.grey,
    ),
    suffixIcon: Icon(
      Icons.clear,
      size: 18.0,
      color: Colors.grey,
    ),
  ),
),

Result screen-> image

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文