【问题标题】:Flutter Complex Linear Gradient Not Working颤振复杂的线性梯度不起作用
【发布时间】:2021-07-08 14:51:09
【问题描述】:

以上是预期的输出。

我需要在 Flutter 中实现这个渐变,但它并没有被排除在外。

颜色:#6646E7

如图所示,颜色偏移非常严格且不平滑。 下面是我想使用的容器

完整代码:

Stack(
      alignment: Alignment.bottomRight,
      children: [
        Container(
          margin: const EdgeInsets.only(left: 10, right: 10, top: 15),
          padding: const EdgeInsets.all(20),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(15),
              color: Colors.white,
              border: Border.all(color: Colors.white, width: 2),
              // gradient: LinearGradient(
              //     begin: Alignment.topLeft,
              //     end: Alignment.bottomRight,
              //     stops: const [
              //       0.01,
              //       0.1,
              //       0.9
              //     ],
              //     colors: [
              //       const Color(0xff6646E7).withOpacity(0.4),
              //       Colors.white,
              //       const Color(0xff6646E7).withOpacity(0.4),
              //     ]),
              // boxShadow: [
              //   const BoxShadow(
              //       color: Color.fromRGBO(0, 0, 0, 0.25),
              //       blurRadius: 3,
              //       spreadRadius: 1,
              //       offset: Offset(0, 4))
              // ]),
              ),
          child: Column(
            children: [
              Row(
                children: [
                  SvgPicture.asset('assets/profile/$icon.svg'),
                  const SizedBox(
                    width: 10,
                  ),
                  Text(
                    title,
                    style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.w600,
                        fontFamily: GoogleFonts.poppins().fontFamily),
                  )
                ],
              ),
              const SizedBox(
                height: 20,
              ),
              child
            ],
          ),
        ),
        Positioned(
          right: 10,
          child: GestureDetector(
              onTap: onEditPressed,
              child: SvgPicture.asset('assets/profile/edit_pen.svg')),
        )
      ],
    );

感谢您的帮助

【问题讨论】:

    标签: flutter user-interface flutter-layout


    【解决方案1】:

    试试这个,

    decoration: BoxDecoration(
      gradient: LinearGradient(
        colors: [
          Colors.black38,
          Colors.black12,
          Colors.black12,
          Colors.black38,
        ],
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
      ),
    ),
    

    用您想要的颜色更改 Colors.black38Colors.black12

    【讨论】:

    • 感谢您的回答,但是色偏又很严格了
    • 根据您的要求,使用十六进制代码提供特定颜色,而不是预定义颜色。
    • 我尝试使用我的十六进制代码 #6646E7 但它仍然不接近参考
    • 你能分享你保存十六进制颜色代码的完整代码吗?
    • 我刚刚检查了你的代码,其中没有让你的容器全屏显示的高度和宽度参数,在我的代码 sn-p 中我指定了height: 200, width: 400 用于测试目的。尝试使用 sn-p 添加这些约束。您将获得此 UI 视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    • 2016-10-31
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    相关资源
    最近更新 更多