-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
how can i set state in static method? i get an error which is 'instanceFactory != null': Object/factory #145
Comments
My guess is that you call
before your registration is finished. |
yes it is global variable |
Yeah there is the problem. Why do you use a global variable here and not access get_it when you need it? |
bcoz periodicTaskFun need it? |
you can call Getit inside a static function |
so should i register service class in static function whith getIt? |
Why registering in the static function? just use it in there with |
i made your said but i get same error: `void periodicTaskFun() { FlutterForegroundServicePlugin.executeTask(() async { final staticIlanService = getIt<IlanService>()
});` error is:
|
could I clone your project and have a closer look? |
i created a clear project for this issue. There is a counter text in the form. When i click the Increase State From HomeViewModal its success. But When i click the Start ForeGround Service; it doesnt set the Text widget and if i use getit i get same error:
|
It didn't crash here. can you push the version that crashes? |
yes it did not crash becoz i use //i pushed crashed build repo |
Ok, it has nothing to do with the ststic method, the problem is that your periodic function is called from a different Isolate which has its own global variables, which means there also is a GetIt but it's a different instance than theone you register your objects in. Do you need to have this running on a different Isolate? would a normal Timer not be enough? I also doubt that you need that static stuff in your example service. Important is for this plugin that your periodic function is either gloibal or static. |
periodicTaskFun of foreground service is working when app is closed but timer is not :( |
ah, I see. Then I fear you have to instanciate your Objects there manually. It doesn't look like you can pass over any data to the functionthat is called. |
even so thanks for your helps :) |
Thanks, spread the word about get_it, check out get_it_mixin and I'm always happy of a nice tweet @thomasburkhartb |
hi to all. i use foreground_service plugin & stacked(state management lib) & get_it and foreground_service needs a static periodicfunction that i use a static service class in it. But when i use static class with stacked plugin, the app is working but i cant manage the state which in my static class. So how to manage state in static class, how can i use get_it & static class & states together?
my static service class is:
locator.dart:
main.dart:
myview.dart which has the periodic function fore foreground_service:
and lastly i added locator.config.dart:
so how can i use final ilanService = getIt(); instead of IlanService ilanService = IlanService(); Bcoz i have to set state in it :( (edited)
The text was updated successfully, but these errors were encountered: