MarcelGarus / marquee

A Flutter widget that scrolls text infinitely. Provides many customizations including custom scroll directions and velocities, pausing after every round and specifying custom durations and curves for accelerating and decelerating.
MIT License
274 stars 113 forks source link

Flutter 2.8.1 - ScrollController not attached to any scroll views error #76

Closed aytunch closed 2 years ago

aytunch commented 2 years ago

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 170 pos 12: '_positions.isNotEmpty': ScrollController not attached to any scroll views.

0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:47:61)

1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)

2 ScrollController.jumpTo

package:flutter/…/widgets/scroll_controller.dart:170

3 _MarqueeState.initState.

package:marquee/marquee.dart:548

4 _MarqueeState.initState.

package:marquee/marquee.dart:545

5 SchedulerBinding._invokeFrameCallback

package:flutter/…/scheduler/binding.dart:1145

danielkohl commented 2 years ago

+1

SergeyShustikov commented 2 years ago

Fixed by rewrtining initState method

 WidgetsBinding.instance?.addPostFrameCallback((_) async {
      if (!_running) {
        _running = true;
        if (_controller.hasClients) {
          _controller.jumpTo(_startPosition);
          await Future<void>.delayed(widget.startAfter);
          Future.doWhile(_scroll);
        }
      }
    });
aytunch commented 2 years ago

@SergeyShustikov @MarcelGarus Can we merge this fix to the package?

MarcelGarus commented 2 years ago

I merged this; it's published in version 2.2.1.