Merge pull request #15 from Nutcake/isovel/message-copy

feat: add copying message text via long press
This commit is contained in:
Nutcake 2023-11-11 13:36:14 +01:00 committed by GitHub
commit 7a5b0c8211
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,10 @@
import 'dart:io';
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 +14,32 @@ class MessageText extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return InkWell(
borderRadius: BorderRadius.circular(16),
onLongPress: () async {
await Clipboard.setData(ClipboardData(text: message.content));
if (context.mounted) {
const content = Text("Copied to clipboard");
ScaffoldMessenger.of(context).showSnackBar(
Platform.isIOS
? const SnackBar(content: content)
: SnackBar(
content: content,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
dismissDirection: DismissDirection.none,
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).size.height - 170,
right: 20,
left: 20,
),
),
);
}
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Container( Container(
@ -21,21 +49,21 @@ class MessageText extends StatelessWidget {
message.formattedContent, message.formattedContent,
softWrap: true, softWrap: true,
maxLines: null, maxLines: null,
style: Theme style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: foregroundColor),
.of(context)
.textTheme
.bodyLarge
?.copyWith(color: foregroundColor),
), ),
), ),
Row( Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
MessageStateIndicator(message: message, foregroundColor: foregroundColor,), MessageStateIndicator(
message: message,
foregroundColor: foregroundColor,
),
], ],
), ),
], ],
),
); );
} }
} }