main
dart 98 lines 2.84 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:localmind/core/models/enums.dart';
3 import 'package:localmind/features/chat/data/models/message.dart';
4 import 'chat_bubble/animated_bubble.dart';
5 import 'chat_bubble/user_bubble.dart';
6 import 'chat_bubble/assistant_bubble.dart';
7 import 'chat_bubble/system_bubble.dart';
8 import 'chat_bubble/tool_bubble/tool_bubble.dart';
9
10 class ChatBubble extends StatelessWidget {
11 const ChatBubble({
12 super.key,
13 required this.message,
14 required this.allMessages,
15 this.onCopy,
16 this.onRetry,
17 this.onDelete,
18 this.onEdit,
19 this.onBranch,
20 this.onContinue,
21 this.onModelTap,
22 this.onModelLongPress,
23 this.onCycleVariant,
24 this.onSave,
25 this.onShare,
26 this.isStreaming = false,
27 });
28
29 final Message message;
30 final List<Message> allMessages;
31 final VoidCallback? onCopy;
32 final VoidCallback? onRetry;
33 final VoidCallback? onDelete;
34 final VoidCallback? onEdit;
35 final VoidCallback? onBranch;
36 final VoidCallback? onContinue;
37 final VoidCallback? onModelTap;
38 final VoidCallback? onModelLongPress;
39 final void Function(int direction)? onCycleVariant;
40 final void Function(Message message)? onSave;
41 final VoidCallback? onShare;
42 final bool isStreaming;
43
44 @override
45 Widget build(BuildContext context) {
46 return RepaintBoundary(child: _buildBubble(context));
47 }
48
49 Widget _buildBubble(BuildContext context) {
50 switch (message.role) {
51 case MessageRole.user:
52 return AnimatedBubble(
53 alignment: AlignmentDirectional.centerEnd,
54 child: UserBubble(
55 message: message,
56 allMessages: allMessages,
57 onCopy: onCopy,
58 onDelete: onDelete,
59 onEdit: onEdit,
60 onBranch: onBranch,
61 onCycleVariant: onCycleVariant,
62 onSave: onSave,
63 onShare: onShare,
64 ),
65 );
66 case MessageRole.assistant:
67 return AnimatedBubble(
68 alignment: AlignmentDirectional.centerStart,
69 child: AssistantBubble(
70 message: message,
71 allMessages: allMessages,
72 onCopy: onCopy,
73 onRetry: onRetry,
74 onDelete: onDelete,
75 onEdit: onEdit,
76 onBranch: onBranch,
77 onContinue: onContinue,
78 onModelTap: onModelTap,
79 onModelLongPress: onModelLongPress,
80 onCycleVariant: onCycleVariant,
81 onSave: onSave,
82 onShare: onShare,
83 isStreaming: isStreaming,
84 ),
85 );
86 case MessageRole.system:
87 return AnimatedBubble(
88 alignment: AlignmentDirectional.center,
89 child: SystemBubble(message: message),
90 );
91 case MessageRole.tool:
92 return AnimatedBubble(
93 alignment: AlignmentDirectional.centerStart,
94 child: ToolBubble(message: message),
95 );
96 }
97 }
98 }