Skip to content

fix(scroll): use widget.scrollBehavior and add trackpad support#3

Open
sichang824 wants to merge 3 commits intorobert-luoqing:masterfrom
sichang824:master
Open

fix(scroll): use widget.scrollBehavior and add trackpad support#3
sichang824 wants to merge 3 commits intorobert-luoqing:masterfrom
sichang824:master

Conversation

@sichang824
Copy link
Copy Markdown

Problem

On macOS (and desktop platforms in general), mouse wheel scroll events (PointerScrollEvent) are only delivered to the widget that wins the hit test. In ChatList, the topmost widgets are message bubbles (containing MouseRegion, SelectableText, etc.), not the internal Scrollable.

The current ScrollConfiguration in _renderList() only configures dragDevices (for drag-to-scroll), but this does not affect which widget receives wheel events. As a result, mouse wheel scrolling does not work properly on desktop platforms.

Additionally, the widget.scrollBehavior parameter is passed to FlutterListView but is ignored by the outer ScrollConfiguration, making it impossible for users to customize scroll behavior.

Solution

  1. Use widget.scrollBehavior if provided - This allows users to pass a custom ScrollBehavior that will be applied to the outer ScrollConfiguration, giving full control over scroll behavior.

  2. Add PointerDeviceKind.trackpad to default dragDevices - This improves trackpad scrolling support on desktop platforms.

Changes

// Before
_renderList() {
  return ScrollConfiguration(
    behavior: ScrollConfiguration.of(context).copyWith(dragDevices: {
      PointerDeviceKind.touch,
      PointerDeviceKind.mouse,
    }),
    child: SmartRefresher(...),
  );
}

// After
_renderList() {
  final scrollBehavior = widget.scrollBehavior ??
      ScrollConfiguration.of(context).copyWith(dragDevices: {
        PointerDeviceKind.touch,
        PointerDeviceKind.mouse,
        PointerDeviceKind.trackpad,
      });
  return ScrollConfiguration(
    behavior: scrollBehavior,
    child: SmartRefresher(...),
  );
}

Testing

  • Added unit tests in test/scroll_behavior_test.dart
  • Verified mouse wheel scrolling works on macOS with this fix

- Use widget.scrollBehavior if provided instead of always overriding
- Add PointerDeviceKind.trackpad to default dragDevices for better desktop support
- Add unit tests verifying trackpad support in dragDevices
- Document the fix behavior in test comments
…t-frame callbacks

Prevent "ValueNotifier was used after being disposed" by adding
if (!mounted) return in all addPostFrameCallback/SchedulerBinding
callbacks that touch ValueNotifier (newMessageCount, showLastUnreadButton,
isShowMoveToTop). Also guard _determineShowNewMsgCount() entry.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant