1

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.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • I actually have solution for this and solved with extra observable in home page which fires when home is ready but wonder maybe there is another way. If not i will post my code as an answer. – Vytautas Pranskunas May 18 '20 at 15:33
  • Did you find another way ? I'm interested in how you've solved it if you can share your code. – Guillaume Roux Oct 22 '20 at 15:44

2 Answers2

1

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.

Guillaume Roux
  • 6,352
  • 1
  • 13
  • 38
  • thi smight work is you always looking to the home screen. However notifications can lead you to any other screens. – Vytautas Pranskunas Oct 27 '20 at 13:19
  • Yes, this was an example. You could also call the `configure()` method right after you've finished loading your data without passing by a home screen and directly pushing your wanted screen. – Guillaume Roux Oct 27 '20 at 13:57
0

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.