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

Safely call 'cancel' on Android even if lateinit property 'mToast' had not been initialized beforehand #231

Merged
merged 1 commit into from
Sep 23, 2020

Conversation

rm3l
Copy link
Contributor

@rm3l rm3l commented Sep 20, 2020

Calling cancel before showToast makes apps crash with the following Kotlin exception message: lateinit property mToast not initialized.
In my apps, I needed to "cancel" any pending Toasts (before they disappear on their own) prior to displaying new ones, and this is why I stumbled upon this particular corner case. Rather than explicitly handling that very first interaction with FlutterToast, I thought it would be more useful to just do nothing if cancel is called without a prior call to showToast.
Feel free to close this PR if you think it doesn't make sense.
Thanks!

…initialized beforehand

This covers cases where we call 'cancel' the very first time,
even if no Toast had ever been displayed beforehand.
@ponnamkarthik ponnamkarthik merged commit cb70da0 into ponnamkarthik:master Sep 23, 2020
@abianche
Copy link

I actually have the same use case, and would be great to get it handled as you described.

@rm3l
Copy link
Contributor Author

rm3l commented Oct 28, 2020

@abianche Until @ponnamkarthik releases a new version on pub.dev, you can actually reference the Git commit containing the changes here, by adding this to your pubspec.yaml file (dependencies section):

  fluttertoast:
    git:
      url: https://github.com/PonnamKarthik/FlutterToast
      ref: cb70da0093d4323002c730219aae7c255a648a0a

This will make Flutter clone this repo at the exact merge commit (cb70da0).

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

Successfully merging this pull request may close these issues.

3 participants