我正在尝试制作一个包含登录屏幕和主屏幕(目前只有两个屏幕)的 Flutter 应用程序。我也在使用 Flutter 安全存储和 Http 库。
\n每当应用程序启动时,我希望应用程序检查两个属性(accessKey 和 accessId)是否存储在安全存储中。如果未找到 accessId,则会自动生成并使用 Uuid 库进行分配。而accessKey不是本地生成的,而是由API提供的。
\n应用程序导航至:
\n1)。HomeScreen,如果 accessKey 存储在安全存储中并且身份验证成功。
\n2). SignInScreen,如果没有找到accessKey或者认证失败。
我的问题是,每次执行读取操作时,安全存储都会抛出错误“对空值使用空检查运算符”。我已经初始化了存储变量,但这个问题仍然发生。
\n这是我的安全存储类代码:
\nimport 'package:flutter_secure_storage/flutter_secure_storage.dart';\n\nclass FAS {\n static FlutterSecureStorage? _storage;\n\n static void init() {\n _storage = const FlutterSecureStorage(\n aOptions: AndroidOptions(encryptedSharedPreferences: true),\n );\n }\n\n static Future<String?> read(String key) async {\n return _storage!.read(key: key);\n }\n\n static Future<Map<String, String>> readAll() async {\n return _storage!.readAll();\n }\n\n static Future<void> write(String key, String value) async {\n await _storage!.write(key: key, value: …Run Code Online (Sandbox Code Playgroud)