google / flutter.widgets

https://pub.dev/packages/flutter_widgets
BSD 3-Clause "New" or "Revised" License
1.37k stars 479 forks source link

[scrollable_positioned_list] Failed assertion: line 239 pos 12: '_scrollableListState == null': is not true in an Overlay #288

Open edwardaux opened 3 years ago

edwardaux commented 3 years ago

Problem description

Using ^0.2.0-nullsafety.0 of scrollable_positioned_list inside a stateful widget that displays an overlay, I constantly get this error every time the overlay gets re-created:

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building PageStorage:
'package:scrollable_positioned_list/src/scrollable_positioned_list.dart': Failed assertion: line 239 pos 12: '_scrollableListState == null': is not true.

Steps to reproduce

My particular use case is a stateful widget that is offering typeahead suggestions (somewhat like what Spotlight does on macOS) using an Overlay.

The underlying problem is a combo of a few things:

Under the covers, though, the scroll controller doesn't like it if it is being re-attached to a new widget when it had previously been attached to another one.

Expected behavior

Well, I wasn't expecting a crash... however, if you think about the above scenario, I'm not entirely sure how I'd expect this library to be able to cope with re-attaching.

Not sure if there's an underlying bug here where this package could handle this scenario a bit better, but I'm raising this ticket as a way of sharing what the underlying problem is and how to resolve (in case other developers stumble across the same problem).

Steps to resolve

While technically 100% accurate, the stack trace isn't particularly helpful in terms of figuring out /why/ it is in this state. My "fix" was relatively simple... just before re-creating the Overlay, I just create a new scroll controller. eg:

_itemScrollController = ItemScrollController();
... // create overlay
felipecastrosales commented 1 year ago

I'm have a same problem here. 🤔

felipecastrosales commented 1 year ago

But my error show inside tests. image

My mixin:

mixin ScrollToMixin {
  void scrollTo(int index, ItemScrollController itemScrollController) {
    itemScrollController.scrollTo(
      index: index,
      alignment: 0,
      curve: Curves.easeIn,
      duration: const Duration(milliseconds: 1500),
    );
  }
}
CodeKiteshub commented 1 year ago

getting same error.

DevTiago commented 10 months ago

+1

andy-thestunt commented 4 months ago

I am also facing the same issue.