36 lines
817 B
Dart
36 lines
817 B
Dart
import 'dart:async';
|
|
|
|
import 'package:aitrainer_app/util/session.dart';
|
|
import 'package:bloc/bloc.dart';
|
|
import 'package:equatable/equatable.dart';
|
|
import 'package:meta/meta.dart';
|
|
|
|
part 'session_event.dart';
|
|
part 'session_state.dart';
|
|
|
|
class SessionBloc extends Bloc<SessionEvent, SessionState> {
|
|
final Session session;
|
|
SessionBloc({this.session}) : super(SessionInitial());
|
|
|
|
@override
|
|
Stream<SessionState> mapEventToState(
|
|
SessionEvent event,
|
|
) async* {
|
|
try {
|
|
if (event is SessionStart) {
|
|
yield SessionLoading();
|
|
await session.fetchSessionAndNavigate();
|
|
yield SessionReady();
|
|
}
|
|
} on Exception catch(ex) {
|
|
yield SessionFailure(message: ex.toString());
|
|
}
|
|
|
|
}
|
|
|
|
@override
|
|
Future<void> close() async {
|
|
await this.close(); super.close();
|
|
}
|
|
}
|