flutter中几种给Container设置背景色的方法

在Flutter中,可以使用以下几种方法为Container设置背景色:

  1. 使用color属性:Container(color: Colors.red)
  2. 使用decoration属性,并在其中使用BoxDecorationContainer(decoration: BoxDecoration(color: Colors.red))
  3. 使用Container.withBackground工厂方法:Container.withBackground(color: Colors.red)

实际上,第二种方法是第一种方法的扩展,允许您设置更多的装饰效果(如