flutter_secure_storage
flutter_secure_storage copied to clipboard
Data of FlutterSecureStorage instance is null on iOS but not on Android
Hello, this code works on my Android app but not iOS. I tested it on a physical device and simulator.
class _MyHomePageState extends State<MyHomePage> {
final storage = const FlutterSecureStorage();
Future _containsKey() async {
return storage.containsKey(key: "conciergeRowGuid");
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _containsKey(),
builder: (context, snapshot) {
return (snapshot.data == false)
? Scaffold(
backgroundColor: Colors.white,
body: Container(child: Text("not loaded"))
)
: FutureBuilder(
future: storage.read(key: "conciergeRowGuid"),
builder: (context, snapshot) {
if (snapshot.data == null) {
return SizedBox(
height: MediaQuery.of(context).size.height - 135,
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
CircularProgressIndicator(
color: Color.fromARGB(255, 176, 64, 251),
),
],
),
);
}
return Container(child: Text("loaded"));
});
});
}
In the iOS app, snapshot.data is always null. Digging into the iOS code of the Flutter Secure Storage, the functions of containsKey, write, read, readAll, deleteAll, all have groupId as nil. Also, OSStatus status has the error code 25300 which means errSecItemNotFound . And the return NSString *value is also nil. There is a similar issue #107 but the fix suggested is not working for me.
Specs:
Flutter 2.10.4
flutter_secure_storage: ^5.0.2
MacOS Big Sur 11.6
Tested on:
- iPhone 13 Simulator iOS 15.0
- Physical iPhone 11 iOS 14.6
- Physical iPhone SE (2nd gen) iOS 15.4.1
I am just having the same problem, android and web can normally get the value, on Ios, although the contains(key) is true, the read() gets null
when it will be fixed? still facing it. @oupat @nizarmasri did you find any solution?
Same here!
Same!
Same here!
PD: In my case the error only appears when I add flavorz in mi app. Without the native flavors everything goes smoothly.
Sorry for the late response. I have released v6.1.0-beta.1 which probably fixes this issue. Can you please check, and if there is any error comment on this issue?
Currently I followed the first step in this:
# ios/Runner/Runner.entitlements
+ <key>keychain-access-groups</key>
+ <array>
+ <string>$(AppIdentifierPrefix)*</string>
+ </array>
answer and everything working. @juliansteenbakker I will check the version as soon I have a break. You think that version would replace the fix I added above?
You think that version would replace the fix I added above?
No, I tried and the fix is also required :c
v6.1.0-beta.1 fixed the issue for me.
I had a similar issue but only when the app went to the background and the phone was locked, turned out the keychain gets locked after a while
const FlutterSecureStorage(
iOptions: IOSOptions(accessibility: KeychainAccessibility.first_unlock),
),
Resolved the issue for me
For me the main issue went away, when I set the MinSDKversion for IOS to 13 (see https://docs.amplify.aws/flutter/start/project-setup/platform-setup/#enable-keychain)
For us, both read is always null, contains is always false and write doesn't throw any error (So assuming that it's storing). This issue is replicable across all scenarios on iOS 17.2 Emulator.
We have even tried these steps
- iOptions: IOSOptions(accessibility: KeychainAccessibility.first_unlock),
- Set MinSDKversion for IOS to 13
$(AppIdentifierPrefix)*
None of them has fixed the issue.
For me the main issue went away, when I set the MinSDKversion for IOS to 13 (see https://docs.amplify.aws/flutter/start/project-setup/platform-setup/#enable-keychain)
This solve issue that can't persist data on macOS for me.
I am using flutter_secure_storage: ^9.0.0. I am getting the same error. FlutterSecureStorage instance is null on ios but not in Andriod.
isn't there related code in develop re: protected data availability