flutter 里面的渐变色设置

实例

复制代码
// 样式
decoration: BoxDecoration(
  gradient: LinearGradient(
    begin: Alignment(0, -1),
    end: Alignment(0, -0.5),
    colors: [Color(0xFFBDCAF9), Color(0xFFF6F6F6)],
  ),
  // 圆角
  borderRadius: BorderRadius.only(
    topLeft: Radius.circular(34.r),
    topRight: Radius.circular(34.r),
  ),
),

位置坐标

Alignment x y 描述
topLeft -1 -1 左上角
topCenter 0 -1 顶部中间
topRight 1 -1 右上角
center 0 0 正中央
bottomCenter 0 1 底部中间

具体解释

想象一个矩形

复制代码
┌─────────────┐  y=-1
│             │
│             │
│             │  y=0
│             │
│             │
└─────────────┘  y=1
x=-1         x=0          x=1

topCenter 的位置

复制代码
┌─────────────┐
│      ●      │ ← topCenter (0, -1)
│             │
│             │
│             │
└─────────────┘

topCenter 代码:

复制代码
gradient: LinearGradient(
  begin: Alignment.topCenter,   // 起点在顶部中间
  end: Alignment.bottomCenter,  // 终点在底部中间
  colors: [Color(0xFFBDCAF9), Color(0xFFF6F6F6)],
),

再次理解:

Alignment x y 描述
Alignment.topLeft -1 -1 左上角
Alignment.topCenter 0 -1 顶部居中
Alignment.topRight 1 -1 右上角
Alignment.centerLeft -1 0 左中
Alignment.center 0 0 正中央
Alignment.centerRight 1 0 右中
Alignment.bottomLeft -1 1 左下角
Alignment.bottomCenter 0 1 底部居中
Alignment.bottomRight 1 1 右下角

结论

常用的位置属性的含义其实就是不同位置的含义。

相关推荐
u0111026756 小时前
WebP 转成 PNG 后为什么更大?图片格式转换不等于压缩
前端·javascript·vue.js
万少6 小时前
Qoder sonus模型 20分钟,复刻 马斯克 飞天汽车
前端·后端·算法
java1234_小锋7 小时前
【技术专题】HTML5 网页技术 - HTML5 列表标签
前端·html·html5
强二小哥帅7 小时前
Kotlin 协程复习笔记
前端
不可能片场7 小时前
工程实践 原子替换改了 ctime 怎么修
前端·electron
暧暧内含光7 小时前
HTTP 文件传输体系全解:从协议标头、OSS 架构到流媒体分片
前端
静默回滚7 小时前
浏览器能显示AVIF,却导不出一张AVIF
前端
小皮虾7 小时前
小程序全局状态还能这么简单?只需初始化一次,页面自动同步
前端·javascript·微信小程序
用户818618028007 小时前
RESTful API 设计规范与版本演进
前端
补码缩写7 小时前
前端AVIF编码开多线程快两三倍,speed调到8就不快了
前端