Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6739430

Browse files
committedAug 26, 2024
Scroll Behavior Updates
- Add NoScrollbarBehavior. - Optimize code. - Add contributor.
1 parent ccebb43 commit 6739430

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Now you can proudly display the time and headache saved by using Responsive Fram
255255
**Development:**
256256
* [Ray Li](https://github.com/searchy2)
257257
* [Spencer Lindemuth](https://github.com/SpencerLindemuth)
258+
* [Trefa1998](https://github.com/Trefa1998)
258259
* *add yourself here by contributing*
259260

260261
**Sponsor:** [Codelessly - Flutter App UI and Website Builder](https://codelessly.com/?utm_medium=link&utm_campaign=direct)

‎lib/responsive_framework.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export 'src/responsive_grid.dart';
77
export 'src/responsive_row_column.dart';
88
export 'src/responsive_scaled_box.dart';
99
export 'src/responsive_value.dart';
10-
export 'src/utils/scroll_behavior.dart';
1110
export 'src/utils/responsive_utils.dart';
11+
export 'src/utils/scroll_behavior.dart';

‎lib/src/utils/scroll_behavior.dart

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ class BouncingScrollWrapper extends StatelessWidget {
3737

3838
@override
3939
Widget build(BuildContext context) {
40-
ScrollBehavior scrollBehavior = const BouncingScrollBehavior();
41-
if (dragWithMouse) {
42-
// If mouse dragging is desired, add it to the drag devices.
43-
scrollBehavior = scrollBehavior.copyWith(
44-
dragDevices: scrollBehavior.dragDevices..add(PointerDeviceKind.mouse),
45-
);
46-
}
4740
return ScrollConfiguration(
48-
behavior: scrollBehavior,
41+
behavior: dragWithMouse
42+
? const BouncingScrollBehavior()
43+
.copyWith(dragDevices: {PointerDeviceKind.mouse})
44+
: const BouncingScrollBehavior(),
4945
child: child,
5046
);
5147
}
@@ -82,15 +78,11 @@ class ClampingScrollWrapper extends StatelessWidget {
8278

8379
@override
8480
Widget build(BuildContext context) {
85-
ScrollBehavior scrollBehavior = const ClampingScrollBehavior();
86-
if (dragWithMouse) {
87-
// If mouse dragging is desired, add it to the drag devices.
88-
scrollBehavior = scrollBehavior.copyWith(
89-
dragDevices: scrollBehavior.dragDevices..add(PointerDeviceKind.mouse),
90-
);
91-
}
9281
return ScrollConfiguration(
93-
behavior: scrollBehavior,
82+
behavior: dragWithMouse
83+
? const ClampingScrollBehavior()
84+
.copyWith(dragDevices: {PointerDeviceKind.mouse})
85+
: const ClampingScrollBehavior(),
9486
child: child,
9587
);
9688
}
@@ -100,6 +92,24 @@ class NoScrollbarBehavior extends ScrollBehavior {
10092
@override
10193
Widget buildScrollbar(
10294
BuildContext context, Widget child, ScrollableDetails details) {
103-
return child; // This prevents the ListView from showing a scrollbar.
95+
return child;
96+
}
97+
}
98+
99+
class NoScrollbarWrapper extends StatelessWidget {
100+
final Widget child;
101+
102+
const NoScrollbarWrapper({super.key, required this.child});
103+
104+
static Widget builder(BuildContext context, Widget child) {
105+
return NoScrollbarWrapper(child: child);
106+
}
107+
108+
@override
109+
Widget build(BuildContext context) {
110+
return ScrollConfiguration(
111+
behavior: NoScrollbarBehavior(),
112+
child: child,
113+
);
104114
}
105115
}

0 commit comments

Comments
 (0)
Please sign in to comment.