Replies: 1 comment 1 reply
-
Did you high-level in |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Why does this limitation exist?
I'm kind of having hard time understanding how to do anything useful within the handler beyond some simple app.
Lot of times Firebase setup will be happening within Flutter widget or some service class.
My project uses dependency injection so I can create (mostly) singletons for various services and provide dependencies for them. This DI happens within class
AppContainer
and it's where I control how various services are set up.This
AppContainer
is instantiated outside ofrunApp
because the services do not use Flutter, mostly it's services that deal with storing and retrieving information (Database & API fetching). Flutter is then notified from these services via exposed streams about any changes happening.This
AppContainer
is provided to application via widgetAppProvider
that extendsInheritedWidget
. This way I can choose which services to expose to Flutter and retrieve them anywhere in the tree.You can probably guess what my problem is. When all my logic for doing network calls and storing data is encapsulated like this (and I have a good reason to do it), I can't access it in top-level function or static method.
I'm not sure what other folks are doing. I can imagine that in some projects you might be doing writes to DB like this:
Which works OK I guess but for me, it's just not very scalable. I would basically need to at least access my
AppContainer
instance on which I'd expose service for writing to DB.I think the only option that is left for me is to create
factory
constructor forAppContainer
and then do something like this:Which will probably work but I just hate it. It's kind of breaking my architecture where the
AppContainer
should not be used directly like this, now I have two places where it's accessed and it can lead to potential trouble.My ideal scenario is to register
FirebaseMessaging
inside some class and provide any services to this class via dependency injection. But as I explained, it does not seem to be possible.Thank you for any answers.
Beta Was this translation helpful? Give feedback.
All reactions