首页 > 技术文章 > flutter AnimatedPositioned

qqcc1388 2019-10-23 18:42 原文

Positioned 的动画版。

只有是 Stack 的 child 时才能工作。

如果 child 的 size 在动画过程会改变,则 AnimatedPositioned 是很好的选择

    double indicatorWidth = (width * 2 / 3).ceilToDouble();
    double indicatorHeight = 2;
    double indicatorTopMargin = height - indicatorHeight*2;
    double left = (currentIndex * width + indicatorWidth / 4).ceilToDouble();
  Widget _indicator() {
      return AnimatedPositioned(
        left: left,
        child: Container(
          height: indicatorHeight,
          width: indicatorWidth,
          margin: EdgeInsets.only(top: indicatorTopMargin),
          color: kGridTextColor,
        ),
        duration: Duration(milliseconds: 200),
      );

推荐阅读