Skip to content

Commit

Permalink
fix: analyzer warning in quicklinks_listview.dart
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
kevmo314 committed Aug 12, 2024
1 parent 704a642 commit 9c94355
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/components/drawer/quicklinks_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 37 in lib/components/drawer/quicklinks_listview.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'mounted'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
ScaffoldMessenger.of(context).showSnackBar(

Check notice on line 38 in lib/components/drawer/quicklinks_listview.dart

View workflow job for this annotation

GitHub Actions / analyze

Don't use 'BuildContext's across async gaps, guarded by an unrelated 'mounted' check.

Guard a 'State.context' use with a 'mounted' check on the State, and other BuildContext use with a 'mounted' check on the BuildContext. See https://dart.dev/diagnostics/use_build_context_synchronously to learn more about this problem.
SnackBar(
content: Text(
AppLocalizations.of(context)!.copiedToClipboard)),

Check notice on line 41 in lib/components/drawer/quicklinks_listview.dart

View workflow job for this annotation

GitHub Actions / analyze

Don't use 'BuildContext's across async gaps, guarded by an unrelated 'mounted' check.

Guard a 'State.context' use with a 'mounted' check on the State, and other BuildContext use with a 'mounted' check on the BuildContext. See https://dart.dev/diagnostics/use_build_context_synchronously to learn more about this problem.
);
},
);
}).toList(),
Expand Down

0 comments on commit 9c94355

Please sign in to comment.