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';
|
|
|
|
|
|
|
|
part 'welcome_bloc.freezed.dart';
|
|
|
|
|
|
|
|
class WelcomeBloc extends Bloc<WelcomeEvent, WelcomeState> {
|
2021-07-12 15:27:58 +00:00
|
|
|
final IWelcomeAuth authImpl;
|
|
|
|
WelcomeBloc(this.authImpl) : super(WelcomeState.initial());
|
2021-06-19 15:41:19 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Stream<WelcomeState> mapEventToState(WelcomeEvent event) async* {
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-07-24 07:05:47 +00:00
|
|
|
|
|
|
|
@freezed
|
|
|
|
abstract class WelcomeEvent with _$WelcomeEvent {
|
|
|
|
const factory WelcomeEvent.getUser() = _GetUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
abstract class WelcomeState implements _$WelcomeState {
|
|
|
|
const factory WelcomeState({
|
|
|
|
required AuthState auth,
|
|
|
|
}) = _WelcomeState;
|
|
|
|
|
|
|
|
factory WelcomeState.initial() => const WelcomeState(
|
|
|
|
auth: AuthState.initial(),
|
|
|
|
);
|
|
|
|
}
|