AppFlowy/app_flowy/lib/welcome/application/splash_bloc.dart

38 lines
1.0 KiB
Dart
Raw Normal View History

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