我正在寻找恢复在 Textformfield 中输入的电子邮件和密码,以将它们保存在手机钥匙串中。这是要使用的代码
class AuthMethodFirebase {
String mail;
String password;
BuildContext context;
AuthMethodFirebase({required this. mail, required this. password, required this.context});
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
// Creation of the secure storage variable
final flutterStorage = const FlutterSecureStorage();
// Creating options for iOS
final iosOptions = const IOSOptions(
accountName: "My app",
accessibility: KeychainAccessibility.unlocked,
);
// Creating options for Android
final androidOptions = const AndroidOptions(
sharedPreferencesName: "My app",
encryptedSharedPreferences: true,
);
Future authMethod() async {
// Saving the connection data in the secure storage
await flutterStorage.write(key: 'secret_key1', value: mail);
await flutterStorage.write(key: 'secret_key2', value: password);
// Retrieve connection data from secure storage for connection
final getStorageMail = await flutterStorage.read(key: 'secret_key1');
final getStoragePassword = await flutterStorage.read(key: 'secret_key2');
// Login to Firebase account
await firebaseAuth.signInWithEmailAndPassword(email: getStorageMail!, password: getStoragePassword!).then((value) {
// Reading of all inputs with option assignments
flutterStorage.readAll(iOptions: iosOptions, aOptions: androidOptions);
});
}
}
但是,当我按下执行我的 authMethod() 函数的按钮时,我的手机 (iPhone) 不让我保存输入钥匙串中的数据,甚至根本不保存它们,我该怎么做?