// 自定义物理效果 - 只允许下拉不允许上推

import 'package:flutter/material.dart';

class OnlyDownScrollPhysics extends ScrollPhysics {
  const OnlyDownScrollPhysics({super.parent});

  @override
  OnlyDownScrollPhysics applyTo(ScrollPhysics? ancestor) {
    return OnlyDownScrollPhysics(parent: buildParent(ancestor));
  }

  @override
  double applyBoundaryConditions(ScrollMetrics position, double value) {
    // 阻止向上滚动（当不在顶部时）
    if (value > position.pixels && position.pixels > position.minScrollExtent) {
      return value - position.pixels;
    }

    // 允许下拉刷新（当在顶部时下拉）
    if (value < position.pixels && position.pixels <= position.minScrollExtent) {
      return 0.0; // 允许下拉
    }

    return super.applyBoundaryConditions(position, value);
  }
}
