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

结论

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

相关推荐
0思必得06 小时前
[Web自动化] Selenium处理动态网页
前端·爬虫·python·selenium·自动化
向哆哆7 小时前
打造高校四六级报名管理系统:基于 Flutter × OpenHarmony 的跨端开发实践
flutter·开源·鸿蒙·openharmony·开源鸿蒙
2501_940007897 小时前
Flutter for OpenHarmony三国杀攻略App实战 - 设置功能实现
flutter
东东5167 小时前
智能社区管理系统的设计与实现ssm+vue
前端·javascript·vue.js·毕业设计·毕设
catino7 小时前
图片、文件的预览
前端·javascript
lbb 小魔仙8 小时前
【Harmonyos】开源鸿蒙跨平台训练营DAY9:获取分类数据并渲染
flutter·华为·harmonyos
mocoding8 小时前
Flutter 3D 翻转动画flip_card三方库在鸿蒙版天气预报卡片中的实战教程
flutter·3d·harmonyos
layman05289 小时前
webpack5 css-loader:从基础到原理
前端·css·webpack
半桔9 小时前
【前端小站】CSS 样式美学:从基础语法到界面精筑的实战宝典
前端·css·html
AI老李9 小时前
PostCSS完全指南:功能/配置/插件/SourceMap/AST/插件开发/自定义语法
前端·javascript·postcss