首页 > 解决方案 > 无法让计算在颤振上工作

问题描述

我正在尝试编写一个在后台运行 scrypt 函数的函数,因为它非常慢。我以前曾经计算过,但由于某种原因,这次我得到“未定义函数计算”

import "package:pointycastle/pointycastle.dart" as PC;
import 'dart:async';
Future<Uint8List> getKey(Uint8List password,Uint8List salt) async {
  return await compute(computeKey, [password,salt]);
}
Uint8List computeKey(List<Uint8List> param) {
  Uint8List salt=param[1];
  Uint8List password=param[1];

  PC.KeyDerivator scrypt = new PC.KeyDerivator("scrypt");
  scrypt.init(new PC.ScryptParameters(16384, 8, 1, 49, salt));
  return scrypt.process(password);
}

标签: asynchronousflutterdart

解决方案


您忘记导入颤振库package:flutter/foundation.dart以及返回回调函数作为参数需要 a List<dynamic> not a List<Uint8List>

还有一个快速的旁注:你不需要await在你的代码中返回未来。


推荐阅读