WT 1.1.26+3 bloc migration
This commit is contained in:
@@ -14,35 +14,30 @@ part 'session_state.dart';
|
||||
class SessionBloc extends Bloc<SessionEvent, SessionState> with Logging {
|
||||
final Session session;
|
||||
StreamSubscription? _sub;
|
||||
SettingsBloc? settingsBloc;
|
||||
|
||||
SessionBloc({required this.session}) : super(SessionInitial());
|
||||
SessionBloc({required this.session}) : super(SessionInitial()) {
|
||||
on<SessionStart>(_onStart);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<SessionState> mapEventToState(
|
||||
SessionEvent event,
|
||||
) async* {
|
||||
try {
|
||||
if (event is SessionStart) {
|
||||
log(" -------- Session starting...");
|
||||
yield SessionLoading();
|
||||
// ignore: close_sinks
|
||||
SettingsBloc settingsBloc = event.settingsBloc;
|
||||
await session.fetchSessionAndNavigate();
|
||||
FirebaseApi().setupRemoteConfig();
|
||||
String lang = AppLanguage().appLocal.languageCode;
|
||||
log("Change lang to $lang");
|
||||
settingsBloc.add(SettingsChangeLanguage(language: lang));
|
||||
yield SessionReady();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
yield SessionFailure(message: ex.toString());
|
||||
}
|
||||
void _onStart(SessionStart event, Emitter<SessionState> emit) async {
|
||||
log(" -------- Session starting...");
|
||||
emit(SessionLoading());
|
||||
|
||||
this.settingsBloc = event.settingsBloc;
|
||||
await session.fetchSessionAndNavigate();
|
||||
FirebaseApi().setupRemoteConfig();
|
||||
String lang = AppLanguage().appLocal.languageCode;
|
||||
log("Change lang to $lang");
|
||||
settingsBloc!.add(SettingsChangeLanguage(language: lang));
|
||||
emit(SessionReady());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await this.close();
|
||||
_sub?.cancel();
|
||||
settingsBloc?.close();
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user