【发布时间】:2015-05-23 18:57:11
【问题描述】:
我在使用 JwtSessionHandler 时遇到了飞镖类型的问题。我想使用来自shelf_auth git 存储库的this 示例应用程序作为指南来集成用户身份验证和会话。
不幸的是,我在运行应用程序时遇到错误(在运行应用程序之前未检测到语法错误) 错误信息如下:
Breaking on exception: object of type _TypeError: type '(String, String) => Future<UserLookupByUsernamePassword<Principal>>' is not a subtype of type 'UserLookupByUsernamePassword' of 'userLookup'.
错误源于这行代码
var sessionHandler = new JwtSessionHandler('super app',new Uuid().v4(),testLookup.lookupByUsernamePassword);
从JwtSessionHandler 的最后一个输入参数开始
testLookup.lookupByUsernamePassword。 testLookup 由 var testLookup = new TestUserLookup(); 定义
在哪里
class TestUserLookup {
Future<Option<Principal>> lookupByUsernamePassword(String username, String password) {
final validUser = username == 'fred';
final principalOpt = validUser ? new Some(new Principal(username)) : const None();
return new Future.value(principalOpt);
}
Future<Option<Principal>> lookupByUsername(String username) {
final validUser = username == 'fred';
final principalOpt = validUser ? new Some(new Principal(username)) : const None();
return new Future.value(principalOpt);
}
}
所以这部分代码和例子中的完全一样。我试图将Option<Principal> 部分更改为UserLookupByUsername<Principal>,但后来我被卡住了。我的应用程序的整个代码可以通过 here 找到。错误发生在handlers.dart。
非常感谢任何帮助。
【问题讨论】: