是否可以创建一个返回自定义流并按此处理它的函数?
user.logIn('owner', '1234')
.listen(
success (Object user) {
print(user);
},
error: (Object user, Object error) {
print(error);
}
);
答案 0 :(得分:2)
类似的东西:
class LoginResult {
bool success = false;
String username;
}
Stream<LoginResult> onLogin() async* {
while(...) {
yield new LoginResult()
..success = isSuccess
..userName = 'someUser';
}
}
或
StreamController<LoginResult> onLoginController = new StreamController<LoginResult>();
// might not be necessary if you only need one listener at most
Stream<LoginResult> _onLogin = onLoginController.stream.asBroadcastStream();
Stream<LoginResult> get onLogin => _onLogin
...
onLoginController.add(new LoginResult()
..success = isSuccess
..userName = 'someUser');
然后你可以像
一样使用它