【问题标题】:Input text being cutoff with overflow输入文本被溢出截断
【发布时间】:2020-07-06 14:52:19
【问题描述】:

您好,我是 Flutter 新手,所以这可能是一个小问题,但我有一个搜索框,其中包含一个 TextField 和一个图标。

当输入文本小于输入框的宽度时它可以正常工作,但一旦超过它似乎会被切成两半,只能看到它的上半部分。

据我了解,Flutter 应该会自动处理溢出。这是通用输入小部件的构建方法,这是我与“行中的图标”一起使用的方法。它在Row 中使用,但我不认为这是问题所在。

这是文本溢出时的样子。

return Expanded(
  child: TextField(
    autofocus: autofocus,
    style: Theme.of(context).textTheme.bodyText2,
    cursorColor: Theme.of(context).cursorColor,
    maxLines: 1,
    controller: controller,
    decoration: InputDecoration(
      border: InputBorder.none,
      hintText: placeholder,
      hintStyle: TextStyle(color: Theme.of(context).hintColor),
    ),
    onChanged: (String value) {
      onChange(value);
    },
    onSubmitted: (String value) {
      onChange(value);
    },
  ),
);

这是GitHub repo,以防您想查看上下文用法。它用于lib/routes/MainPage.dartlib/routes/SearchPage.dart

【问题讨论】:

  • 我无法从您的代码中重现该问题。请提供我们可以重现的代码
  • 问题中有一个指向github repo的链接,你可以在那里看到完整的源代码,但基本上给定的小部件与一个图标一起放在一个行中,它位于一个容器中是 AppBar 动作的一部分。

标签: flutter flutter-layout


【解决方案1】:

事实证明,由于InputDecoration 上的contentPadding,它被切断了。对于那些面临同样问题的人,请将decoration 属性更改为:

InputDecoration(
  contentPadding: EdgeInsets.zero, // Removes padding
  isDense: true,                   // Centers the text
  border: InputBorder.none,
  hintText: placeholder,
  hintStyle: TextStyle(color: Theme.of(context).hintColor),
)

【讨论】:

    猜你喜欢
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多