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

Bug: PageController.page cannot be accessed before a PageView is built with it #175

Closed
damphat opened this issue Apr 30, 2023 · 16 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@damphat
Copy link
Contributor

damphat commented Apr 30, 2023

Describe the bug
When the IntroductionScreen has been disposed, the async method _autoScroll(int? _durationInt) continues to run asynchronously.

That causes an Exception has occurred.
_AssertionError ('package:flutter/src/widgets/page_view.dart': Failed assertion: line 173 pos 7: 'positions.isNotEmpty': PageController.page cannot be accessed before a PageView is built with it.)

To Reproduce
Run the example of this package with pushReplacement() and showSkipButton = true:

    void _onIntroEnd(context) {
        Navigator.of(context).pushReplacement(
            MaterialPageRoute(builder: (_) => const HomePage()),
        );
    }
    showSkipButton: true,
    showBackButton: false,

To fix this issues _autoScroll process must be canceled in dispose()

@damphat damphat added the bug Something isn't working label Apr 30, 2023
@ghenry
Copy link
Collaborator

ghenry commented Apr 30, 2023

Thanks for your report. Want to send a PR?

@ghenry ghenry self-assigned this Apr 30, 2023
@Macacoazul01
Copy link
Contributor

Adding this here to look later, maybe it'll help with the problem.

https://stackoverflow.com/questions/17552757/is-there-any-way-to-cancel-a-dart-future

@Macacoazul01
Copy link
Contributor

@damphat can you test the PR to see if it solves your problem?

@Macacoazul01
Copy link
Contributor

@ghenry are you maintaining dots indicator too?

@ghenry
Copy link
Collaborator

ghenry commented May 3, 2023 via email

@Macacoazul01
Copy link
Contributor

gonna open a breaking change PR there
There's no point of position being a double if dots are int

@Macacoazul01
Copy link
Contributor

Pyozer/dots_indicator#24

@Macacoazul01
Copy link
Contributor

if this update lands i'm gonna change here to int too

@damphat
Copy link
Contributor Author

damphat commented May 4, 2023

The last fix does not work; it should be simple as if (!mounted) break;

Make sure to put the statement after the async gap.

        await Future.delayed(_duration);
        if (!mounted) {
          break;
        }

@damphat
Copy link
Contributor Author

damphat commented May 4, 2023

Adding this here to look later, maybe it'll help with the problem.

https://stackoverflow.com/questions/17552757/is-there-any-way-to-cancel-a-dart-future

image

It seems that we can cancel the return value, but the async code still runs

@Macacoazul01
Copy link
Contributor

Macacoazul01 commented May 5, 2023

The last fix does not work; it should be simple as if (!mounted) break;

Make sure to put the statement after the async gap.

        await Future.delayed(_duration);
        if (!mounted) {
          break;
        }

I thought of using mounted property instead of the cancel one, but wanna try the cancel for the first time. Unfortunately it didnt work...

Tks for the help!

When @ghenry approves the PR this will be fixed

@ghenry
Copy link
Collaborator

ghenry commented May 5, 2023

Approved and merged. Just awaiting perms for pub.dev.

@ghenry ghenry closed this as completed in caf02c6 May 30, 2023
@erixsyaiful
Copy link

is this bug not resolved yet? i still got the same bug in version 3.1.9

@damphat
Copy link
Contributor Author

damphat commented Jun 21, 2023

is this bug not resolved yet? i still got the same bug in version 3.1.9

@Macacoazul01 The bug has reappeared in the implementation of infinityAutoScroll. Did you forget to check if the widget is still mounted after the async gaps?

f25bbbd#diff-b01e1c7007799dbc6e79576c5c970152638818840b6e2e6e630f352ee545321c

@Macacoazul01
Copy link
Contributor

image

@damphat
Copy link
Contributor Author

damphat commented Jun 21, 2023

Hi, you have moved the async gap with (await Future.delayed(...)) here:

Screenshot 2023-06-21 at 8 36 29 PM

we must check if widget state is still mounted.

The bug is here, when the thread wake up from await Future.delayed(...) it can't touch _pageController because that has been dispose by user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants