Skip to content

Instantly share code, notes, and snippets.

@gildaswise
Created September 13, 2018 20:08
Show Gist options
  • Save gildaswise/f46c9645dbb07804e92edfa0e051b7e1 to your computer and use it in GitHub Desktop.
Save gildaswise/f46c9645dbb07804e92edfa0e051b7e1 to your computer and use it in GitHub Desktop.
Apple's and Android's refresh indicator to use with CupertinoSliverRefreshControl
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Widget buildAppleRefreshIndicator(
BuildContext context,
RefreshIndicatorMode refreshState,
double pulledExtent,
double refreshTriggerPullDistance,
double refreshIndicatorExtent,
) {
const Curve opacityCurve = const Interval(0.4, 0.8, curve: Curves.easeInOut);
return Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: refreshState == RefreshIndicatorMode.drag
? Opacity(
opacity: opacityCurve.transform(
min(pulledExtent / refreshTriggerPullDistance, 1.0)),
child: const Icon(
CupertinoIcons.down_arrow,
color: CupertinoColors.inactiveGray,
size: 36.0,
),
)
: Opacity(
opacity: opacityCurve
.transform(min(pulledExtent / refreshIndicatorExtent, 1.0)),
child: const CupertinoActivityIndicator(radius: 14.0),
),
),
);
}
Widget buildAndroidRefreshIndicator(
BuildContext context,
RefreshIndicatorMode refreshState,
double pulledExtent,
double refreshTriggerPullDistance,
double refreshIndicatorExtent,
) {
const Curve opacityCurve = const Interval(0.4, 0.8, curve: Curves.easeInOut);
return Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: refreshState == RefreshIndicatorMode.drag
? Opacity(
opacity: opacityCurve.transform(
min(pulledExtent / refreshTriggerPullDistance, 1.0)),
child: const Icon(
Icons.arrow_downward,
color: CupertinoColors.inactiveGray,
size: 24.0,
),
)
: Opacity(
opacity: opacityCurve
.transform(min(pulledExtent / refreshIndicatorExtent, 1.0)),
child: const CircularProgressIndicator(strokeWidth: 2.0),
),
),
);
}
@gildaswise
Copy link
Author

Refer to this issue on when and how to use this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment