feat: add clear chat functionality

This commit is contained in:
Udhay-Adithya
2025-09-21 01:08:02 +05:30
parent 3a4a871676
commit fc6abd044a
2 changed files with 25 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
import 'package:apidash_design_system/apidash_design_system.dart';
import '../../models/chat_models.dart'; import '../../models/chat_models.dart';
import '../widgets/chat_bubble.dart'; import '../widgets/chat_bubble.dart';
import '../../viewmodel/chat_viewmodel.dart'; import '../../viewmodel/chat_viewmodel.dart';
@@ -82,6 +84,17 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Row( child: Row(
children: [ children: [
ADIconButton(
icon: Icons.clear_all_rounded,
tooltip: 'Clear chat',
onPressed: ref.watch(chatViewmodelProvider).isGenerating
? null
: () {
ref
.read(chatViewmodelProvider.notifier)
.clearCurrentChat();
},
),
Expanded( Expanded(
child: TextField( child: TextField(
controller: _textController, controller: _textController,

View File

@@ -284,6 +284,18 @@ class ChatViewmodel extends StateNotifier<ChatState> {
state = state.copyWith(isGenerating: false); state = state.copyWith(isGenerating: false);
} }
void clearCurrentChat() {
final id = _currentRequest?.id ?? 'global';
_sub?.cancel();
final newSessions = {...state.chatSessions};
newSessions[id] = [];
state = state.copyWith(
chatSessions: newSessions,
isGenerating: false,
currentStreamingResponse: '',
);
}
Future<void> applyAutoFix(ChatAction action) async { Future<void> applyAutoFix(ChatAction action) async {
final requestId = _currentRequest?.id; final requestId = _currentRequest?.id;
if (requestId == null) return; if (requestId == null) return;