简体   繁体   中英

Flutter: BouncingScrollPhysics not working

Minimal code:

ListView.builder(
  physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
  itemBuilder: (_, i) => ListTile(title: Text('$i')),
  itemCount: 50,
)

The BouncingScrollPhysics seems to have no effect. I am testing this on macOS.

You don't need to set parent argument. You can just set empty constructor and it will work:

physics: BouncingScrollPhysics(),

Instead of setting physics parameter you can also use ScrollBehavior

class CustomScrollBehavior extends ScrollBehavior {
  const CustomScrollBehavior();
  @override
  ScrollPhysics getScrollPhysics(BuildContext context) {
     return const BouncingScrollPhysics();
  }
}

ScrollConfiguration(
        behavior: CustomScrollBehavior(),
        child: ListView.builder(
          // physics: BouncingScrollPhysics(),
          itemBuilder: (ctx, index) {
            ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM