Flutter Secure Storage写入无法在Web上正常工作-Nosuchmethoderror:找不到方法:' generatekey'在null上

发布于 2025-02-05 19:06:31 字数 2000 浏览 3 评论 0原文

使用Flutter Secure Storage来存储数据问题。 只有当我使用某些服务器(例如Apache2)托管版本Web构建时,才会看到问题。 在使用Flutter Run -D Chrome运行应用程序时,它可以正常工作。 此外,iOS和Android版本的发行版本都可以正常运行。

我得到的问题是: nosuchmethoderror:找不到方法:null上的'GenerateKey'

代码:

if (isMasterPasswordCorrect == true) {
                                        print(
                                            'master password is correct-----');
                                        print(masterPasswordController.text);
                                        final secureStorage =
                                            new FlutterSecureStorage();
                                        try {
                                          print(
                                              'writing master password data into secure storage');
                                          await secureStorage.write(
                                              key: 'masterPassword',
                                              value: masterPasswordController
                                                  .text);
                                          print(
                                              'reading master password from secure storage');
                                          _isMasterPasswordPresent =
                                              await secureStorage.read(
                                                  key: 'masterPassword');

                                          print(
                                              '${_isMasterPasswordPresent}');
                                        } catch (e) {
                                          print(e);
                                        }
}

输出

main.dart.js:21714 master password is correct-----
main.dart.js:21714 14000
main.dart.js:21714 writing master password data into secure storage
main.dart.js:21714 NoSuchMethodError: method not found: 'generateKey' on null

Having issue with storing data using flutter secure storage.
Issue is seen only when I host the release web build with some server (like apache2).
While runing the app using flutter run -d chrome, it is working fine.
Also the release version for iOS and android versions are working fine.

The issue I am getting is:
NoSuchMethodError: method not found: 'generateKey' on null

Code:

if (isMasterPasswordCorrect == true) {
                                        print(
                                            'master password is correct-----');
                                        print(masterPasswordController.text);
                                        final secureStorage =
                                            new FlutterSecureStorage();
                                        try {
                                          print(
                                              'writing master password data into secure storage');
                                          await secureStorage.write(
                                              key: 'masterPassword',
                                              value: masterPasswordController
                                                  .text);
                                          print(
                                              'reading master password from secure storage');
                                          _isMasterPasswordPresent =
                                              await secureStorage.read(
                                                  key: 'masterPassword');

                                          print(
                                              '${_isMasterPasswordPresent}');
                                        } catch (e) {
                                          print(e);
                                        }
}

Output

main.dart.js:21714 master password is correct-----
main.dart.js:21714 14000
main.dart.js:21714 writing master password data into secure storage
main.dart.js:21714 NoSuchMethodError: method not found: 'generateKey' on null

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文