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

结论

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

相关推荐
青莲84313 小时前
Android 事件分发机制 - 事件流向详解
android·前端·面试
musashi13 小时前
用 Electron 写了一个 macOS 版本的 wallpaper(附源码、下载地址)
前端·vue.js·electron
满天星辰14 小时前
Typescript之类型总结大全
前端·typescript
JFChen14 小时前
Web 仔用 Node 像 Java 一样写后端服务
前端
XiaoSong14 小时前
React useState 原理和异步更新
前端·react.js
徐徐子14 小时前
从vue3 watch开始理解Vue的响应式原理
前端·vue.js
眯眼因为很困啦14 小时前
GitHub Fork 协作完整流程
前端·git·前端工程化
whisper14 小时前
🚀 React Router 7 + Vercel 部署全指南
前端
还债大湿兄14 小时前
huggingface.co 下载有些要给权限的模型 小记录
开发语言·前端·javascript
叶落无痕5214 小时前
Electron应用自动化测试实例
前端·javascript·功能测试·测试工具·electron·单元测试