为 return 自定义流创建函数

Make function to return custom stream

是否可以创建一个 returns 自定义流并像这样处理它的函数?

user.logIn('owner', '1234')
.listen(
  success (Object user) {
    print(user);
  },
  error: (Object user, Object error) {
    print(error);
  }
);

类似于:

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');

然后就可以像

一样使用了