Im learning flutter bloc. im trying to make a authentication event work.
This is my bloc
class SplashBloc extends Bloc<SplashEvent, SplashState> {
final supabaseClient = Supabase.instance.client;
StreamSubscription<AuthState>? _subscription;
Session? userSession;
SplashBloc() : super(SplashInitialState()) {
on<SplashInitialEvent>(
(event, emit) {
// listenAuthState(event, emit);
},
);
}
@override
Stream<SplashState> mapEventToState(SplashEvent event,) async* {
_subscription?.cancel();
if (event is SplashInitialEvent) {
_subscription = supabaseClient.auth.onAuthStateChange.listen((event) {
if (event.session?.accessToken != null) {
emit(SignedInState()); // The member 'emit' can only be used within 'package:bloc/src/bloc.dart' or a test.
} else {
yield NotSignedInState(); //Yield statements must be in a generator function (one marked with either 'async*' or 'sync*').Try adding 'async*' or 'sync*' to the enclosing function.
}
});
}
}
What is the correct way to listen to a stream and update the state? I'm still figuring bloc any help would be appreciated.