Skip to content

NotificationListener with child as ListView not emittting ScrollEndNotification DragDetails properly #39929

@nimishbansal

Description

@nimishbansal
When I add child to a NotificationListener as ListView and when I am scrolling the list view several notifications are captured.one of them being ScrollEndNotification which has DragEndDetails parameter named as (dragDetails)

Now what happens is dragDetails is not null only at the ends of the list view. If I scroll by flinging the list view and the final location is in middle of the list view then dragDetails of scrollEndNotification instance is null.

What I think is it is happening due to

If a drag ends with some residual velocity, a typical ScrollPhysics will start a ballistic scroll, which delays the ScrollEndNotification until the ballistic simulation completes, at which time dragDetails will be null.

https://api.flutter.dev/flutter/widgets/ScrollEndNotification/dragDetails.html

  • Now if this dragDetails are None how can I find actual DragEndDetails?

  • Is there any method already available, or I have to make it my own and how can I make it?.

Steps to Reproduce:

class MyListView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(itemCount:500,itemBuilder: (context, index) {
      return Text(index.toString());
    });
  }
}

class TemporaryTest extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _TemporaryTestState();
  }
}

class _TemporaryTestState extends State<TemporaryTest> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return NotificationListener(
      child: MyListView(),
      onNotification: (notification) {
        if (notification.runtimeType == ScrollEndNotification) {
          print((notification as ScrollEndNotification).dragDetails); //prints mostly null, only prints instance of DragEndDetails when either we are overscrolling at start or end, not in middle
        }
        return true;
      },
    );
  }
}

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body:TemporaryTest(),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions