flutter_carousel_slider icon indicating copy to clipboard operation
flutter_carousel_slider copied to clipboard

Carousels crashs application on swipe with overscroll_indicator Failed assertion notification.metrics.axis == widget.axis

Open brunodmn opened this issue 3 years ago • 3 comments

When swiping forward and back really quick, bellow error is thrown and app crashes (when enableInfiniteScroll is false).

Error ════════ Exception caught by animation library ═════════════════════════════════ The following assertion was thrown while notifying listeners for AnimationController: 'package:flutter/src/widgets/overscroll_indicator.dart': Failed assertion: line 243 pos 14: 'notification.metrics.axis == widget.axis': is not true. package:flutter/…/widgets/overscroll_indicator.dart:243 2

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub: https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack #2 _GlowingOverscrollIndicatorState._handleScrollNotification package:flutter/…/widgets/overscroll_indicator.dart:243 #3 _NotificationElement.onNotification package:flutter/…/widgets/notification_listener.dart:130 #4 _NotificationNode.dispatchNotification package:flutter/…/widgets/framework.dart:3078 #5 _NotificationNode.dispatchNotification package:flutter/…/widgets/framework.dart:3081 #6 _NotificationNode.dispatchNotification package:flutter/…/widgets/framework.dart:3081

This is a reproducible code, just put in anywhere on your code, it will crash your app, if you swipe forward/back quickly.

CarouselSlider.builder(
                options: CarouselOptions(
                    height: 100,
                    enableInfiniteScroll: false
                    ),
                itemCount: 10,
                itemBuilder:
                    (BuildContext context, int index, int pageViewIndex) =>
                        Container(
                            width: MediaQuery.of(context).size.width,
                            child: Text(index.toString())),
          )

If I set enableInfiniteScroll to true (or omit it), it works as expected.

CarouselSlider.builder(
                options: CarouselOptions(
                    height: 100,
                                 ),
                itemCount: 10,
                itemBuilder:
                    (BuildContext context, int index, int pageViewIndex) =>
                        Container(
                            width: MediaQuery.of(context).size.width,
                            child: Text(index.toString())),
          )

brunodmn avatar May 18 '22 18:05 brunodmn

Hey, @brunodmn as a workaround for now you can set: scrollPhysics: const BouncingScrollPhysics(), in your CarouselOptions.

tsinis avatar May 24 '22 20:05 tsinis

Hey, @brunodmn as a workaround for now you can set: scrollPhysics: const BouncingScrollPhysics(), in your CarouselOptions.

it did work. Thank you!

brunodmn avatar May 25 '22 19:05 brunodmn

Hello,

This is also a problem for me, I used the above fix for now but would be great if the user couldn't over or underscroll!

Thanks

pma07pg avatar Jun 08 '22 09:06 pma07pg