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

Closed
@thumbert

Description

@thumbert

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

Metadata

Metadata

Assignees

Labels

assigned for triageissue is assigned to a domain expert for further triagef: focusFocus traversal, gaining or losing focusf: scrollingViewports, list views, slivers, etc.found in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions