颤振线性渐变不显示

Flutter Linear Gradient Not Displaying

我正在尝试向容器添加线性渐变,如下所示:

Container(
      color: Colors.white,
      width: double.infinity,
      height: double.infinity,
      decoration: BoxDecoration(
          gradient: LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        stops: [0.1, 0.5, 0.9],
        colors: [
          Color(0xFFffe9bf),
          Color(0xFFffd280),
          Color(0xFFffb020),
        ],
      ))),

热重启并重新安装应用程序后,它不会显示。我错过了什么吗?任何帮助,将不胜感激。

"Cannot provide both a color and a decoration\nThe color argument is just a shorthand for \"decoration: new BoxDecoration(color: color)\"."

因此从容器

中移除颜色属性开始移除
Container(
  color: Colors.white,
  width: double.infinity,..

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ The following assertion was thrown during performLayout(): BoxConstraints forces an infinite height. The offending constraints were: BoxConstraints(w=661.0, h=Infinity)

您可能希望给您的容器宽度和高度已知值,要么是常量,要么是使用 MediaQuery,如图所示

Container(

  width: 100,
  height: 50,
  decoration: BoxDecoration(
      gradient: LinearGradient(
    begin: Alignment.topLeft,
    end: Alignment.bottomRight,
    stops: [0.1, 0.5, 0.9],
    colors: [
      Color(0xFFffe9bf),
      Color(0xFFffd280),
      Color(0xFFffb020),
    ],
  ))),

结果