Created
September 13, 2018 20:08
-
-
Save gildaswise/f46c9645dbb07804e92edfa0e051b7e1 to your computer and use it in GitHub Desktop.
Apple's and Android's refresh indicator to use with CupertinoSliverRefreshControl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | |
), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refer to this issue on when and how to use this.