Open ASVKVINAYAK opened 3 years ago
I have exactly the same problem. Specifically, when using get_storage inside FCMs FirebaseMessaging.onBackgroundMessage
.
You need to explicitly declare a variable to be nullable. For example,
bool isLoggedIn = GetStorage().read('isLoggedIn') ?? false; // This will fail
vs
bool? isLoggedIn = GetStorage().read('isLoggedIn') ?? false; // This will work because "bool?" declare "isLoggedIn" nullable
Mine too. My get_storage got reset when receiving message from FirebaseMessaging.onBackgroundMessage
.
Is there anyone got the solution for this?
I ended up writing two GetStorage.init()
both in main() and FirebaseMessaging.onBackgroundMessage
handler and it works for me.
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await GetStorage.init(); // here
await $.firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(handleOnBackgroundMessage);
runApp(HospitalApp());
}
Future<void> handleOnBackgroundMessage(RemoteMessage event) async {
await GetStorage.init(); // and here
await $.firebase.initializeApp();
$.firebase.handleOnMessage(event);
}
Are you able to save data in the handleOnBackgroundMessage function? As i am unable to save data when receiving notifications in the background.
@henry8th Yeah sure, I can. I have no issue for storing data in FirebaseMessaging.onBackgroundMessage
handler.
Same problem here, what Flutter version are you using @ajipandean?
My flutter version is Flutter v2.2.3. @diegosiao
Hi, there the Getstorage is not working in this Scenario
not working at my end as well when using GetStorage in workmanager background process. It always returns null. Any solution for it?
@ajipandean
any solution for this one?
add GetStorage.init(); but got error
No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider
@ajipandean any solution for this one? add GetStorage.init(); but got error
No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider
I am also getting same exception.
I had the same issue trying to us GetStorage to store data on FCM background message and read the data on app resume, but it did not work. I have to revert to shared_preferences, which suffers the same fate. But shared_preference have reload() function which you can use to sync values saved in background and in foreground.
Expecting GetStorage to implement the same, since flutter has separate memory handler for background and foreground.
I am using workmanager plugin to run my app in the background and using getstorage for saving user information but when the app runs in the background get storage returns null for the particular read data What should I do I am not getting what is wrong in my code Any suggestions are welcome