0

I want to add an overscrolls at the end and at the top of the list, only if someone overscrolls.

So... I had a few ideas, I tried to start by using a GestureDetector, and it seems to not work if the list is bigger than the screen, then I went adding a ListView Scroller controller, but it only works if the List is bigger than the screen.

I went ahead an tried to add it through Notification, but it seems too slow.

Any ideas?

class _PullableListState extends State<PullableList> {
  double overScrollOnEnd = 0;

  @override
  Widget build(BuildContext context) {
    return NotificationListener<ScrollNotification>(
      onNotification: (notification) {
        // print(notification.metrics.pixels);
        if (notification is OverscrollNotification) {
          setState(() {
            overScrollOnEnd += notification.dragDetails.delta.dy;
          });
          print(overScrollOnEnd);
        }
        if (notification is ScrollUpdateNotification) {
          setState(() {
            overScrollOnEnd = 0;
          });
        }
        return true;
      },
      child: Container(
        margin: EdgeInsets.only(top: max(overScrollOnEnd, 0)),
        child: ListView.builder(
          itemBuilder: widget.itemBuilder,
          itemCount: widget.itemCount,
        ),
      ),
    );
  }
}

1 Answer 1

2

You want AlwaysScrollableScrollPhysics combined with BouncingScrollPhysics.

class _PullableListState extends State<PullableList> {
  double overScrollOnEnd = 0;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: max(overScrollOnEnd, 0)),
      child: ListView.builder(
        physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
        itemBuilder: widget.itemBuilder,
        itemCount: widget.itemCount,
      ),
    );
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

This seems like the solution for the problem.
If I wanted to add an action, lets say if I were to overflow by an X amount, how would you add it? ( You already answered my question, so I thank you, I'm just waiting for the 10 minutes to approve your answer ).
For that you'd still have to use ScrollNotifications. This is just the scroll physics, and it doesn't emit any events on its own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.