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

Should the BuildContext parameter in showToast really exist? #36

Open
jonasborggren opened this issue Feb 1, 2024 · 3 comments
Open

Comments

@jonasborggren
Copy link

jonasborggren commented Feb 1, 2024

We've been using this library in multiple ways without knowing (I wasn't a part in setup of the project), here's what I mean:

  • Wrapped the whole app in StyledToast widget (StyledToast(child: MaterialApp(..)))
  • Calling showToast using context parameter (showToast and showToastWidget)

We had an issue where the provided context could be disposed while the toast was showing (and/or was trying to dismiss), causing the following error:

Null check operator used on a null value
#0      OverlayEntry.remove (package:flutter/src/widgets/overlay.dart:170)
#1      ToastFuture.dismiss (package:flutter_styled_toast/src/styled_toast_manage.dart:74)
#2      new ToastFuture.create.<anonymous closure> (package:flutter_styled_toast/src/styled_toast_manage.dart:51)
#3      Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18)
#4      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398)
#5      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)
/// in a widget under the same widget tree
/// `context` is from the widget
showToast(..., context: context, ...);
// or
showToastWidget(Text(...), context: context, ..);

At least that's the reason we think it's happening, since it stops happening when we set context parameter to null or don't use context parameter at all.

Why be able to do both?

One way this could be avoided would be to have showToast that doesn't have context parameter, and another called showToastOn with a context parameter.

Let me know if I can help.

@jonasborggren
Copy link
Author

Actually, #28 is probably due to this too.

@egonbeermat
Copy link

@jonasborggren It is/was, and the simple modification I posted there has eliminated any further reports in Crashlytics - I could never reproduce the error locally. This package appears abandoned, so I just use locally hosted / modified source in my app now.

@jonasborggren
Copy link
Author

Can you post your changes to a fork of this library perhaps? Thanks for letting me know.

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

2 participants