Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppendIndicator done_before record #11

Closed
Aoi-hosizora opened this issue Feb 6, 2021 · 0 comments
Closed

AppendIndicator done_before record #11

Aoi-hosizora opened this issue Feb 6, 2021 · 0 comments

Comments

@Aoi-hosizora
Copy link
Owner

Aoi-hosizora commented Feb 6, 2021

enum _AppendIndicatorMode {
  drag, // start to show
  armed, // drag far enough
  append, // run the append callback
  done_before, // before append callback is done
  done, // append callback is done
  canceled, // canceled by no arming
}
  static const _kScaleSlowDuration = Duration(milliseconds: 400);
  static const _kScaleFastDuration = Duration(milliseconds: 100);
  static const _kProgressFadeDuration = Duration(milliseconds: 100);
  static const _kProgressIncrDuration = Duration(milliseconds: 150);
  static const _kProgressFinalDuration = Duration(milliseconds: 150);
  AnimationController _progressController;
  Animation<double> _progressAnimation;

  void initState() {
    super.initState();
    _sizeController = AnimationController(vsync: this);
    _sizeFactor = _sizeController.drive(Tween(begin: 0.0, end: 1.0));
    _progressController = AnimationController(vsync: this);
    _progressAnimation = _progressController.drive(Tween(begin: 0.0, end: 1.0));
  }

  void _start() {
    _sizeController.value = 0.0;
    _progressController.value = 0.0;
    _dragOffset = 0;
  }
  /// Show animation with "-> fade -> increasing -> shrink" or "-> shrink".
  void _dismiss(_AppendIndicatorMode newMode) async {
    if (newMode == _AppendIndicatorMode.canceled) {
      // -> cancel
      _mode = _AppendIndicatorMode.canceled;
      if (mounted) setState(() {});
    } else if (newMode == _AppendIndicatorMode.done) {
      // -> done_before
      _mode = _AppendIndicatorMode.done_before;
      if (mounted) setState(() {});
      await Future.delayed(_kProgressFadeDuration); // fade
      await _progressController.animateTo(1.0, duration: _kProgressIncrDuration); // increasing
      await Future.delayed(_kProgressFinalDuration);
      // -> done
      _mode = _AppendIndicatorMode.done;
      if (mounted) setState(() {});
    }
    await _sizeController.animateTo(0.0, duration: _kScaleSlowDuration, curve: Curves.easeOutCubic); // shrink

    // -> null
    _mode = null;
    if (mounted) setState(() {});
  }
SizeTransition(
  sizeFactor: _sizeFactor,
  axis: Axis.horizontal,
  child: AnimatedCrossFade(
    duration: _kProgressFadeDuration,
    crossFadeState: _mode == _AppendIndicatorMode.done_before || _mode == _AppendIndicatorMode.done ? CrossFadeState.showSecond : CrossFadeState.showFirst,
    firstChild: LinearProgressIndicator(
      value: _mode == _AppendIndicatorMode.append || _mode == _AppendIndicatorMode.done_before || _mode == _AppendIndicatorMode.done ? null : 0,
      minHeight: widget.minHeight,
      backgroundColor: widget.backgroundColor,
      valueColor: widget.valueColor,
    ),
    secondChild: AnimatedBuilder(
      animation: _progressAnimation,
      builder: (_, __) => LinearProgressIndicator(
        value: _progressAnimation.value,
        minHeight: widget.minHeight,
        backgroundColor: widget.backgroundColor,
        valueColor: widget.valueColor,
      ),
    ),
  ),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant