Flutter 中 Stack 的使用详解(内含对比图) _ Flutter Widgets,flutter下拉刷新组件

如果你看看源码可以看到这个参数的默认值是 AlignmentDirectional.topStart ,但是这里我们依然可以使用我们熟悉的 Alignment.topLeft 来进行参数设置,这是为什么呢?我们看看来看看 AlignmentDirectional 源码吧,Alignment 源码在前面的章节我们看过了

Stack(
// 居中对齐
alignment: Alignment.topLeft,
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] arguments 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值