2026-05-08 20:27:57 +07:00

30 lines
805 B
Dart

import 'package:flutter_bloc/flutter_bloc.dart';
class AppState {
final bool online;
final String? role;
final String? serverUrl;
const AppState({required this.online, this.role, this.serverUrl});
AppState copyWith({bool? online, String? role, String? serverUrl}) {
return AppState(
online: online ?? this.online,
role: role ?? this.role,
serverUrl: serverUrl ?? this.serverUrl,
);
}
}
class AppCubit extends Cubit<AppState> {
AppCubit() : super(const AppState(online: true));
void setSession({required String role, required String serverUrl}) {
emit(state.copyWith(role: role, serverUrl: serverUrl, online: true));
}
void setOnline(bool value) => emit(state.copyWith(online: value));
void clearSession() => emit(const AppState(online: true));
}