cmdrootaccess / another-flushbar

A flexible widget for user notification. Customize your text, button, duration, animations and much more. For Android devs, it is made to replace Snackbars and Toasts.
https://pub.dev/packages/another_flushbar
MIT License
146 stars 90 forks source link

Question: Migration from `flushbar` #25

Closed evanblasband closed 3 years ago

evanblasband commented 3 years ago

I was previously using flushbar in my app and have now migrated however I am getting the following error:

_flushbarRoute@17117910' has not been initialized

My scenario is as follows:

// BLE devices connects
connectFlushbar = Flushbar(title: connectedName);
if (!connectFlushbar.isShowing()) {.          <-------- Error here
connectFlushbar.show(context);
}

When I was using flushbar the _flushbarRoute was null until it was shown however using another_flushbar it is not initialized which is why isShowing() creates the error. I am not really sure where to go from here. Any help would be appreciated.

Note: I have the check because multiple BLE devices can connect simultaneously (or close to it) and therefore I do not want to bombard the user with flushbars if this happens.

cmdrootaccess commented 3 years ago

hello, which version are you using ?

evanblasband commented 3 years ago

I am using version 1.10.18

cmdrootaccess commented 3 years ago

okay this really seems to be a bug. i will fix it

cmdrootaccess commented 3 years ago

fixed in 1.10.20

evanblasband commented 3 years ago

Hi,

Unfortunately the bug was not fixed with 1.10.20. After looking into it, it seems that the following does not actually check if the variable is not initialized:

if (_flushbarRoute == null) {
        return false;
}

As a temporary fix I wrapped it in a try catch as follows:

try {
      if (_flushbarRoute == null) {
        return false;
      }
    } catch (e) {
      print(e);
      return false;
    }

and the following error was still printed flutter: LateInitializationError: Field '_flushbarRoute@17117910' has not been initialized. It seems _flushbarRoute is only initialized when .show() is called? I am not exactly sure where the best place to initialize it and solve the root of the problem but the try-catch is a band-aide solution.

cmdrootaccess commented 3 years ago

great observation . maybe i need to change _flushbarRoute from late to optional . will make tests. late cant be checked if its initialized or not.

ghensto commented 3 years ago

Has this issue been fixed?

cmdrootaccess commented 3 years ago

fixed in another_flushbar: ^1.10.22