-
-
Notifications
You must be signed in to change notification settings - Fork 434
Flutter secure storage not storing data after I closed app IOS #532
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
Comments
This will help https://www.youtube.com/watch?v=JogvnnaJ8TI |
I'm noticing this in a specific scenario where I log out and log in of my app. So basically, we wipe the stored data, and then store a new token when logging in. After restarting/hot restart; same behavior as @stefanoHTB described. If I login and store a token after a clean start; there is no issue upon restart. In my case, this problem occurs on both Android and iOS |
Hello, if you do getToken a second time, will the value still be null? I encountered a strange behavior that sometimes when I start the application, the value is returned null first time. However, it returns value after a certain amount of time when I try to do getToken again. And only on iOS. |
Duplicates #524 ? |
Having the same problem. Did anyone found a solution? |
Having this same problem on MacOS. flutter secure storage version 9.0 |
@codelovercc Same issue on macOS, did not test iOS yet.
How are you all fixing this? I see no solution, at least not with an understandable explanation. I'm beginning to think this PKG is not working well enough, pity. I will circle back to the issue later. I still need to test it on all platforms. Edit:
|
@rydmike Enable keychain this will help you. I've tested on macOS 12.7.1 (21G920) and Android Simulator API 34, it works. |
Thanks @codelovercc for the suggestion. I have tried enabling keychain on both iOS (17.0.1 (21A342) and macOS Version 14.3 (23D56) in all modes debug/profile/release. No luck. I also tried with
Made no difference, if it was true or false, or if that The flutter_secure_storage just always reads blank data when it starts up. While running the app it sets and gets data fine in it. But close the app and start it again, and it is gone. |
@rydmike Can you try it in a new flutter project? |
Same problem occurring on Windows. |
@codelovercc I have tried, and also tried recreating the runner on macos, by deleting it and making a new one. I have also tried this part with the mentioned here: https://github.com/mogol/flutter_secure_storage All in all it did not help either. I am a bit unsure of it should be the same as "Bundle identifier" in xcode, that is seems to put into Keychain Sharing under Keychain Groups. Xcode did that edit. Then I don't know if that should then also be used in This package is a bit frustrating to use, since it seem to be close to impossible to get it to work on all platforms. Any help is of course appreciated, but I may need to come up with some alternative soonish, not urgent yet. Still not sure if there is any other good and reputable option available. |
Got it working on macOS. Here is how. When you are using <key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.domain.app</string>
</array> And I did, but it was still not working. However, do not use any mOptions: MacOsOptions(
synchronizable: true,
accessibility: KeychainAccessibility.first_unlock,
), At least for me adding any kind of mOptions: MacOsOptions(
groupId: 'com.domain.app', // NO NO! Did not matter what I used, any string made it not work.
synchronizable: true,
accessibility: KeychainAccessibility.first_unlock,
), At least now it seems to work in my macOS builds as well and that is nice. |
I am closing all older issues. If this issue still exists in the latest version, please let me know. |
I am having problems storing a token with flutter secure storage!
When I close the app or hot-restart the data gets lost or returns null
Any Suggestions?
-------------------------------------------------------------------- code
class Storage {
final storage = const FlutterSecureStorage();
final String _token = 'token';
Future setToken(String token) async {
const options =
IOSOptions(accessibility: KeychainAccessibility.first_unlock);
await storage.write(key: _token, value: token, iOptions: options);
}
Future<String?> getToken() async {
const options =
IOSOptions(accessibility: KeychainAccessibility.first_unlock);
return await storage.read(key: _token, iOptions: options);
}
}
The text was updated successfully, but these errors were encountered: