Ashish-Raturi / scroll_loop_auto_scroll

This widget automatically scrolls the custom child widget to an infinite loop.
MIT License
19 stars 7 forks source link

Fix "ScrollController not attached to any scroll views." #6

Open hyungtaecf opened 1 year ago

hyungtaecf commented 1 year ago

This should fix this error I was getting:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 105 pos 12: '_positions.isNotEmpty': ScrollController not attached to any scroll views.
scroll_controller.dart:105
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      ScrollController.position
scroll_controller.dart:105
#3      _ScrollLoopAutoScrollState.animationHandler
scroll_loop_auto_scroll.dart:124
#4      _ScrollLoopAutoScrollState.initState.<anonymous closure>
scroll_loop_auto_scroll.dart:117
<asynchronous suspension>

This is because in this part of the code it is calling animationHandler() after an asynchronous gap and not checking if there are clients positions before accessing scrollController.position

WidgetsBinding
.instance.addPostFrameCallback((timeStamp) async {
      await Future.delayed(widget.delay);
      animationHandler();
    });
dawiddszewczyk commented 7 months ago

I also exposed this error on 0.0.5 version @hyungtaecf