代码之家  ›  专栏  ›  技术社区  ›  swastij

如何在颤振中创建垂直线性梯度?

  •  0
  • swastij  · 技术社区  · 2 年前

    我试图创建一个垂直的线性梯度,即从顶部中心到底部中心,如下所示 image .

    我想出了这段代码,它创建了从左上到右下的对角线渐变。如何获得垂直线性梯度?

     Container(
          height: 550,
          width: 550,
          decoration: BoxDecoration(
                        gradient: LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment(0.9, 0.1),
                          colors: [opFireOrange, fireOrange]
                         ),
                        borderRadius: BorderRadius.all(Radius.circular(6.0)),
             ),
        ),
    
    2 回复  |  直到 2 年前
        1
  •  1
  •   mechaadi    2 年前

    您应该将end:Agnment(0.9,0.1)更改为end:Agnment.bottomCenter,并将停止点列表添加到LinearGradient中,下面的代码应该在颤振中生成所需的垂直线性渐变:

    LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              stops: [0.9, 0.1],
              colors: [opFireOrange, fireOrange],
    ),
    
        2
  •  0
  •   novol    2 年前

    添加停止并设置正确 对齐 喜欢

    gradient: LinearGradient(
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      colors: [Colors.orange, Colors.deepOrange],
                    stops: [0.8, 1.0],
                  ),