mchess-client/lib/connection_cubit/connection_cubit.dart

36 lines
799 B
Dart
Raw Normal View History

import 'package:flutter_bloc/flutter_bloc.dart';
import '../connection/ws_connection.dart';
class ConnectionCubit extends Cubit<ConnectionCubitState> {
static final ConnectionCubit _instance = ConnectionCubit._internal();
ConnectionCubit._internal() : super(ConnectionCubitState.init());
factory ConnectionCubit.getInstance() {
return ConnectionCubit();
}
factory ConnectionCubit() {
return _instance;
}
2024-05-19 15:22:06 +00:00
void connect(String? passphrase) {
ServerConnection.getInstance().connect(passphrase);
2023-06-29 23:49:18 +00:00
}
void opponentConnected() {
emit(ConnectionCubitState(true));
}
}
class ConnectionCubitState {
2023-06-29 23:49:18 +00:00
final bool opponentConnected;
2023-06-29 23:49:18 +00:00
ConnectionCubitState(this.opponentConnected);
factory ConnectionCubitState.init() {
return ConnectionCubitState(false);
}
}