Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scrollable_positioned_list] _scrollableListState == null using PageView #231

Closed
oseiasmribeiro opened this issue Feb 25, 2021 · 9 comments

Comments

@oseiasmribeiro
Copy link

oseiasmribeiro commented Feb 25, 2021

A state problem occurs when using the ScrollablePositionedList inside a PageView. The problem can be reproduced through the sample repository: https://github.com/oseiasmribeiro/scrollablepositionedlistpageview

Actual behavior

bugpageview

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Expanded(flex: 1):
'package:scrollable_positioned_list/src/scrollable_positioned_list.dart': Failed assertion: line 222 pos 12: '_scrollableListState == null': is not true.

The relevant error-causing widget was
Expanded
lib/bible.dart:156
When the exception was thrown, this was the stack
#2 ItemScrollController._attach
package:scrollable_positioned_list/src/scrollable_positioned_list.dart:222
#3 _ScrollablePositionedListState.initState
package:scrollable_positioned_list/src/scrollable_positioned_list.dart:271
#4 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4765
#5 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4601
... Normal element mounting (7 frames)
...
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
'package:scrollable_positioned_list/src/scrollable_positioned_list.dart': Failed assertion: line 222 pos 12: '_scrollableListState == null': is not true.
The relevant error-causing widget was
Expanded
lib/bible.dart:152
════════════════════════════════════════════════════════════════════════════════

Environment

scrollable_positioned_list: 1.9.0
MacBook Pro 16,2 / macOS 10.15.7 (19H15)
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.6, on Mac OS X 10.15.7 19H15 darwin-x64, locale pt-BR)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.53.2)
[✓] Connected device (1 available)

@oseiasmribeiro
Copy link
Author

Please, someone help me. It could be that I'm doing something wrong.

@oseiasmribeiro
Copy link
Author

This seems to be the same problem I had a few years ago: #39

@oseiasmribeiro
Copy link
Author

Please, help me.

1 similar comment
@oseiasmribeiro
Copy link
Author

Please, help me.

@saviourdog
Copy link

i need help too,5555

@tarobins
Copy link
Collaborator

The problem is that the ItemScrollController can only be attached to one ScrollablePositionedList at a time. However, when you switch pages in the PageView, there are two ScrollablePositionedList visible for a moment and you're trying to have the ItemScrollController attached to both.

You'll need to come up with a way to have a different ItemScrollController for each page.

@oseiasmribeiro
Copy link
Author

Okay, Tarobins, I'll try. Thanks for your help!

@oseiasmribeiro
Copy link
Author

I put the ItemScrollController and the ItemPositionListener inside the PageView.builder's itemBuilder, solved the problem. Thanks @tarobins for the tip.

@ghost
Copy link

ghost commented Oct 28, 2021

@oseiasmribeiro can you share the code here, because I'm having the same issue with Page view builder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants