最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - Difficulty creating a linear progress animation with an Instagram story-like bounce effect - Stack Overflow

programmeradmin6浏览0评论

I am trying to achieve story progress animations like in this GIF demo of Instagram.

Instagram loader animation

I am using flutter story display library

Here is the code I am trying when the user clicks on skip or next story.

Next story button click

AnimationController? _progressController;
late Animation<double> _animation;

 _progressController = AnimationController(
  duration: Duration.zero,
  vsync: this,
);
_setAnimation();

void _nextStory() {
List<StoryCard> cards = widget.children[_storyIndex].children;
if (_cardIndex >= cards.length) return;
_progressController?.reset();
cards[_cardIndex].onDispose?.call(_cardIndex);
if (_cardIndex < cards.length - 1) {
  _setStoryCardVisited(_storyIndex, _cardIndex, true);
  _playStory(isCallVisit: true);
  _isTapped = false;
  cards[_cardIndex].onNext?.call(_cardIndex);
  _setAnimation();
  // _progressController?.forward();
} else {
  _pageController
      ?.nextPage(
          duration: const Duration(milliseconds: 250),
          curve: Curves.easeOut)
      .then((_) => cards[_cardIndex].onNext?.call(_cardIndex));
}

void _setAnimation() {
_animation = Tween<double>(begin: 0.0, end: 1.0).animate(
  CurvedAnimation(
    parent: _progressController!,
    curve: Curves.easeOutBack, // Bounce forward effect
  ),
)..addStatusListener((status) {
    if (status == AnimationStatuspleted) {
      _nextStory();
    }
  });

}

Animated Container

AnimatedBuilder(
              animation: widget.animation,
              builder: (context, child) {
                return Stack(
                  children: [
                    LinearProgressIndicator(
                      value: widget.animation.value,
                      backgroundColor: Colors.grey,
                      // color: Colors.white,
                      valueColor:
                          AlwaysStoppedAnimation<Color>(Colors.white),
                    ),
               
                  ],
                );
              },
            )

Thanks in advance.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论