Flutter 无法在颤振中为容器设置背景色

Flutter 无法在颤振中为容器设置背景色,flutter,flutter-layout,flutter-widget,Flutter,Flutter Layout,Flutter Widget,我正在使用下面的代码将容器的背景色设置为黑色,但它没有显示 Align( alignment: Alignment.bottomCenter, child: Container( color: Colors.black, margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),

我正在使用下面的代码将容器的背景色设置为黑色,但它没有显示

       Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              color: Colors.black,
              margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
              height: 40,
              width: double.infinity,
              child: RaisedButton(
                textColor: Colors.white,
                color: Colors.blue[300],
                onPressed: () => null,
                child: Text('Next'),
              ),
             ),
          )
输出:


有人能帮我吗?

使用
padding
属性而不是
margin
我认为问题在于raised按钮获得容器的大小,这就是为什么您没有看到任何黑色。正如建议的那样,您可以使用填充物,这样RaisedButton就不会得到容器的大小,您将看到黑色

这是以下代码的结果:

Align(
        alignment: Alignment.bottomCenter,
        child: Container(
          color: Colors.black,
          margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
          padding : EdgeInsets.only(left: 10, right: 10, bottom: 10, top: 10),
          height: 40,
          width: double.infinity,
          child: RaisedButton(
            textColor: Colors.white,
            color:Colors.blue[300],
            onPressed: () => null,
            child: Text('Next'),
          ),
         ),
      ),

您可以更改这些值以获得所需的结果。简单的解决方案是:将其包装在容器中并赋予其颜色属性

Container(
            color: Colors.black,
            child: Align(
              alignment: Alignment.bottomCenter,
              child: Container(
                margin: EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10),
                height: 40,
                width: double.infinity,
                child: RaisedButton(
                  textColor: Colors.white,
                  color: Colors.blue[300],
                  onPressed: () => null,
                  child: Text('Next'),
                ),
              ),
            ),
          )