Jisho-Study-Tool/lib/bloc/database/database_bloc.dart

28 lines
642 B
Dart
Raw Normal View History

2021-07-17 16:11:17 +02:00
2021-12-01 23:09:53 +01:00
import 'package:flutter_bloc/flutter_bloc.dart';
2021-07-17 16:11:17 +02:00
import './database_event.dart';
import './database_state.dart';
2021-08-08 23:16:54 +02:00
export 'package:flutter_bloc/flutter_bloc.dart';
2021-07-17 16:11:17 +02:00
export './database_event.dart';
export './database_not_connected_exception.dart';
2021-12-01 23:09:53 +01:00
export './database_state.dart';
2021-07-17 16:11:17 +02:00
class DatabaseBloc extends Bloc<DatabaseEvent, DatabaseState> {
2021-12-01 23:09:53 +01:00
DatabaseBloc() : super(const DatabaseDisconnected());
2021-07-17 16:11:17 +02:00
@override
Stream<DatabaseState> mapEventToState(DatabaseEvent event)
async* {
if (event is ConnectedToDatabase) {
yield DatabaseConnected(event.database);
} else {
2021-12-01 23:09:53 +01:00
yield const DatabaseDisconnected();
2021-07-17 16:11:17 +02:00
}
}
2021-12-01 23:09:53 +01:00
}