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

结论

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

相关推荐
Moment25 分钟前
牛逼,NextJs 从 16.3 开始全面拥抱 Agent Native 🥰🥰🥰
前端·后端·面试
沸点小助手1 小时前
6月沸点活动获奖名单公示|本周互动话题上新🎊
前端·后端
Csvn1 小时前
React 19 `use()` 来了:以后数据加载可以不用 useEffect?
前端·react.js
没落英雄1 小时前
从零开始搭建一个 AI Agent —— LangChain + TypeScript 实战手记
前端·人工智能·架构
远航_1 小时前
git submodule
前端·后端·github
摸着石头过河的石头1 小时前
从 Webpack 到 RSBuild:前端构建工具的进化之路
前端
疯狂的魔鬼1 小时前
告别 boolean 地狱:一个文件上传组件的状态机实践
前端·设计
竹林8181 小时前
Solana DApp 开发踩坑实录:从零用 @solana/web3.js 实现链上数据查询与交易签名
前端·javascript
狂师1 小时前
测试工程师的AI 技能库:推荐5个让你效率翻倍的Skills
前端·后端·测试
李明卫杭州1 小时前
Vue3 watch 与 watchEffect 深度解析
前端