mirror of
https://github.com/foss42/apidash.git
synced 2025-07-01 21:47:11 +08:00
Feat: Copy Response
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
// lib/dashbot/widgets/chat_bubble.dart
|
// lib/dashbot/widgets/chat_bubble.dart
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'content_renderer.dart';
|
import 'content_renderer.dart';
|
||||||
|
|
||||||
class ChatBubble extends StatelessWidget {
|
class ChatBubble extends StatelessWidget {
|
||||||
@ -21,7 +22,28 @@ class ChatBubble extends StatelessWidget {
|
|||||||
: Theme.of(context).colorScheme.surfaceContainerHighest,
|
: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: renderContent(context, message),
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
child: renderContent(context, message),
|
||||||
|
),
|
||||||
|
if (!isUser) ...[
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.copy, size: 20),
|
||||||
|
tooltip: 'Copy Response',
|
||||||
|
onPressed: () {
|
||||||
|
Clipboard.setData(ClipboardData(text: message));
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Copied to clipboard')),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:apidash/dashbot/providers/dashbot_providers.dart';
|
import 'package:apidash/dashbot/providers/dashbot_providers.dart';
|
||||||
import 'package:apidash/providers/providers.dart';
|
import 'package:apidash/providers/providers.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'chat_bubble.dart';
|
import 'chat_bubble.dart';
|
||||||
|
|
||||||
class DashBotWidget extends ConsumerStatefulWidget {
|
class DashBotWidget extends ConsumerStatefulWidget {
|
||||||
@ -106,28 +105,10 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
const Text('DashBot', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
const Text('DashBot', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
Row(
|
IconButton(
|
||||||
children: [
|
icon: const Icon(Icons.delete_sweep),
|
||||||
IconButton(
|
tooltip: 'Clear Chat',
|
||||||
icon: const Icon(Icons.copy),
|
onPressed: () => ref.read(chatMessagesProvider.notifier).clearMessages(),
|
||||||
tooltip: 'Copy Last Response',
|
|
||||||
onPressed: () {
|
|
||||||
final lastBotMessage = ref.read(chatMessagesProvider).lastWhere(
|
|
||||||
(msg) => msg['role'] == 'bot',
|
|
||||||
orElse: () => {'message': ''},
|
|
||||||
)['message'];
|
|
||||||
Clipboard.setData(ClipboardData(text: lastBotMessage));
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(content: Text('Copied to clipboard')),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.delete_sweep),
|
|
||||||
tooltip: 'Clear Chat',
|
|
||||||
onPressed: () => ref.read(chatMessagesProvider.notifier).clearMessages(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user