【问题标题】:Flutter error after installing encrypt dependency安装加密依赖后出现颤振错误
【发布时间】:2021-09-16 08:51:03
【问题描述】:

我正在开发一个简单的应用程序,在身份验证方面,我需要使用 encrypt 包来加密 jwt 令牌,但是由于我安装了 encrypt 依赖,flutter 现在给了我这个错误:

    flutter pub add encrypt Launching lib\main.dart on Chrome in debug mode...
    flutter/.pub-cache/hosted/pub.dartlang.org/pointycastle-3.1.3/lib/key_derivators/argon2.dart:42:27:
Error: The integer literal 0xFFFFFFFFFFFFFFFF can't be represented exactly in JavaScript.
    Try changing the literal to something that can be represented in Javascript.
    In Javascript 0x10000000000000000 is the nearest value that can be represented exactly. static const int M32L = 0xFFFFFFFFFFFFFFFF; 
    
    flutter/.pub-cache/hosted/pub.dartlang.org/pointycastle-3.1.3/lib/src/utils.dart:313:9:
Error: The integer literal 0xFFFFFFFFFFFFFFFF can't be represented exactly in JavaScript.
    Try changing the literal to something that can be represented in Javascript.
    In Javascript 0x10000000000000000 is the nearest value that can be represented exactly. ((0xFFFFFFFFFFFFFFFF) ^ ((1 << (64 - count)) - 1));
    
    flutter/.pub-cache/hosted/pub.dartlang.org/pointycastle-3.1.3/lib/src/platform_check/platform_check.dart:6:35: Error: Method not found: 'getPlatform'. static Platform get instance => getPlatform(); Failed to compile application.

或者你知道任何其他加密字符串的库吗?

【问题讨论】:

  • 目前在flutter web中好像不能使用encrypt库,解决办法是切换到ninja库。

标签: flutter dart web encryption argon2-ffi


【解决方案1】:

pointycastle-3.1.3 不完全支持网络。

如果它是您在pubspec.yaml 中添加为依赖项的包,则将其升级到预发布版本;

dependencies:
  pointycastle: ^3.2.0-rc0

但是如果它依赖于你导入的另一个包, 然后添加预发布版本作为依赖覆盖;

dependency_overrides:
  pointycastle: ^3.2.0-rc0

【讨论】:

  • 安德烈在另一个答案中是正确的,应该是:dependency_overrides:
  • 是的,安德烈的答案是第一位的,应该是“接受”的答案。 @stecco
【解决方案2】:

我没有足够的声誉来评论以前的答案,但有一些地方需要纠正:

dependency_overrides:

而不是

dependency_override:

【讨论】:

    猜你喜欢
    • 2021-06-17
    • 1970-01-01
    • 2021-05-01
    • 2022-01-14
    • 2021-06-09
    • 2020-10-12
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多