Skip to content

BouncingScrollPhysics issue #62890

@dsrenesanse

Description

@dsrenesanse

This is a pagination case. If a user in overscroll (maxExtended - position < 0) while new data coming into the list and didn't unpin it's finger, CustomScrollView with BouncingScrollPhysics will kick you into the end of the list.

Flutter channel: stable.
Flutter version: v1.20.0

Example:

import 'package:flutter/material.dart';

void main() {
  runApp(MyHomePage());
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  final list = [0, 1, 2];
  var loading = false;
  final colors = [
    Colors.cyan,
    Colors.indigo,
    Colors.pink,
    Colors.red,
    Colors.blue,
    Colors.yellowAccent
  ];

  final sc = ScrollController();

  @override
  void initState() {
    super.initState();
    sc.addListener(_onScroll);
  }

  Future<void> loadMore() async {
    if(list.length < 6){
      await Future.delayed(const Duration(seconds: 3));
      list.addAll([3, 4, 5]);
    }
  }

  void _onScroll() {
    final maxExtended = sc.position.maxScrollExtent;
    final position = sc.position.pixels;
    final dif = maxExtended - position;
    if (dif == 0.0 && !loading) {
      loading = true;
      loadMore().then((value) {
        setState(() {});
        loading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: CustomScrollView(
        controller: sc,
        physics: BouncingScrollPhysics(),
        slivers: [
          SliverList(
              delegate: SliverChildBuilderDelegate(
                  (_, index) => SizedBox(
                      width: double.infinity,
                      child: Container(
                        height: 400,
                        color: colors[index],
                        child: Text(
                          index.toString(),
                          style: TextStyle(
                            fontSize: 30,
                          ),
                        ),
                      )),
                  childCount: list.length))
        ],
      ),
    );
  }

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

Video:
ezgif-4-580f64cab9f1

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: regressionIt was better in the past than it is nowf: material designflutter/packages/flutter/material repository.f: scrollingViewports, list views, slivers, etc.found in release: 1.20Found to occur in 1.20frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions