1 Star 1 Fork 0

蔡江洋/flutter-custom-refresh-indicator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
check_mark_indicator.dart 4.15 KB
一键复制 编辑 原始数据 按行查看 历史
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,
),
],
);
},
);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jiang-yang-cai/flutter-custom-refresh-indicator.git
git@gitee.com:jiang-yang-cai/flutter-custom-refresh-indicator.git
jiang-yang-cai
flutter-custom-refresh-indicator
flutter-custom-refresh-indicator
master

搜索帮助