opt ScrollBehavior

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-07-23 20:00:00 +08:00
parent fa75f5c542
commit 47aaa28898
8 changed files with 54 additions and 17 deletions

View File

@@ -549,7 +549,6 @@ class RefreshIndicatorState extends State<RefreshIndicator>
if (widget.isClampingScrollPhysics) {
return ScrollConfiguration(
behavior: RefreshScrollBehavior(
desktopDragDevices,
scrollPhysics: RefreshScrollPhysicsIOS(
parent: const RangeMaintainingScrollPhysics(),
onDrag: _onDrag,
@@ -562,7 +561,6 @@ class RefreshIndicatorState extends State<RefreshIndicator>
}
return ScrollConfiguration(
behavior: RefreshScrollBehavior(
desktopDragDevices,
scrollPhysics: RefreshScrollPhysics(
parent: const RangeMaintainingScrollPhysics(),
onDrag: _onDrag,
@@ -625,8 +623,7 @@ class RefreshIndicatorState extends State<RefreshIndicator>
typedef refreshIndicator = RefreshIndicator;
class RefreshScrollBehavior extends CustomScrollBehavior {
const RefreshScrollBehavior(
super.dragDevices, {
const RefreshScrollBehavior({
required this.scrollPhysics,
});

View File

@@ -1,8 +1,19 @@
import 'dart:io' show Platform;
import 'package:flutter/gestures.dart' show PointerDeviceKind;
import 'package:flutter/material.dart';
const Set<PointerDeviceKind> desktopDragDevices = {
.touch,
.mouse,
.trackpad,
.stylus,
.invertedStylus,
.unknown,
};
class CustomScrollBehavior extends MaterialScrollBehavior {
const CustomScrollBehavior(this.dragDevices);
const CustomScrollBehavior();
@override
Widget buildScrollbar(
@@ -12,14 +23,32 @@ class CustomScrollBehavior extends MaterialScrollBehavior {
) => child;
@override
final Set<PointerDeviceKind> dragDevices;
Widget buildOverscrollIndicator(
BuildContext context,
Widget child,
ScrollableDetails details,
) {
if (Platform.isAndroid) {
return StretchingOverscrollIndicator(
axisDirection: details.direction,
clipBehavior: details.decorationClipBehavior ?? .hardEdge,
child: child,
);
}
return child;
}
@override
Set<PointerDeviceKind> get dragDevices => desktopDragDevices;
}
const Set<PointerDeviceKind> desktopDragDevices = <PointerDeviceKind>{
PointerDeviceKind.touch,
PointerDeviceKind.stylus,
PointerDeviceKind.invertedStylus,
PointerDeviceKind.trackpad,
PointerDeviceKind.unknown,
PointerDeviceKind.mouse,
};
class NoOverscrollIndicator extends CustomScrollBehavior {
const NoOverscrollIndicator();
@override
Widget buildOverscrollIndicator(
BuildContext context,
Widget child,
ScrollableDetails details,
) => child;
}