Vytautas Pranskunas
Vytautas Pranskunas

Reputation: 890

Wait until app starts after onLaunch with firebase messaging and flutter

I am building an app with flutter and firebase cloud messaging. In onLounch method I have some beahviuorSubjects which triggering redirects and data refresh. However they are not working because they fire before somebody listens. I do not want to use ReplaySubject because it is tricky so I wonder if there is some standard way how to golde them until app is ready?

p.s. i know that they do work because if i do some await Future.delay(Duration(seconds: 10)) all is working fine but this is not the way to go.

Upvotes: 1

Views: 377

Answers (2)

Vytautas Pranskunas
Vytautas Pranskunas

Reputation: 890

So i have solved this by adding FirebaseMessageing.configure() to startup model And in background handler i have this code my code is:

handle(dynamic data, bool onLaunch) {
    if (onLaunch) {
      onHomeReady.take(1).listen((event) {
        _innerHandler(data, onLaunch);
      });
    } else {
      _innerHandler(data, onLaunch);
    }
  }

and onHomeReady.add(..) is triggered when in home init method. This is more flexible and concern separated but calling FirebaseMessaging.configure() in home page will do a job in most of cases.

Upvotes: 0

Guillaume Roux
Guillaume Roux

Reputation: 7318

Okay I've found out how to wait for a certain screen.

Basically the onLaunch method will be triggered once you make a call to your FirebaseMessaging.configure() method. So, if you want your application to start with a loading screen and then go to a home screen after loading some data you simply need to call FirebaseMessaging.configure() inside your home screen to fire the onLaunch at that moment.

Upvotes: 1

Related Questions