How to obtain Ref when in global function as from isolate or background process (eg: workmanager) #1956
Replies: 4 comments
-
The state in an isolate is by definition Isolated. So you won't have access to the same state in your flutter app. However you can use a raw |
Beta Was this translation helpful? Give feedback.
-
Thanks, Thanks |
Beta Was this translation helpful? Give feedback.
-
There are a few usage patterns where you actually could share the same container you use for pure dart code with the widget tree. For functions that have to be global for example you could use the following: void someFunction(ProviderContainer c){
c.read(someProvider);
}
void main() {
final c = ProviderContainer();
someFunction(c);
runApp(UncontrolledProviderScope(container: c, child: const MyApp(),));
c.dispose();
} However, it is best to structure your app so that this is not necessary. Most dart code that wants to have access to a This approach does not work with isolates though as already mentioned. If this answers your question feel free to close the issue, if you still have questions maybe give a simple example of what you want to do. |
Beta Was this translation helpful? Give feedback.
-
after i used the provider container, edit |
Beta Was this translation helpful? Give feedback.
-
as title
Beta Was this translation helpful? Give feedback.
All reactions