refactor: Enable lint use_build_context_synchronously

This commit is contained in:
Christian Kußowski 2026-03-25 10:42:17 +01:00
commit 3296c0d92d
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
50 changed files with 490 additions and 293 deletions

View file

@ -27,6 +27,8 @@ class UrlLauncher {
const UrlLauncher(this.context, this.url, [this.name]);
Future<void> launchUrl() async {
final l10n = L10n.of(context);
final scaffoldMessenger = ScaffoldMessenger.of(context);
if (url!.toLowerCase().startsWith(AppConfig.deepLinkPrefix) ||
url!.toLowerCase().startsWith(AppConfig.inviteLinkPrefix) ||
{'#', '@', '!', '+', '\$'}.contains(url![0]) ||
@ -36,8 +38,8 @@ class UrlLauncher {
final uri = Uri.tryParse(url!);
if (uri == null) {
// we can't open this thing
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(L10n.of(context).cantOpenUri(url!))),
scaffoldMessenger.showSnackBar(
SnackBar(content: Text(l10n.cantOpenUri(url!))),
);
return;
}
@ -47,10 +49,10 @@ class UrlLauncher {
// that the user can see the actual url before opening the browser.
final consent = await showOkCancelAlertDialog(
context: context,
title: L10n.of(context).openLinkInBrowser,
title: l10n.openLinkInBrowser,
message: url,
okLabel: L10n.of(context).open,
cancelLabel: L10n.of(context).cancel,
okLabel: l10n.open,
cancelLabel: l10n.cancel,
);
if (consent != OkCancelResult.ok) return;
}
@ -90,8 +92,8 @@ class UrlLauncher {
return;
}
if (uri.host.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(L10n.of(context).cantOpenUri(url!))),
scaffoldMessenger.showSnackBar(
SnackBar(content: Text(l10n.cantOpenUri(url!))),
);
return;
}
@ -161,6 +163,7 @@ class UrlLauncher {
}
}
servers.addAll(identityParts.via);
if (!context.mounted) return;
if (room != null) {
if (room.isSpace) {
// TODO: Implement navigate to space
@ -178,6 +181,7 @@ class UrlLauncher {
}
return;
} else {
if (!context.mounted) return;
await showAdaptiveDialog(
context: context,
builder: (c) =>
@ -185,6 +189,7 @@ class UrlLauncher {
);
}
if (roomIdOrAlias.sigil == '!') {
if (!context.mounted) return;
if (await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
@ -192,6 +197,7 @@ class UrlLauncher {
) ==
OkCancelResult.ok) {
roomId = roomIdOrAlias;
if (!context.mounted) return;
final response = await showFutureLoadingDialog(
context: context,
future: () => matrix.client.joinRoom(
@ -200,11 +206,13 @@ class UrlLauncher {
),
);
if (response.error != null) return;
if (!context.mounted) return;
// wait for two seconds so that it probably came down /sync
await showFutureLoadingDialog(
context: context,
future: () => Future.delayed(const Duration(seconds: 2)),
);
if (!context.mounted) return;
if (event != null) {
context.go(
Uri(
@ -228,6 +236,7 @@ class UrlLauncher {
return Profile(userId: userId);
}),
);
if (!context.mounted) return;
await UserDialog.show(
context: context,
profile: profileResult.result!,