From 9c94355c94b15ddb46e864744b8820d1472859b1 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Mon, 12 Aug 2024 15:01:33 -0400 Subject: [PATCH] fix: analyzer warning in quicklinks_listview.dart Fix the analyzer warning about using 'BuildContext' across async gaps in `lib/components/drawer/quicklinks_listview.dart`. * Convert `onLongPress` to an async function. * Replace the `.then()` call with `await` for `Clipboard.setData`. * Add a check for `mounted` before calling `ScaffoldMessenger.of(context).showSnackBar`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/muxable/rtchat?shareId=XXXX-XXXX-XXXX-XXXX). --- lib/components/drawer/quicklinks_listview.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/components/drawer/quicklinks_listview.dart b/lib/components/drawer/quicklinks_listview.dart index d52a39b52..a3b223c3e 100644 --- a/lib/components/drawer/quicklinks_listview.dart +++ b/lib/components/drawer/quicklinks_listview.dart @@ -31,15 +31,15 @@ class QuicklinksListView extends StatelessWidget { overflow: TextOverflow.ellipsis, ), onTap: () => openUrl(source.url), - onLongPress: () { + onLongPress: () async { Navigator.pop(context); - Clipboard.setData(ClipboardData(text: url)).then((_) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context)!.copiedToClipboard)), - ); - }); + await Clipboard.setData(ClipboardData(text: url)); + if (!mounted) return; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of(context)!.copiedToClipboard)), + ); }, ); }).toList(),