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 右下角

结论

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

相关推荐
小a杰.12 小时前
Flutter 与 AI 深度集成指南:从基础实现到高级应用
人工智能·flutter
程序员爱钓鱼13 小时前
Node.js 编程实战:文件读写操作
前端·后端·node.js
PineappleCoder13 小时前
工程化必备!SVG 雪碧图的最佳实践:ID 引用 + 缓存友好,无需手动算坐标
前端·性能优化
JIngJaneIL13 小时前
基于springboot + vue古城景区管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
敲敲了个代码13 小时前
隐式类型转换:哈基米 == 猫 ? true :false
开发语言·前端·javascript·学习·面试·web
澄江静如练_14 小时前
列表渲染(v-for)
前端·javascript·vue.js
JustHappy14 小时前
「chrome extensions🛠️」我写了一个超级简单的浏览器插件Vue开发模板
前端·javascript·github
Loo国昌14 小时前
Vue 3 前端工程化:架构、核心原理与生产实践
前端·vue.js·架构
sg_knight14 小时前
拥抱未来:ECMAScript Modules (ESM) 深度解析
开发语言·前端·javascript·vue·ecmascript·web·esm