fix(ui): 下拉刷新刷新期间冻结下拉位移
This commit is contained in:
1 parent
01bef7f758
commit
35860e056b
2 files changed
+73
-15
No files matched your search
@@ -9,7 +9,6 @@ import '../theme/app_colors.dart';
|
||||
|
||||
const double _maxPullDistance = 96;
|
||||
const double _refreshThreshold = 56;
|
||||
const double _holdDistance = 56;
|
||||
const double _indicatorHeight = 56;
|
||||
const double _indicatorMaxOffset = 10;
|
||||
const Duration _arrowTurnDuration = Duration(milliseconds: 160);
|
||||
@@ -42,6 +41,7 @@ class _AppPullToRefreshState extends State<AppPullToRefresh>
|
||||
late final AnimationController _offsetController;
|
||||
_PullState _state = _PullState.idle;
|
||||
bool _refreshing = false;
|
||||
bool _retracting = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -60,7 +60,7 @@ class _AppPullToRefreshState extends State<AppPullToRefresh>
|
||||
}
|
||||
|
||||
bool _onScroll(ScrollNotification notification) {
|
||||
if (notification.depth != 0 || _refreshing) return false;
|
||||
if (notification.depth != 0 || _refreshing || _retracting) return false;
|
||||
if (notification is ScrollStartNotification) {
|
||||
if (notification.dragDetails != null) _setPullDistance(0);
|
||||
} else if (notification is ScrollUpdateNotification) {
|
||||
@@ -91,24 +91,31 @@ class _AppPullToRefreshState extends State<AppPullToRefresh>
|
||||
}
|
||||
|
||||
void _release() {
|
||||
if (_refreshing) return;
|
||||
if (_refreshing || _retracting) return;
|
||||
if (_state == _PullState.armed) {
|
||||
unawaited(_refresh());
|
||||
} else if (_state == _PullState.pull) {
|
||||
_offsetController.value = 0;
|
||||
setState(() {
|
||||
_state = _PullState.idle;
|
||||
});
|
||||
unawaited(_retract());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _retract() async {
|
||||
if (_retracting) return;
|
||||
_retracting = true;
|
||||
await _animateOffsetTo(0);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_state = _PullState.idle;
|
||||
_retracting = false;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _refresh() async {
|
||||
if (_refreshing) return;
|
||||
_refreshing = true;
|
||||
setState(() => _state = _PullState.refreshing);
|
||||
final refreshFuture = Future<void>.sync(widget.onRefresh);
|
||||
try {
|
||||
await _animateOffsetTo(_holdDistance);
|
||||
await refreshFuture;
|
||||
} finally {
|
||||
if (mounted) {
|
||||
@@ -152,7 +159,10 @@ class _AppPullToRefreshState extends State<AppPullToRefresh>
|
||||
Transform.translate(
|
||||
key: const Key('pull-refresh-content'),
|
||||
offset: Offset(0, offset),
|
||||
child: IgnorePointer(ignoring: _refreshing, child: child),
|
||||
child: IgnorePointer(
|
||||
ignoring: _refreshing || _retracting,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
if (_state != _PullState.idle && offset > 0)
|
||||
Positioned(
|
||||
|
||||
Reference in new issue
Block a user