public override Widget build(BuildContext context) { return(new _CupertinoSliverRefresh( refreshIndicatorLayoutExtent: widget.refreshIndicatorExtent, hasLayoutExtent: hasSliverLayoutExtent, child: new LayoutBuilder( builder: (BuildContext context1, BoxConstraints constraints) => { latestIndicatorBoxExtent = constraints.maxHeight; refreshState = transitionNextState(); if (widget.builder != null && latestIndicatorBoxExtent > 0) { return widget.builder( context1, refreshState, latestIndicatorBoxExtent, widget.refreshTriggerPullDistance, widget.refreshIndicatorExtent ); } return new Container(); } ) )); }
public static Widget buildSimpleRefreshIndicator( BuildContext context, RefreshIndicatorMode refreshState, float pulledExtent, float refreshTriggerPullDistance, float refreshIndicatorExtent ) { Curve opacityCurve = new Interval(0.4f, 0.8f, curve: Curves.easeInOut); return(new Align( alignment: Alignment.bottomCenter, child: new Padding( padding: EdgeInsets.only(bottom: 16.0f), child: refreshState == RefreshIndicatorMode.drag ? new Opacity( opacity: opacityCurve.transform(Mathf.Min(pulledExtent / refreshTriggerPullDistance, 1.0f) ), child: new Icon( CupertinoIcons.down_arrow, color: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context), size: 36.0f ) ) : new Opacity( opacity: opacityCurve.transform( Mathf.Min(pulledExtent / refreshIndicatorExtent, 1.0f) ), child: new CupertinoActivityIndicator(radius: 14.0f) ) ) )); }
RefreshIndicatorMode transitionNextState() { RefreshIndicatorMode nextState = RefreshIndicatorMode.refresh; void goToDone() { nextState = RefreshIndicatorMode.done; if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.idle) { setState(() => hasSliverLayoutExtent = false); } else { SchedulerBinding.instance.addPostFrameCallback((timestamp) => { setState(() => hasSliverLayoutExtent = false); }); } } switch (refreshState) { case RefreshIndicatorMode.inactive: if (latestIndicatorBoxExtent <= 0) { return(RefreshIndicatorMode.inactive); } else { nextState = RefreshIndicatorMode.drag; } goto case RefreshIndicatorMode.drag; case RefreshIndicatorMode.drag: if (latestIndicatorBoxExtent == 0) { return(RefreshIndicatorMode.inactive); } else if (latestIndicatorBoxExtent < widget.refreshTriggerPullDistance) { return(RefreshIndicatorMode.drag); } else { if (widget.onRefresh != null) //HapticFeedback.mediumImpact(); { SchedulerBinding.instance.addPostFrameCallback((timestamp) => { refreshTask = widget.onRefresh().whenComplete(() => { if (mounted) { setState(() => refreshTask = null); refreshState = transitionNextState(); } }); setState(() => hasSliverLayoutExtent = true); }); } return(RefreshIndicatorMode.armed); } break; case RefreshIndicatorMode.armed: if (refreshState == RefreshIndicatorMode.armed && refreshTask == null) { goToDone(); goto case RefreshIndicatorMode.done; } if (latestIndicatorBoxExtent > widget.refreshIndicatorExtent) { return(RefreshIndicatorMode.armed); } else { nextState = RefreshIndicatorMode.refresh; } goto case RefreshIndicatorMode.refresh; case RefreshIndicatorMode.refresh: if (refreshTask != null) { return(RefreshIndicatorMode.refresh); } else { goToDone(); } goto case RefreshIndicatorMode.done; case RefreshIndicatorMode.done: if (latestIndicatorBoxExtent > widget.refreshTriggerPullDistance * _inactiveResetOverscrollFraction) { return(RefreshIndicatorMode.done); } else { nextState = RefreshIndicatorMode.inactive; } break; } return(nextState); }
public override void initState() { base.initState(); refreshState = RefreshIndicatorMode.inactive; }