代码拉取完成,页面将自动刷新
import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class CheckMarkIndicator extends StatefulWidget {
final Widget child;
const CheckMarkIndicator({
Key? key,
required this.child,
}) : super(key: key);
@override
_CheckMarkIndicatorState createState() => _CheckMarkIndicatorState();
}
class _CheckMarkIndicatorState extends State<CheckMarkIndicator>
with SingleTickerProviderStateMixin {
static const _indicatorSize = 150.0;
/// Whether to render check mark instead of spinner
bool _renderCompleteState = false;
ScrollDirection prevScrollDirection = ScrollDirection.idle;
@override
Widget build(BuildContext context) {
return CustomRefreshIndicator(
offsetToArmed: _indicatorSize,
onRefresh: () => Future.delayed(const Duration(seconds: 2)),
child: widget.child,
completeStateDuration: const Duration(seconds: 2),
onStateChanged: (change) {
/// set [_renderCompleteState] to true when controller.state become completed
if (change.didChange(to: IndicatorState.complete)) {
setState(() {
_renderCompleteState = true;
});
/// set [_renderCompleteState] to false when controller.state become idle
} else if (change.didChange(to: IndicatorState.idle)) {
setState(() {
_renderCompleteState = false;
});
}
},
builder: (
BuildContext context,
Widget child,
IndicatorController controller,
) {
return Stack(
children: <Widget>[
AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget? _) {
if (controller.scrollingDirection == ScrollDirection.reverse &&
prevScrollDirection == ScrollDirection.forward) {
controller.stopDrag();
}
prevScrollDirection = controller.scrollingDirection;
final containerHeight = controller.value * _indicatorSize;
return Container(
alignment: Alignment.center,
height: containerHeight,
child: OverflowBox(
maxHeight: 40,
minHeight: 40,
maxWidth: 40,
minWidth: 40,
alignment: Alignment.center,
child: AnimatedContainer(
duration: const Duration(milliseconds: 150),
alignment: Alignment.center,
child: _renderCompleteState
? const Icon(
Icons.check,
color: Colors.white,
)
: SizedBox(
height: 30,
width: 30,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor:
const AlwaysStoppedAnimation(Colors.white),
value:
controller.isDragging || controller.isArmed
? controller.value.clamp(0.0, 1.0)
: null,
),
),
decoration: BoxDecoration(
color: _renderCompleteState
? Colors.greenAccent
: Colors.black,
shape: BoxShape.circle,
),
),
),
);
},
),
AnimatedBuilder(
builder: (context, _) {
return Transform.translate(
offset: Offset(0.0, controller.value * _indicatorSize),
child: child,
);
},
animation: controller,
),
],
);
},
);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。