【问题标题】:How to give gradient to CircleAvatar in flutter?如何在颤动中为 CircleAvatar 赋予渐变?
【发布时间】:2021-04-01 20:27:31
【问题描述】:

如何在flutter中为CircleAvatar();小部件赋予渐变色?

【问题讨论】:

  • 而不是CircleAvatar.backgroundColor?不,没有办法
  • @pskink 一定有办法!!
  • 我认为 CircleAvatar 不可能。使用圆形容器模拟行为。
  • “必须有办法!!” - 怎么做?这是一个构造函数:api.flutter.dev/flutter/material/CircleAvatar/CircleAvatar.html - 没有任何“梯度”参数
  • 我能够通过将 Container 添加为子项并为容器的盒子装饰赋予渐变属性来实现该功能/

标签: flutter dart flutter-layout


【解决方案1】:
Container(
  decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  gradient: LinearGradient(
                  colors: [
                          color1,
                          color2,
                  ],
                  begin: Alignment.bottomLeft,
                  end: Alignment.topRight
                  )
              ),
              child: CircleAvatar(
                  child: Text(
                        'MS',
                        style: TextStyle(
                          color: Colors.white
                        )
                  ),
                  backgroundColor: Colors.transparent
              )
    )

【讨论】:

    【解决方案2】:

    我能够通过使用 Container 作为 CircleAvatar 的子级并将 gradient 属性赋予 Container 来实现我正在寻找的功能strong>容器。

     CircleAvatar(
            radius: 40,
            child: Container(
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                gradient: LinearGradient(
                  colors: [
                    color1,
                    color2,
                  ],
                ),
              ),
            ),
          ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-27
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      • 2021-07-24
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      相关资源
      最近更新 更多