refactor: Enable lint use_build_context_synchronously
This commit is contained in:
parent
a3fc1bff01
commit
3296c0d92d
50 changed files with 490 additions and 293 deletions
|
|
@ -25,6 +25,7 @@ class PublicRoomDialog extends StatelessWidget {
|
|||
const PublicRoomDialog({super.key, this.roomAlias, this.chunk, this.via});
|
||||
|
||||
Future<void> _joinRoom(BuildContext context) async {
|
||||
final l10n = L10n.of(context);
|
||||
final client = Matrix.of(context).client;
|
||||
final chunk = this.chunk;
|
||||
final knock = chunk?.joinRule == 'knock';
|
||||
|
|
@ -48,12 +49,13 @@ class PublicRoomDialog extends StatelessWidget {
|
|||
);
|
||||
final roomId = result.result;
|
||||
if (roomId == null) return;
|
||||
if (!context.mounted) return;
|
||||
if (knock && client.getRoomById(roomId) == null) {
|
||||
Navigator.of(context).pop<bool>(true);
|
||||
await showOkAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).youHaveKnocked,
|
||||
message: L10n.of(context).pleaseWaitUntilInvited,
|
||||
title: l10n.youHaveKnocked,
|
||||
message: l10n.pleaseWaitUntilInvited,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
@ -73,6 +75,7 @@ class PublicRoomDialog extends StatelessWidget {
|
|||
bool _testRoom(PublishedRoomsChunk r) => r.canonicalAlias == roomAlias;
|
||||
|
||||
Future<PublishedRoomsChunk> _search(BuildContext context) async {
|
||||
final l10n = L10n.of(context);
|
||||
final chunk = this.chunk;
|
||||
if (chunk != null) return chunk;
|
||||
final query = await Matrix.of(context).client.queryPublicRooms(
|
||||
|
|
@ -80,7 +83,7 @@ class PublicRoomDialog extends StatelessWidget {
|
|||
filter: PublicRoomQueryFilter(genericSearchTerm: roomAlias),
|
||||
);
|
||||
if (!query.chunk.any(_testRoom)) {
|
||||
throw (L10n.of(context).noRoomsFound);
|
||||
throw (l10n.noRoomsFound);
|
||||
}
|
||||
return query.chunk.firstWhere(_testRoom);
|
||||
}
|
||||
|
|
@ -248,6 +251,7 @@ class PublicRoomDialog extends StatelessWidget {
|
|||
hintText: L10n.of(context).reason,
|
||||
);
|
||||
if (reason == null || reason.isEmpty) return;
|
||||
if (!context.mounted) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.reportRoom(
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ class UserDialog extends StatelessWidget {
|
|||
hintText: L10n.of(context).reason,
|
||||
);
|
||||
if (reason == null || reason.isEmpty) return;
|
||||
if (!context.mounted) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(
|
||||
|
|
|
|||
|
|
@ -53,16 +53,18 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
onSelected: (choice) async {
|
||||
switch (choice) {
|
||||
case ChatPopupMenuActions.leave:
|
||||
final l10n = L10n.of(context);
|
||||
final router = GoRouter.of(context);
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).areYouSure,
|
||||
message: L10n.of(context).archiveRoomDescription,
|
||||
okLabel: L10n.of(context).leave,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
title: l10n.areYouSure,
|
||||
message: l10n.archiveRoomDescription,
|
||||
okLabel: l10n.leave,
|
||||
cancelLabel: l10n.cancel,
|
||||
isDestructive: true,
|
||||
);
|
||||
if (confirmed != OkCancelResult.ok) return;
|
||||
if (!context.mounted) return;
|
||||
final result = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => widget.room.leave(),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:fluffychat/l10n/l10n.dart';
|
|||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/adaptive_dialog_action.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix_api_lite/utils/logs.dart';
|
||||
|
||||
/// Displays a loading dialog which reacts to the given [future]. The dialog
|
||||
/// will be dismissed and the value will be returned when the future completes.
|
||||
|
|
@ -40,6 +41,15 @@ Future<Result<T>> showFutureLoadingDialog<T>({
|
|||
}
|
||||
}
|
||||
|
||||
if (!context.mounted) {
|
||||
Logs().e(
|
||||
'Unable to show loading dialog!',
|
||||
Exception('The BuildContext is not mounted!'),
|
||||
StackTrace.current,
|
||||
);
|
||||
return Result.capture(futureExec);
|
||||
}
|
||||
|
||||
final result = await showAdaptiveDialog<Result<T>>(
|
||||
context: context,
|
||||
barrierDismissible: barrierDismissible,
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import 'package:universal_html/html.dart' as html;
|
|||
|
||||
extension LocalNotificationsExtension on MatrixState {
|
||||
Future<void> showLocalNotification(Event event) async {
|
||||
final l10n = L10n.of(context);
|
||||
final roomId = event.room.id;
|
||||
if (activeRoomId == roomId) {
|
||||
if (WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed) {
|
||||
|
|
@ -114,11 +115,11 @@ extension LocalNotificationsExtension on MatrixState {
|
|||
actions: [
|
||||
NotificationAction(
|
||||
DesktopNotificationActions.openChat.name,
|
||||
L10n.of(context).openChat,
|
||||
l10n.openChat,
|
||||
),
|
||||
NotificationAction(
|
||||
DesktopNotificationActions.seen.name,
|
||||
L10n.of(context).markAsRead,
|
||||
l10n.markAsRead,
|
||||
),
|
||||
],
|
||||
hints: hints,
|
||||
|
|
|
|||
|
|
@ -265,12 +265,19 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
InitWithRestoreExtension.deleteSessionBackup(name);
|
||||
|
||||
if (loggedInWithMultipleClients) {
|
||||
final snackbarContext =
|
||||
FluffyChatApp
|
||||
.router
|
||||
.routerDelegate
|
||||
.navigatorKey
|
||||
.currentContext ??
|
||||
context;
|
||||
|
||||
if (!snackbarContext.mounted) return;
|
||||
final l10n = L10n.of(snackbarContext);
|
||||
ScaffoldMessenger.of(
|
||||
FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ??
|
||||
context,
|
||||
).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context).oneClientLoggedOut)),
|
||||
);
|
||||
snackbarContext,
|
||||
).showSnackBar(SnackBar(content: Text(l10n.oneClientLoggedOut)));
|
||||
return;
|
||||
}
|
||||
FluffyChatApp.router.go('/');
|
||||
|
|
@ -382,15 +389,17 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
}
|
||||
|
||||
Future<void> dehydrateAction(BuildContext context) async {
|
||||
final l10n = L10n.of(context);
|
||||
final response = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
isDestructive: true,
|
||||
title: L10n.of(context).dehydrate,
|
||||
message: L10n.of(context).dehydrateWarning,
|
||||
title: l10n.dehydrate,
|
||||
message: l10n.dehydrateWarning,
|
||||
);
|
||||
if (response != OkCancelResult.ok) {
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
final result = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: client.exportDump,
|
||||
|
|
@ -404,6 +413,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
'fluffychat-export-${DateFormat(DateFormat.YEAR_MONTH_DAY).format(DateTime.now())}.fluffybackup';
|
||||
|
||||
final file = MatrixFile(bytes: exportBytes, name: exportFileName);
|
||||
if (!context.mounted) return;
|
||||
file.save(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ Future<void> showMemberActionsPopupMenu({
|
|||
required User user,
|
||||
void Function()? onMention,
|
||||
}) async {
|
||||
final l10n = L10n.of(context);
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
final theme = Theme.of(context);
|
||||
final displayname = user.calcDisplayname();
|
||||
final isMe = user.room.client.userID == user.id;
|
||||
|
|
@ -245,12 +247,13 @@ Future<void> showMemberActionsPopupMenu({
|
|||
case _MemberActions.kick:
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).areYouSure,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).no,
|
||||
message: L10n.of(context).kickUserDescription,
|
||||
title: l10n.areYouSure,
|
||||
okLabel: l10n.yes,
|
||||
cancelLabel: l10n.no,
|
||||
message: l10n.kickUserDescription,
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
if (!context.mounted) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.kick(),
|
||||
|
|
@ -260,12 +263,13 @@ Future<void> showMemberActionsPopupMenu({
|
|||
case _MemberActions.ban:
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).areYouSure,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).no,
|
||||
message: L10n.of(context).banUserDescription,
|
||||
title: l10n.areYouSure,
|
||||
okLabel: l10n.yes,
|
||||
cancelLabel: l10n.no,
|
||||
message: l10n.banUserDescription,
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
if (!context.mounted) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.ban(),
|
||||
|
|
@ -275,20 +279,22 @@ Future<void> showMemberActionsPopupMenu({
|
|||
case _MemberActions.report:
|
||||
final reason = await showTextInputDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).whyDoYouWantToReportThis,
|
||||
okLabel: L10n.of(context).report,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
hintText: L10n.of(context).reason,
|
||||
title: l10n.whyDoYouWantToReportThis,
|
||||
okLabel: l10n.report,
|
||||
cancelLabel: l10n.cancel,
|
||||
hintText: l10n.reason,
|
||||
);
|
||||
if (reason == null || reason.isEmpty) return;
|
||||
if (!context.mounted) return;
|
||||
|
||||
final result = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.room.client.reportUser(user.id, reason),
|
||||
);
|
||||
if (result.error != null) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context).contentHasBeenReported)),
|
||||
if (!context.mounted) return;
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(content: Text(l10n.contentHasBeenReported)),
|
||||
);
|
||||
return;
|
||||
case _MemberActions.info:
|
||||
|
|
@ -304,12 +310,13 @@ Future<void> showMemberActionsPopupMenu({
|
|||
case _MemberActions.unban:
|
||||
if (await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).areYouSure,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).no,
|
||||
message: L10n.of(context).unbanUserDescription,
|
||||
title: l10n.areYouSure,
|
||||
okLabel: l10n.yes,
|
||||
cancelLabel: l10n.no,
|
||||
message: l10n.unbanUserDescription,
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
if (!context.mounted) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => user.unban(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue