0

我有以下小部件树: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

我有 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,
              ),
            ),
          ),
        ),
      ),
    );```
4

1 回答 1

0

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

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

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

我希望这个对你有用。

于 2021-03-21T10:16:49.610 回答