xuelongqy / flutter_easy_refresh

A flutter widget that provides pull-down refresh and pull-up load.
https://xuelongqy.github.io/flutter_easy_refresh/
MIT License
3.89k stars 633 forks source link

feat:exposure ERScrollBehaviorBuilder to add custom scroll behavior #614

Closed laiiihz closed 1 year ago

laiiihz commented 2 years ago

since flutter 3.3 landed on stable , flutter add a new pointer device (trackpad). this PR exposure a api which can define a custom scroll behavior.

example:

class CustomScrollBehavior extends ScrollBehavior {
  final ScrollPhysics? _physics;

  const CustomScrollBehavior([this._physics]);

  @override
  ScrollPhysics getScrollPhysics(BuildContext context) {
    return _physics ?? super.getScrollPhysics(context);
  }

  @override
  Widget buildViewportChrome(
      BuildContext context, Widget child, AxisDirection axisDirection) {
    return child;
  }

  @override
  Set<PointerDeviceKind> get dragDevices => <PointerDeviceKind>{
        PointerDeviceKind.touch,
        PointerDeviceKind.stylus,
        PointerDeviceKind.invertedStylus,
        PointerDeviceKind.mouse,
        PointerDeviceKind.unknown,
        // add a trackpad
        PointerDeviceKind.trackpad,
      };
}
      EasyRefresh(
        scrollBehaviorBuilder: (physics) {
          return CustomScrollBehavior(physics);
        },
        onRefresh: () async {},
        child: ListView.builder(
          itemBuilder: (context, index) {
            return const SkeletonItem();
          },
          itemCount: 8,
        ),
      )
xuelongqy commented 1 year ago

Thanks, this looks great.