Skip to content

Commit

Permalink
change progress calculation at _initScroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Salman S committed Sep 18, 2020
1 parent 42aeb8f commit 4a85736
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/main.dart
Expand Up @@ -88,18 +88,30 @@ class _TokopediaState extends State<Tokopedia> with TickerProviderStateMixin {
double scrollOffsetBackground = 150;
double scrollOffsetInput = 150;
double scrollOffsetIcon = 120;

// delay animation to start animate only after scrolling
// as far as startAnimationAfterOffset value
// this is for a smoother effect
if(_scrollController.offset >= startAnimationAfterOffset)
{
double offset = _scrollController.offset - startAnimationAfterOffset;

_animationBackground.progress = (offset / scrollOffsetBackground);
_animationInput.progress = (offset / scrollOffsetInput);
_animationIcon.progress = (offset / scrollOffsetIcon);
}
double offset = _scrollController.offset - startAnimationAfterOffset;
double progressBackground = offset / scrollOffsetBackground;
double progressInput = offset / scrollOffsetInput;
double progressIcon = offset / scrollOffsetIcon;

// make sure progress animation always between 0.0 and 1.0
progressBackground = progressBackground <= 0.0 ? 0.0 : progressBackground;
progressBackground = progressBackground >= 1.0 ? 1.0 : progressBackground;

// make sure progress animation always between 0.0 and 1.0
progressInput = progressInput <= 0.0 ? 0.0 : progressInput;
progressInput = progressInput >= 1.0 ? 1.0 : progressInput;

// make sure progress animation always between 0.0 and 1.0
progressIcon = progressIcon <= 0.0 ? 0.0 : progressIcon;
progressIcon = progressIcon >= 1.0 ? 1.0 : progressIcon;

_animationBackground.progress = progressBackground;
_animationInput.progress = progressInput;
_animationIcon.progress = progressIcon;
});
}

Expand Down

0 comments on commit 4a85736

Please sign in to comment.