RefreshLoader method
Implementation
Widget RefreshLoader(
BuildContext context,
Widget child,
IndicatorController controller,
) {
return AnimatedBuilder(
animation: controller,
builder: (context, _) {
final refreshProgress = controller.value.clamp(0.0, 1.0);
final isRefreshing = controller.isLoading || controller.isComplete;
final isPulling = refreshProgress > 0 && !isRefreshing;
final currentStatus = _getRefreshStatus(refreshProgress, isRefreshing);
if (currentStatus != _refreshStatus &&
(_refreshStatus != DDSRefreshStatus.completed &&
_refreshStatus != DDSRefreshStatus.failed)) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
setState(() {
_refreshStatus = currentStatus;
});
_executeStateAction(currentStatus);
}
});
}
return Stack(
children: [
if (isPulling ||
isRefreshing ||
_refreshStatus == DDSRefreshStatus.completed ||
_refreshStatus == DDSRefreshStatus.failed)
Positioned(
top: 0,
left: 0,
right: 0,
height: widget.refreshTriggerThreshold,
child: Container(
height: widget.refreshTriggerThreshold,
color: widget.loaderBackgroundColor ?? Colors.transparent,
padding: EdgeInsets.only(
top: widget.loaderPaddingTop,
bottom: widget.loaderPaddingBottom,
),
child: Center(
child: _buildRefreshLoader(
rotationProgress: isPulling ? refreshProgress : null,
),
),
),
),
Transform.translate(
offset:
Offset(0, refreshProgress * widget.refreshTriggerThreshold),
child: widget.enableBoxShadow && refreshProgress > 0
? Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color:
Theme.of(context).brightness == Brightness.dark
? Colors.white
.withOpacity(0.1 * refreshProgress)
: Colors.black
.withOpacity(0.2 * refreshProgress),
blurRadius: 10 * refreshProgress,
offset: Offset(0, -5 * refreshProgress),
spreadRadius: 0,
),
],
),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(refreshProgress * 30),
topRight: Radius.circular(refreshProgress * 30),
),
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(refreshProgress * 20),
topRight: Radius.circular(refreshProgress * 20),
),
child: child,
),
),
)
: Container(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(refreshProgress * 30),
topRight: Radius.circular(refreshProgress * 30),
),
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(refreshProgress * 20),
topRight: Radius.circular(refreshProgress * 20),
),
child: child,
),
),
),
],
);
},
);
}