feat: add copying message text via long press

This commit is contained in:
Garrett Watson 2023-11-10 18:34:17 -05:00
parent af43af673d
commit 393d71a8bc

View file

@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:recon/models/message.dart'; import 'package:recon/models/message.dart';
import 'package:recon/widgets/formatted_text.dart'; import 'package:recon/widgets/formatted_text.dart';
import 'package:recon/widgets/messages/message_state_indicator.dart'; import 'package:recon/widgets/messages/message_state_indicator.dart';
import 'package:flutter/material.dart';
class MessageText extends StatelessWidget { class MessageText extends StatelessWidget {
const MessageText({required this.message, this.foregroundColor, super.key}); const MessageText({required this.message, this.foregroundColor, super.key});
@ -11,7 +12,14 @@ class MessageText extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return GestureDetector(
onLongPress: () async {
await Clipboard.setData(ClipboardData(text: message.content)).then((_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Copied to clipboard")));
});
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Container( Container(
@ -21,8 +29,7 @@ class MessageText extends StatelessWidget {
message.formattedContent, message.formattedContent,
softWrap: true, softWrap: true,
maxLines: null, maxLines: null,
style: Theme style: Theme.of(context)
.of(context)
.textTheme .textTheme
.bodyLarge .bodyLarge
?.copyWith(color: foregroundColor), ?.copyWith(color: foregroundColor),
@ -32,10 +39,14 @@ class MessageText extends StatelessWidget {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
MessageStateIndicator(message: message, foregroundColor: foregroundColor,), MessageStateIndicator(
message: message,
foregroundColor: foregroundColor,
),
], ],
), ),
], ],
),
); );
} }
} }