Created
January 8, 2023 12:54
-
-
Save FlutterWiz/ea61ad51c4162ce03292cbcb0e41da31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
part 'chat_setup_state.dart'; | |
part 'chat_setup_cubit.freezed.dart'; | |
@lazySingleton | |
class ChatSetupCubit extends HydratedCubit<ChatSetupState> { | |
late StreamSubscription<ChatUserModel>? _chatUserSubscription; | |
late final IChatService _chatService; | |
ChatSetupCubit() : super(ChatSetupState.empty()) { | |
_chatService = getIt<IChatService>(); | |
_chatUserSubscription = | |
_chatService.chatAuthStateChanges.listen(_listenChatUserAuthStateChangesStream); | |
} | |
@override | |
Future<void> close() async { | |
await _chatUserSubscription?.cancel(); | |
super.close(); | |
} | |
Future<void> _listenChatUserAuthStateChangesStream( | |
ChatUserModel chatUser, | |
) async { | |
emit( | |
state.copyWith(chatUser: chatUser, isUserCheckedFromChatService: true), | |
); | |
} | |
@override | |
ChatSetupState? fromJson(Map<String, dynamic> json) { | |
return ChatSetupState.empty().copyWith( | |
chatUser: json["chatUser"], | |
); | |
} | |
@override | |
Map<String, dynamic>? toJson(ChatSetupState state) { | |
return { | |
"chatUser": state.chatUser.toJson(), | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment