Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ListView.builder with a custom controller will not respond to PageUp/PageDown key events on the web #93521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thumbert opened this issue Nov 12, 2021 · 3 comments
Assignees
Labels
assigned for triage issue is assigned to a domain expert for further triage f: focus Focus traversal, gaining or losing focus f: scrolling Viewports, list views, slivers, etc. found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically

Comments

@thumbert
Copy link

Steps to Reproduce

Run the following code

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);
  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late ScrollController _controller;

  @override
  void initState() {
    _controller = ScrollController();
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: ListView.builder(
              itemCount: 500,
              controller: _controller, // will not respond to PageUp, PageDown
              itemBuilder: (BuildContext context, int i) => Text('Item $i'))),
    );
  }
}

If I run this example for a web target, pressing PageUp and PageDown on the keyboard does not have any effect. If I comment out the line

controller: _controller,

the PageUp and PageDown presses work as expected. Is this normal/expected? How do I get the default behavior if I want to have a custom scroll controller?

Sorry for cross posting, but I got no answer on SO and this potentially is a bug
https://stackoverflow.com/questions/69791696/flutters-listview-builder-with-custom-controller-will-not-respond-to-pageup-pag

Thanks for your help,
Tony

@mamuseferha mamuseferha added the in triage Presently being triaged by the triage team label Nov 12, 2021
@mamuseferha
Copy link

Hi @thumbert, thank you for filing this issue. I tested this on the latest stable and master channel and it is reproducible

flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6.1 20G224 darwin-x64, locale en-US)
    • Flutter version 2.5.3 at /Users/flo/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (4 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/flo/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.0, Build version 13A5212g
    • CocoaPods version 1.11.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.60.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.27.0

[✓] Connected device (4 available)
    • sdk gphone x86 (mobile)    • emulator-5554                        • android-x86    • Android 11 (API 30) (emulator)
    • iPhone 12 Pro Max (mobile) • 98CBBFB1-4069-4A28-B7F7-138911ACBE72 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
    • macOS (desktop)            • macos                                • darwin-x64     • macOS 11.6.1 20G224 darwin-x64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 93.0.4577.63

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 2.6.0-12.0.pre.701, on macOS 11.6.1 20G224 darwin-x64, locale en-US)
    • Flutter version 2.6.0-12.0.pre.701 at /Users/flo/fvm/versions/master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 24b9346c9b (7 hours ago), 2021-11-11 16:45:40 -0800
    • Engine revision aaacb670af
    • Dart version 2.15.0 (build 2.15.0-285.0.dev)
    • DevTools version 2.8.0

[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/flo/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 13.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.60.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.27.0

[✓] Connected device (4 available)
    • sdk gphone x86 (mobile)    • emulator-5554                        • android-x86    • Android 11 (API 30) (emulator)
    • iPhone 12 Pro Max (mobile) • 98CBBFB1-4069-4A28-B7F7-138911ACBE72 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
    • macOS (desktop)            • macos                                • darwin-x64     • macOS 11.6.1 20G224 darwin-x64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 93.0.4577.63

! Doctor found issues in 1 category.

Thank you

@mamuseferha mamuseferha added f: scrolling Viewports, list views, slivers, etc. found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically and removed in triage Presently being triaged by the triage team labels Nov 12, 2021
@yjbanov yjbanov added the assigned for triage issue is assigned to a domain expert for further triage label Nov 18, 2021
@Piinks Piinks added the f: focus Focus traversal, gaining or losing focus label Feb 23, 2023
@Piinks
Copy link
Contributor

Piinks commented Feb 23, 2023

Hi @thumbert the default behavior for keyboard shortcuts like page up and page down centers around focus. When you press page up and page down, the scrollable that encloses the nearest focus will receive the input.
If focus is not currently active, the default scroll action will use the primary scroll controller.
On desktop (and web running on desktop), since there can be many scrolling widgets in a large window, the primary scrollable (your ListView perhaps) will need to set primary to true so the PrimayScrollController knows which one gets the default shortcut handling.
If you want to access the PrimaryScrollController in order to manipulate the scroll position, just call PrimaryScrollController.of(context).

I think this is working as expected, so I am going to close this issue, but if we missed something, let us know and we can take another look!

@Piinks Piinks closed this as completed Feb 23, 2023
@github-actions
Copy link

github-actions bot commented Mar 9, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
assigned for triage issue is assigned to a domain expert for further triage f: focus Focus traversal, gaining or losing focus f: scrolling Viewports, list views, slivers, etc. found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-web Web applications specifically
Projects
None yet
Development

No branches or pull requests

5 participants