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
|
|
@ -211,6 +211,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
context: context,
|
||||
future: room.leave,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (success.error != null) return;
|
||||
context.go('/rooms');
|
||||
}
|
||||
|
|
@ -475,8 +476,9 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
Future<void>? loadTimelineFuture;
|
||||
|
||||
Future<void> _getTimeline({String? eventContextId}) async {
|
||||
await Matrix.of(context).client.roomsLoading;
|
||||
await Matrix.of(context).client.accountDataLoading;
|
||||
final matrix = Matrix.of(context);
|
||||
await matrix.client.roomsLoading;
|
||||
await matrix.client.accountDataLoading;
|
||||
if (eventContextId != null &&
|
||||
(!eventContextId.isValidMatrixId || eventContextId.sigil != '\$')) {
|
||||
eventContextId = null;
|
||||
|
|
@ -632,6 +634,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
Future<void> sendFileAction({FileType type = FileType.any}) async {
|
||||
final files = await selectFiles(context, allowMultiple: true, type: type);
|
||||
if (files.isEmpty) return;
|
||||
if (!mounted) return;
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (c) => SendFileDialog(
|
||||
|
|
@ -663,6 +666,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
final file = await ImagePicker().pickImage(source: ImageSource.camera);
|
||||
if (file == null) return;
|
||||
if (!mounted) return;
|
||||
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
|
|
@ -684,6 +688,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
maxDuration: const Duration(minutes: 1),
|
||||
);
|
||||
if (file == null) return;
|
||||
if (!mounted) return;
|
||||
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
|
|
@ -726,26 +731,27 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
mimeType: mimeType,
|
||||
);
|
||||
|
||||
room
|
||||
.sendFileEvent(
|
||||
file,
|
||||
inReplyTo: replyEvent,
|
||||
threadRootEventId: activeThreadId,
|
||||
extraContent: {
|
||||
'info': {...file.info, 'duration': duration},
|
||||
'org.matrix.msc3245.voice': {},
|
||||
'org.matrix.msc1767.audio': {
|
||||
'duration': duration,
|
||||
'waveform': waveform,
|
||||
},
|
||||
try {
|
||||
await room.sendFileEvent(
|
||||
file,
|
||||
inReplyTo: replyEvent,
|
||||
threadRootEventId: activeThreadId,
|
||||
extraContent: {
|
||||
'info': {...file.info, 'duration': duration},
|
||||
'org.matrix.msc3245.voice': {},
|
||||
'org.matrix.msc1767.audio': {
|
||||
'duration': duration,
|
||||
'waveform': waveform,
|
||||
},
|
||||
)
|
||||
.catchError((e) {
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(content: Text((e as Object).toLocalizedString(context))),
|
||||
);
|
||||
return null;
|
||||
});
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(content: Text(e.toLocalizedString(context))),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
replyEvent = null;
|
||||
});
|
||||
|
|
@ -807,29 +813,30 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
|
||||
Future<void> reportEventAction() async {
|
||||
final event = selectedEvents.single;
|
||||
final l10n = L10n.of(context);
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
final score = await showModalActionPopup<int>(
|
||||
context: context,
|
||||
title: L10n.of(context).reportMessage,
|
||||
message: L10n.of(context).howOffensiveIsThisContent,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
title: l10n.reportMessage,
|
||||
message: l10n.howOffensiveIsThisContent,
|
||||
cancelLabel: l10n.cancel,
|
||||
actions: [
|
||||
AdaptiveModalAction(
|
||||
value: -100,
|
||||
label: L10n.of(context).extremeOffensive,
|
||||
),
|
||||
AdaptiveModalAction(value: -50, label: L10n.of(context).offensive),
|
||||
AdaptiveModalAction(value: 0, label: L10n.of(context).inoffensive),
|
||||
AdaptiveModalAction(value: -100, label: l10n.extremeOffensive),
|
||||
AdaptiveModalAction(value: -50, label: l10n.offensive),
|
||||
AdaptiveModalAction(value: 0, label: l10n.inoffensive),
|
||||
],
|
||||
);
|
||||
if (score == null) return;
|
||||
if (!mounted) return;
|
||||
final reason = await showTextInputDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).whyDoYouWantToReportThis,
|
||||
okLabel: L10n.of(context).ok,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
hintText: L10n.of(context).reason,
|
||||
title: l10n.whyDoYouWantToReportThis,
|
||||
okLabel: l10n.ok,
|
||||
cancelLabel: l10n.cancel,
|
||||
hintText: l10n.reason,
|
||||
);
|
||||
if (reason == null || reason.isEmpty) return;
|
||||
if (!mounted) return;
|
||||
final result = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.reportEvent(
|
||||
|
|
@ -840,12 +847,13 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
),
|
||||
);
|
||||
if (result.error != null) return;
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
showEmojiPicker = false;
|
||||
selectedEvents.clear();
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context).contentHasBeenReported)),
|
||||
scaffoldMessenger.showSnackBar(
|
||||
SnackBar(content: Text(l10n.contentHasBeenReported)),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -861,6 +869,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
setState(selectedEvents.clear);
|
||||
} catch (e, s) {
|
||||
if (!mounted) return;
|
||||
ErrorReporter(
|
||||
context,
|
||||
'Error while delete error events action',
|
||||
|
|
@ -885,6 +894,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
: null;
|
||||
if (reasonInput == null) return;
|
||||
final reason = reasonInput.isEmpty ? null : reasonInput;
|
||||
if (!mounted) return;
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
futureWithProgress: (onProgress) async {
|
||||
|
|
@ -1239,6 +1249,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
okLabel: L10n.of(context).unpin,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (response == OkCancelResult.ok) {
|
||||
final events = room.pinnedEventIds
|
||||
..removeWhere((oldEvent) => oldEvent == eventId);
|
||||
|
|
@ -1328,17 +1339,18 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
Future<void> onPhoneButtonTap() async {
|
||||
// VoIP required Android SDK 21
|
||||
if (PlatformInfos.isAndroid) {
|
||||
DeviceInfoPlugin().androidInfo.then((value) {
|
||||
if (value.version.sdkInt < 21) {
|
||||
Navigator.pop(context);
|
||||
showOkAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).unsupportedAndroidVersion,
|
||||
message: L10n.of(context).unsupportedAndroidVersionLong,
|
||||
okLabel: L10n.of(context).close,
|
||||
);
|
||||
}
|
||||
});
|
||||
final androidInfo = await DeviceInfoPlugin().androidInfo;
|
||||
if (!mounted) return;
|
||||
if (androidInfo.version.sdkInt < 21) {
|
||||
Navigator.pop(context);
|
||||
await showOkAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context).unsupportedAndroidVersion,
|
||||
message: L10n.of(context).unsupportedAndroidVersionLong,
|
||||
okLabel: L10n.of(context).close,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final callType = await showModalActionPopup<CallType>(
|
||||
context: context,
|
||||
|
|
@ -1359,11 +1371,13 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
],
|
||||
);
|
||||
if (callType == null) return;
|
||||
if (!mounted) return;
|
||||
|
||||
final voipPlugin = Matrix.of(context).voipPlugin;
|
||||
try {
|
||||
await voipPlugin!.voip.inviteToCall(room, callType);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(e.toLocalizedString(context))));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue