38 lines
997 B
Dart
Raw Normal View History

import 'package:app_flowy/user/domain/auth_state.dart';
import 'package:app_flowy/user/domain/i_splash.dart';
2021-06-19 23:41:19 +08:00
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
2021-09-06 16:18:34 +08:00
part 'splash_bloc.freezed.dart';
2021-06-19 23:41:19 +08:00
2021-09-06 16:18:34 +08:00
class SplashBloc extends Bloc<SplashEvent, SplashState> {
final ISplashUser authImpl;
2021-09-06 16:18:34 +08:00
SplashBloc(this.authImpl) : super(SplashState.initial());
2021-06-19 23:41:19 +08:00
@override
2021-09-06 16:18:34 +08:00
Stream<SplashState> mapEventToState(SplashEvent event) async* {
2021-06-19 23:41:19 +08:00
yield* event.map(
2021-07-12 23:27:58 +08:00
getUser: (val) async* {
2021-09-04 16:53:58 +08:00
final authState = await authImpl.currentUserProfile();
2021-06-19 23:41:19 +08:00
yield state.copyWith(auth: authState);
},
);
}
}
@freezed
class SplashEvent with _$SplashEvent {
2021-09-06 16:18:34 +08:00
const factory SplashEvent.getUser() = _GetUser;
}
@freezed
class SplashState with _$SplashState {
2021-09-06 16:18:34 +08:00
const factory SplashState({
required AuthState auth,
2021-09-06 16:18:34 +08:00
}) = _SplashState;
2021-09-06 16:18:34 +08:00
factory SplashState.initial() => const SplashState(
auth: AuthState.initial(),
);
}