From e97e0a52af0d8bd95d9501f52788550a4f643125 Mon Sep 17 00:00:00 2001 From: Nutcake Date: Sat, 11 Nov 2023 10:54:47 +0100 Subject: [PATCH] Move copy message snackbar to top of view On Android 13 or newer there is an operating system integrated message bubble that pops up and shows you any automated clipboard changes at the bottom left of the screen. This bubble obscures the message text of the snackbar so I've moved it to the top of the screen when on Android. It might make sense to do more accurate version checking in the future to only show the snackbar if on Android < 13 or iOS but we'd need to pull in the device_info_plus package or similar for that. --- lib/widgets/messages/message_text.dart | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/widgets/messages/message_text.dart b/lib/widgets/messages/message_text.dart index c085df5..f9d7bcd 100644 --- a/lib/widgets/messages/message_text.dart +++ b/lib/widgets/messages/message_text.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:recon/models/message.dart'; @@ -17,7 +19,24 @@ class MessageText extends StatelessWidget { onLongPress: () async { await Clipboard.setData(ClipboardData(text: message.content)); if (context.mounted) { - ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Copied to clipboard"))); + 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(