Merge pull request #15 from Nutcake/isovel/message-copy
feat: add copying message text via long press
This commit is contained in:
commit
7a5b0c8211
1 changed files with 37 additions and 9 deletions
|
@ -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/widgets/formatted_text.dart';
|
||||
import 'package:recon/widgets/messages/message_state_indicator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MessageText extends StatelessWidget {
|
||||
const MessageText({required this.message, this.foregroundColor, super.key});
|
||||
|
@ -11,7 +14,32 @@ class MessageText extends StatelessWidget {
|
|||
|
||||
@override
|
||||
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,
|
||||
children: [
|
||||
Container(
|
||||
|
@ -21,21 +49,21 @@ class MessageText extends StatelessWidget {
|
|||
message.formattedContent,
|
||||
softWrap: true,
|
||||
maxLines: null,
|
||||
style: Theme
|
||||
.of(context)
|
||||
.textTheme
|
||||
.bodyLarge
|
||||
?.copyWith(color: foregroundColor),
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: foregroundColor),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
MessageStateIndicator(message: message, foregroundColor: foregroundColor,),
|
||||
MessageStateIndicator(
|
||||
message: message,
|
||||
foregroundColor: foregroundColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue