buildRefreshIndicator method Null safety

Widget buildRefreshIndicator(
  1. BuildContext context,
  2. RefreshIndicatorMode refreshState,
  3. double pulledExtent,
  4. double refreshTriggerPullDistance,
  5. double refreshIndicatorExtent
)

Builds a refresh indicator that reflects the standard iOS pull-to-refresh behavior. Specifically, this entails presenting an activity indicator that changes depending on the current refreshState. As the user initially drags down, the indicator will gradually reveal individual ticks until the refresh becomes armed. At this point, the animated activity indicator will begin rotating. Once the refresh has completed, the activity indicator shrinks away as the space allocation animates back to closed.

Implementation

static Widget buildRefreshIndicator(
  BuildContext context,
  RefreshIndicatorMode refreshState,
  double pulledExtent,
  double refreshTriggerPullDistance,
  double refreshIndicatorExtent,
) {
  final double percentageComplete = clampDouble(pulledExtent / refreshTriggerPullDistance, 0.0, 1.0);

  // Place the indicator at the top of the sliver that opens up. Note that we're using
  // a Stack/Positioned widget because the CupertinoActivityIndicator does some internal
  // translations based on the current size (which grows as the user drags) that makes
  // Padding calculations difficult. Rather than be reliant on the internal implementation
  // of the activity indicator, the Positioned widget allows us to be explicit where the
  // widget gets placed. Also note that the indicator should appear over the top of the
  // dragged widget, hence the use of Overflow.visible.
  return Center(
    child: Stack(
      clipBehavior: Clip.none,
      children: <Widget>[
        Positioned(
          top: _kActivityIndicatorMargin,
          left: 0.0,
          right: 0.0,
          child: _buildIndicatorForRefreshState(refreshState, _kActivityIndicatorRadius, percentageComplete),
        ),
      ],
    ),
  );
}