我收到的错误:发生异常。 NoSuchMethodError(NoSuchMethodError:在空调用getter'uid'。 接收者:null 尝试调用:uid)
@override
AuthenticationState get initialState => Uninitialized();
@override
Stream<AuthenticationState> mapEventToState(
AuthenticationEvent event,
) async* {
if (event is AppStarted) {
yield* _mapAppStartedToState();
} else if (event is LoggedIn) {
yield* _mapLoggedInToState();
} else if (event is LoggedOut) {
yield* _mapLoggedOutToState();
}
}
Stream<AuthenticationState> _mapAppStartedToState() async* {
try {
final isSignedIn = await _userRepository.isSignedIn();
if (isSignedIn) {
final uid = await _userRepository.getUser();
final isFirstTime = await _userRepository.isFirstTime(uid);
if (!isFirstTime) {
yield AuthenticatedButNotSet(uid);
} else {
yield Authenticated(uid);
}
} else {
yield Unauthenticated();
}
} catch (_) {
yield Unauthenticated();
}
}
调用getUser时发生错误,但我不确定为什么,因为我包含了一个产生未经验证的catch块
Future<String> getUser() async {
return (await _firebaseAuth.currentUser()).uid;
}