flutter - 如何在 flutter 中使用 LinearGradient 和变换?

标签 flutter dart flutter-layout flutter-animation

how to use LinearGradient in flutter with transform?

decoration: BoxDecoration(
    gradient: LinearGradient(
    colors: [Colors.black, Colors.white],
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
    transform: ???,
  )
 ),

最佳答案

您可以使用GradientRotation类,它扩展了GradientTransform类。它以弧度为单位的角度作为参数,并沿顺时针方向旋转着色器

这是一个GradientRotation的示例:

Container(
        padding: const EdgeInsets.all(15),
        child: Text(title,
            style: TextStyle(
                fontFamily: 'RobotoCondensed',
                fontSize: 20,
                color: Colors.white)),
        width: 100,
        height: 100,
        decoration: BoxDecoration(
          gradient: LinearGradient(
            transform: GradientRotation(pi/2),
            colors: [
              color.withOpacity(0.5),
              color.withOpacity(0.55),
              color.withOpacity(0.65),
              color.withOpacity(0.75),
              color.withOpacity(0.85),
            ],
            begin: Alignment.centerRight,
            end: Alignment.bottomRight,
            stops: [0, 0.1, 0.2, 0.3, 0.4],
          ),
          borderRadius: BorderRadius.circular(15),
        ),

以下是GradientRoation应用的快照:

Without GradientRotation

With 90 degree rotation in clockwise direction

在第一张图片中,我没有使用GradientRotation;在第二张图片中,我传递了 90 度(pi/2 弧度)作为参数,因此它沿顺时针方向旋转了 90 度。

如果热重启失败,请尝试热重新加载您的应用程序以查看更改。

关于flutter - 如何在 flutter 中使用 LinearGradient 和变换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59986915/

相关文章:

Dart/flutter : iOS app crashes with Firebase ML Vision

firebase - 从Firebase存储获取图像

flutter - 如何在 Flutter 中的任何图标上显示弹出菜单?

android - 我在 flutter 中实现以下设计时遇到问题

flutter - 实现 CupertinoActionSheet 的正确方法是什么?

Flutter:type_ahead建议框高度?

firebase - Flutter/Firestore:类 'QuerySnapshot'没有实例getter 'document'

flutter - 在 Flutter 中将数据传递给有状态的小部件

google-maps - 如何在 flutter 中在谷歌地图上绘制多段线

flutter - 我需要在选项卡中添加一些东西 我应该在代码中的什么地方添加