我使用的是riverpod_generator和riverpod中的AsyncNotifier
part 'auth_controller.g.dart';
// 3. annotate
@riverpod
// 4. extend like this
class AuthController extends _$AuthController {
// 5. override the [build] method to return a [FutureOr]
@override
FutureOr<void> build() {
// 6. return a value (or do nothing if the return type is void)
}
Future<void> signIn({
required String email,
required String password,
}) async {
final authRepository = ref.read(authRepositoryProvider);
state = const AsyncLoading();
state = await AsyncValue.guard(
() async => await authRepository.signIn(email, password));
}
Future<void> logout() async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
await FirebaseAuth.instance.signOut();
});
}
}
因此,当我试图注销时,错误将发生,它说
未来已完成
如何解决这个问题?
1条答案
按热度按时间vfh0ocws1#
我解决了这个问题,实际上我听了FirebaseAuth currentUser的变化,然后它会自动重定向主页(如果登录)或登录页面(如果注销),所以会出现错误,因为我订阅了FirebaseAuth的变化