Flutter拡張NestedScrollView(3)ドロップダウン・リフレッシュの解決
6159 ワード
ポイント前の2つの問題を解決します.楽しくプロジェクトをしてみました.完璧です.
FlutterCandies QQ群:181398081
しかし公式のプルダウンを使ってRefreshIndicatorをリフレッシュすると使えないことがわかりました.
黙ってソースを開けて、もう一度見てみましょう.の
まず、これにデバッグしてnotificationを見つけました.depthは0ではありませんが、実は理解しやすいです.NestedScrollViewには転がるものがたくさんあるからです.デフォルトのRefreshIndicatorでは、最初のレイヤでなければ効果がありません.
では、私は変更して、もう一度やってみますか?
で、handleScrollNotificationメソッドでは、スクロールできないリストにスライドすると、取得したviewportDimensionは0であることがわかります.これにより、viewportDimensionの値が上書きされます.
だから私は以下の変更をしました
NestedScrollViewにとって.最大スクロール可能なviewportDimensionに注目し、これを使用してドロップダウン・リフレッシュ全体を駆動します.
Sample Code
用法は公式と一致する
最後にGithub extended_を載せるnested_scroll_view、もしあなたがもっと良い方法でこの問題を解決したり、何か分からないところがあったら、私に教えてください.心から感謝します.
FlutterCandies QQ群:181398081
しかし公式のプルダウンを使ってRefreshIndicatorをリフレッシュすると使えないことがわかりました.
黙ってソースを開けて、もう一度見てみましょう.の
まず、これにデバッグしてnotificationを見つけました.depthは0ではありませんが、実は理解しやすいです.NestedScrollViewには転がるものがたくさんあるからです.デフォルトのRefreshIndicatorでは、最初のレイヤでなければ効果がありません.
/// A [ScrollNotificationPredicate] that checks whether
/// `notification.depth == 0`, which means that the notification did not bubble
/// through any intervening scrolling widgets.
bool defaultScrollNotificationPredicate(ScrollNotification notification) {
return notification.depth == 0;
}
では、私は変更して、もう一度やってみますか?
bool defaultScrollNotificationPredicate(ScrollNotification notification) {
return true;
return notification.depth == 0;
}
で、handleScrollNotificationメソッドでは、スクロールできないリストにスライドすると、取得したviewportDimensionは0であることがわかります.これにより、viewportDimensionの値が上書きされます.
だから私は以下の変更をしました
double maxContainerExtent = 0.0;
bool _handleScrollNotification(ScrollNotification notification) {
if (!widget.notificationPredicate(notification)) return false;
maxContainerExtent = math.max(
notification.metrics.viewportDimension, this.maxContainerExtent);
if (notification is ScrollStartNotification &&
notification.metrics.extentBefore == 0.0 &&
_mode == null &&
_start(notification.metrics.axisDirection)) {
setState(() {
_mode = _RefreshIndicatorMode.drag;
});
return false;
}
bool indicatorAtTopNow;
switch (notification.metrics.axisDirection) {
case AxisDirection.down:
indicatorAtTopNow = true;
break;
case AxisDirection.up:
indicatorAtTopNow = false;
break;
case AxisDirection.left:
case AxisDirection.right:
indicatorAtTopNow = null;
break;
}
if (indicatorAtTopNow != _isIndicatorAtTop) {
if (_mode == _RefreshIndicatorMode.drag ||
_mode == _RefreshIndicatorMode.armed)
_dismiss(_RefreshIndicatorMode.canceled);
} else if (notification is ScrollUpdateNotification) {
if (_mode == _RefreshIndicatorMode.drag ||
_mode == _RefreshIndicatorMode.armed) {
if (notification.metrics.extentBefore > 0.0) {
_dismiss(_RefreshIndicatorMode.canceled);
} else {
_dragOffset -= notification.scrollDelta;
_checkDragOffset(maxContainerExtent);
}
}
if (_mode == _RefreshIndicatorMode.armed &&
notification.dragDetails == null) {
// On iOS start the refresh when the Scrollable bounces back from the
// overscroll (ScrollNotification indicating this don't have dragDetails
// because the scroll activity is not directly triggered by a drag).
_show();
}
} else if (notification is OverscrollNotification) {
if (_mode == _RefreshIndicatorMode.drag ||
_mode == _RefreshIndicatorMode.armed) {
_dragOffset -= notification.overscroll / 2.0;
_checkDragOffset(maxContainerExtent);
}
} else if (notification is ScrollEndNotification) {
switch (_mode) {
case _RefreshIndicatorMode.armed:
_show();
break;
case _RefreshIndicatorMode.drag:
_dismiss(_RefreshIndicatorMode.canceled);
break;
default:
// do nothing
break;
}
}
return false;
}
NestedScrollViewにとって.最大スクロール可能なviewportDimensionに注目し、これを使用してドロップダウン・リフレッシュ全体を駆動します.
Sample Code
用法は公式と一致する
return NestedScrollViewRefreshIndicator(
onRefresh: onRefresh,
child: extended.NestedScrollView(
最後にGithub extended_を載せるnested_scroll_view、もしあなたがもっと良い方法でこの問題を解決したり、何か分からないところがあったら、私に教えてください.心から感謝します.