Flutter 中 Stack 的使用详解(内含对比图) _ Flutter Widgets

本文详细介绍了 Flutter 中 Stack 组件的使用,包括 Alignment 和 AlignmentDirectional 的源码分析,展示了 Stack 的各种对齐方式效果,并探讨了 fit 填充方式的差异,如 StackFit.loose、StackFit.expand 和 StackFit.passthrough。同时,文章还提及了 clipBehavior 的剪裁行为。适合 Flutter 移动开发者深入理解 Stack 组件。
摘要由CSDN通过智能技术生成

children: [
getItem(3, width: 120, height: 120, color: Colors.purple),
getItem(2, width: 80, height: 80, color: Colors.blue),
getItem(1),
],
)

Alignment 和 AlignmentDirectional 源码

// Alignment
class Alignment extends AlignmentGeometry {
/// Creates an alignment.
///
/// The [x] and [y] argu

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

ments must not be null.
const Alignment(this.x, this.y)
: assert(x != null),
assert(y != null);
static const Alignment topLeft = Alignment(-1.0, -1.0);
static const Alignment center = Alignment(0.0, 0.0);

}

// AlignmentDirectional
class AlignmentDirectional extends AlignmentGeometry {
const AlignmentDirectional(this.start, this.y)
: assert(start != null),
assert(y != null);
static const AlignmentDirectional topStart = AlignmentDirectional(-1.0, -1.0);
// 考虑使用 Alignment.center 代替
static const AlignmentDirectional center = AlignmentDirectional(0.0, 0.0);

}

上面我们贴出了核心源码,可以看出他俩都是继承自 AlignmentGeometry ,然后实现也是差不多,而且源码中的注释也是推荐我们使用 Alignment 代替

各种对齐方式效果

这里我们就使用 Alignment 了

Alignment.topLeft Alignment.topCenter Alignment.topRight
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值