mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-10 02:43:12 +00:00
40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:equatable/equatable.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:selfprivacy/config/get_it_config.dart';
|
|
|
|
part 'connection_status_event.dart';
|
|
part 'connection_status_state.dart';
|
|
|
|
class ConnectionStatusBloc
|
|
extends Bloc<ConnectionStatusEvent, ConnectionStatusState> {
|
|
ConnectionStatusBloc()
|
|
: super(
|
|
const ConnectionStatusState(
|
|
connectionStatus: ConnectionStatus.nonexistent,
|
|
),
|
|
) {
|
|
on<ConnectionStatusChanged>((final event, final emit) {
|
|
emit(ConnectionStatusState(connectionStatus: event.connectionStatus));
|
|
});
|
|
final apiConnectionRepository = getIt<ApiConnectionRepository>();
|
|
_apiConnectionStatusSubscription =
|
|
apiConnectionRepository.connectionStatusStream.listen(
|
|
(final ConnectionStatus connectionStatus) {
|
|
add(
|
|
ConnectionStatusChanged(connectionStatus),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
StreamSubscription? _apiConnectionStatusSubscription;
|
|
|
|
@override
|
|
Future<void> close() {
|
|
_apiConnectionStatusSubscription?.cancel();
|
|
return super.close();
|
|
}
|
|
}
|