容器填充 EdgeInsets.fromLTRB 更改背景颜色

时间:2021-04-02 08:03:52

标签: flutter flutter-container flutter-padding

我想在容器内对齐文本。我为包含文本的容器使用了填充类。填充有效,但似乎 EdgeInsets.fromLTRB 将容器的文本和背景颜色全部偏移。为什么会发生?我可以使用 mainAxisAlignment,但我想了解为什么填充类会改变背景颜色。谢谢。

new Container(
  width: 311,
  height: 48,
  //padding: EdgeInsets.all(15),
  padding: EdgeInsets.fromLTRB(127.5, 0, 0, 0),
  decoration: new BoxDecoration(
      color: Color(0xfffb2cfef),
      borderRadius: BorderRadius.circular(16)),
  child: Row(
    //mainAxisAlignment: MainAxisAlignment.center,
    children: [
      new Text(
        "Create account",
        style: TextStyle(
          fontFamily: 'Montserrat',
          color: Colors.white,
          fontSize: 16,
          fontWeight: FontWeight.w500,
          fontStyle: FontStyle.normal,
        ),
      ),
    ],
  ),
),

iOS simulator screenshot

1 个答案:

答案 0 :(得分:0)

您在装饰中使用颜色

decoration: new BoxDecoration(
    color: Color(0xfffb2cfef),
    borderRadius: BorderRadius.circular(16)),

尝试删除它