mirror of
https://github.com/foss42/apidash.git
synced 2025-11-30 17:59:18 +08:00
96 lines
2.9 KiB
Dart
96 lines
2.9 KiB
Dart
import 'package:apidash_design_system/tokens/tokens.dart';
|
|
import '../../../../core/utils/dashbot_icons.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
|
|
|
class ChatBubble extends StatelessWidget {
|
|
final String message;
|
|
final MessageRole role;
|
|
final String? promptOverride;
|
|
|
|
const ChatBubble({
|
|
super.key,
|
|
required this.message,
|
|
required this.role,
|
|
this.promptOverride,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (promptOverride != null &&
|
|
role == MessageRole.user &&
|
|
message == promptOverride) {
|
|
return SizedBox.shrink();
|
|
}
|
|
if (message.isEmpty) {
|
|
return Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Column(
|
|
children: [
|
|
kVSpacer8,
|
|
DashbotIcons.getDashbotIcon1(width: 42),
|
|
kVSpacer8,
|
|
CircularProgressIndicator.adaptive(),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
return Align(
|
|
alignment: role == MessageRole.user
|
|
? Alignment.centerRight
|
|
: Alignment.centerLeft,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (role == MessageRole.system) ...[
|
|
kVSpacer6,
|
|
DashbotIcons.getDashbotIcon1(width: 42),
|
|
kVSpacer8,
|
|
],
|
|
Container(
|
|
margin: const EdgeInsets.symmetric(vertical: 5.0),
|
|
padding: const EdgeInsets.all(12.0),
|
|
constraints: BoxConstraints(
|
|
maxWidth: MediaQuery.of(context).size.width * 0.75,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: role == MessageRole.user
|
|
? Theme.of(context).colorScheme.primaryContainer
|
|
: Theme.of(context).colorScheme.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(16.0),
|
|
),
|
|
child: MarkdownBody(
|
|
data: message.isEmpty ? " " : message,
|
|
selectable: true,
|
|
styleSheet: MarkdownStyleSheet.fromTheme(
|
|
Theme.of(context),
|
|
).copyWith(
|
|
p: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: role == MessageRole.user
|
|
? Theme.of(context).colorScheme.surfaceBright
|
|
: Theme.of(context).colorScheme.onSurface,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (role == MessageRole.system) ...[
|
|
IconButton(
|
|
onPressed: () {
|
|
Clipboard.setData(ClipboardData(text: message));
|
|
},
|
|
icon: Icon(
|
|
Icons.copy_rounded,
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
enum MessageRole { user, system }
|