【问题标题】:How to move up the lable text without moving the hint text in TextFormField (flutter)如何在不移动 TextFormField 中的提示文本的情况下向上移动标签文本(颤振)
【发布时间】:2021-03-21 09:23:42
【问题描述】:

我有以下小部件树:SizedBox( child: Container ( child: TextFormField(),),),

我希望 labelText 与容器的顶部边缘内联。 contentPadding: EdgeInsets.fromLTRB(x, x, x, x),EdgeInsets.only(x, x, x, x), 根本没有帮助。

contentPadding:EdgeInsets.only(left: 10.0, right: 20.0, ),//paddingin InputDecoration

padding: EdgeInsets.only(left: 10.0, right: 20.0,),//padding Container

我有容器 1,这是初始视图。

使用上面的 EdgeInsets 我得到容器 2。我该怎么做才能实现 Container 3

编辑

return SizedBox(
      height: 105,
      child: Container(
        decoration: decorationBox.copyWith(
          borderRadius: BorderRadius.all(Radius.circular(15.0)),
        ),
        margin: EdgeInsets.all(15.0),
        padding: EdgeInsets.only(left: 10.0, right: 20.0,),
        width: 350.0,
        child: Center(
          child: TextFormField(
            cursorColor: color,
            validator: validate,
            obscureText: obscure,
            keyboardType: keyboard,
            onSaved: onSaved,
            
            decoration: decorationText.copyWith(
              hintText: hintText,
              labelText: labelText,
             
              prefixIcon: Icon(
                icon,
                color: color,
                size: 40.0,
              ),
            ),
          ),
        ),
      ),
    );```

【问题讨论】:

    标签: flutter flutter-layout textformfield


    【解决方案1】:

    您是否尝试过使用其他小部件代替 SizedBox(如 UnconstrainedBox),您能否显示容器的完整代码以更好地理解问题。

    所以我发现,SizedBox 只是创建一个具有给定宽度/高度的盒子,并且不允许孩子超出给定尺寸。

    因此您可以使用受限框代替 SizedBox 并将边距/填充设置为文本容器,以便它可以超出框。

    我希望它对你有用。

    【讨论】:

    • 谢谢。我尝试使用 LimitedBox,它给了我 3 号容器,但它都很拥挤,而且我没有任何底部填充物。我也尝试过 UnconstrainedBox,它的效果与 SizedBox 相同。
    猜你喜欢
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 1970-01-01
    相关资源
    最近更新 更多