-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
原先电脑上只能使用横向滚轮滚动, 修改后支持纵向滚轮和左键拖动,
- Loading branch information
Showing
2 changed files
with
119 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/gestures.dart'; | ||
|
||
/// 滚动容器 | ||
/// 支持鼠标滚轮滚动和拖动滚动 | ||
/// 传入ListView的scrollController | ||
class ScrollableWrapper extends StatelessWidget { | ||
final Widget child; | ||
final ScrollController scrollController; | ||
|
||
const ScrollableWrapper({ | ||
super.key, | ||
required this.child, | ||
required this.scrollController, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MouseRegion( | ||
child: Listener( | ||
onPointerSignal: (pointerSignal) { | ||
// 鼠标滚轮滚动 | ||
if (pointerSignal is PointerScrollEvent && | ||
scrollController.hasClients) { | ||
scrollController.position.moveTo( | ||
scrollController.offset + pointerSignal.scrollDelta.dy, | ||
curve: Curves.linear, | ||
); | ||
} | ||
}, | ||
child: GestureDetector( | ||
onPanUpdate: (details) { | ||
// 拖动滚动 | ||
if (scrollController.hasClients) { | ||
scrollController.position.moveTo( | ||
scrollController.offset - details.delta.dx, | ||
curve: Curves.linear, | ||
); | ||
} | ||
}, | ||
child: child, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters