selfprivacy.org.app/lib/logic/bloc/connection_status_bloc.dart
2024-04-29 18:02:23 +04:00

28 lines
851 B
Dart

import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:selfprivacy/config/get_it_config.dart';
/// basically, a bus for other blocs to listen to server status updates
class ConnectionStatusBloc extends Bloc<ConnectionStatus, ConnectionStatus> {
ConnectionStatusBloc() : super(ConnectionStatus.nonexistent) {
on<ConnectionStatus>(
(final newStatus, final emit) => emit(newStatus),
);
final apiConnectionRepository = getIt<ApiConnectionRepository>();
_apiConnectionStatusSubscription =
apiConnectionRepository.connectionStatusStream.listen(
(final ConnectionStatus newStatus) => add(newStatus),
);
}
StreamSubscription? _apiConnectionStatusSubscription;
@override
Future<void> close() {
_apiConnectionStatusSubscription?.cancel();
return super.close();
}
}