mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
38 lines
1.0 KiB
Dart
38 lines
1.0 KiB
Dart
import 'package:app_flowy/welcome/domain/auth_state.dart';
|
|
import 'package:app_flowy/welcome/domain/i_splash.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'splash_bloc.freezed.dart';
|
|
|
|
class SplashBloc extends Bloc<SplashEvent, SplashState> {
|
|
final ISplashUser authImpl;
|
|
SplashBloc(this.authImpl) : super(SplashState.initial());
|
|
|
|
@override
|
|
Stream<SplashState> mapEventToState(SplashEvent event) async* {
|
|
yield* event.map(
|
|
getUser: (val) async* {
|
|
final authState = await authImpl.currentUserProfile();
|
|
yield state.copyWith(auth: authState);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
@freezed
|
|
abstract class SplashEvent with _$SplashEvent {
|
|
const factory SplashEvent.getUser() = _GetUser;
|
|
}
|
|
|
|
@freezed
|
|
abstract class SplashState implements _$SplashState {
|
|
const factory SplashState({
|
|
required AuthState auth,
|
|
}) = _SplashState;
|
|
|
|
factory SplashState.initial() => const SplashState(
|
|
auth: AuthState.initial(),
|
|
);
|
|
}
|