refactor: Update to Dart 3.10 with . shorthands

This commit is contained in:
Christian Kußowski 2025-11-30 12:54:06 +01:00
commit 1ea649f01e
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
167 changed files with 3351 additions and 3912 deletions

View file

@ -22,8 +22,13 @@ IconData _getIconFromName(String displayname) {
}.any((s) => name.contains(s))) {
return Icons.web_outlined;
}
if ({'desktop', 'windows', 'macos', 'linux', 'ubuntu'}
.any((s) => name.contains(s))) {
if ({
'desktop',
'windows',
'macos',
'linux',
'ubuntu',
}.any((s) => name.contains(s))) {
return Icons.desktop_mac_outlined;
}
return Icons.device_unknown_outlined;

View file

@ -15,8 +15,9 @@ extension LocalizedBody on Event {
showFutureLoadingDialog(
context: context,
futureWithProgress: (onProgress) {
final fileSize =
infoMap['size'] is int ? infoMap['size'] as int : null;
final fileSize = infoMap['size'] is int
? infoMap['size'] as int
: null;
return downloadAndDecryptAttachment(
onDownloadProgress: fileSize == null
? null
@ -47,8 +48,11 @@ extension LocalizedBody on Event {
thumbnailInfoMap['size'] < room.client.database.maxFileSize;
bool get showThumbnail =>
[MessageTypes.Image, MessageTypes.Sticker, MessageTypes.Video]
.contains(messageType) &&
[
MessageTypes.Image,
MessageTypes.Sticker,
MessageTypes.Video,
].contains(messageType) &&
(kIsWeb ||
isAttachmentSmallEnough ||
isThumbnailSmallEnough ||

View file

@ -6,29 +6,28 @@ extension VisibleInGuiExtension on List<Event> {
List<Event> filterByVisibleInGui({
String? exceptionEventId,
String? threadId,
}) =>
where(
(event) {
if (threadId != null &&
event.relationshipType != RelationshipTypes.reaction) {
if ((event.relationshipType != RelationshipTypes.thread ||
event.relationshipEventId != threadId) &&
event.eventId != threadId) {
return false;
}
} else if (event.relationshipType == RelationshipTypes.thread) {
return false;
}
return event.isVisibleInGui || event.eventId == exceptionEventId;
},
).toList();
}) => where((event) {
if (threadId != null &&
event.relationshipType != RelationshipTypes.reaction) {
if ((event.relationshipType != RelationshipTypes.thread ||
event.relationshipEventId != threadId) &&
event.eventId != threadId) {
return false;
}
} else if (event.relationshipType == RelationshipTypes.thread) {
return false;
}
return event.isVisibleInGui || event.eventId == exceptionEventId;
}).toList();
}
extension IsStateExtension on Event {
bool get isVisibleInGui =>
// always filter out edit and reaction relationships
!{RelationshipTypes.edit, RelationshipTypes.reaction}
.contains(relationshipType) &&
!{
RelationshipTypes.edit,
RelationshipTypes.reaction,
}.contains(relationshipType) &&
// always filter out m.key.* and other known but unimportant events
!isKnownHiddenStates &&
// event types to hide: redaction and reaction events
@ -40,22 +39,20 @@ extension IsStateExtension on Event {
(!AppSettings.hideUnknownEvents.value || isEventTypeKnown);
bool get isState => !{
EventTypes.Message,
EventTypes.Sticker,
EventTypes.Encrypted,
}.contains(type);
EventTypes.Message,
EventTypes.Sticker,
EventTypes.Encrypted,
}.contains(type);
bool get isCollapsedState => !{
EventTypes.Message,
EventTypes.Sticker,
EventTypes.Encrypted,
EventTypes.RoomCreate,
EventTypes.RoomTombstone,
}.contains(type);
EventTypes.Message,
EventTypes.Sticker,
EventTypes.Encrypted,
EventTypes.RoomCreate,
EventTypes.RoomTombstone,
}.contains(type);
bool get isKnownHiddenStates =>
{
PollEventContent.responseType,
}.contains(type) ||
{PollEventContent.responseType}.contains(type) ||
type.startsWith('m.key.verification.');
}

View file

@ -28,22 +28,19 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(String clientName) async {
try {
// Send error notification:
final l10n = await lookupL10n(PlatformDispatcher.instance.locale);
ClientManager.sendInitNotification(
l10n.initAppError,
e.toString(),
);
ClientManager.sendInitNotification(l10n.initAppError, e.toString());
} catch (e, s) {
Logs().e('Unable to send error notification', e, s);
}
// Try to delete database so that it can created again on next init:
database?.delete().catchError(
(e, s) => Logs().wtf(
'Unable to delete database, after failed construction',
e,
s,
),
);
(e, s) => Logs().wtf(
'Unable to delete database, after failed construction',
e,
s,
),
);
// Delete database file:
if (!kIsWeb) {
@ -77,8 +74,9 @@ Future<MatrixSdkDatabase> _constructDatabase(String clientName) async {
// fix dlopen for old Android
await applyWorkaroundToOpenSqlCipherOnOldAndroidVersions();
// import the SQLite / SQLCipher shared objects / dynamic libraries
final factory =
createDatabaseFactoryFfi(ffiInit: SQfLiteEncryptionHelper.ffiInit);
final factory = createDatabaseFactoryFfi(
ffiInit: SQfLiteEncryptionHelper.ffiInit,
);
// required for [getDatabasesPath]
databaseFactory = factory;
@ -90,11 +88,7 @@ Future<MatrixSdkDatabase> _constructDatabase(String clientName) async {
// to manage SQLite encryption
final helper = cipher == null
? null
: SQfLiteEncryptionHelper(
factory: factory,
path: path,
cipher: cipher,
);
: SQfLiteEncryptionHelper(factory: factory, path: path, cipher: cipher);
// check whether the DB is already encrypted and otherwise do so
await helper?.ensureDatabaseFileEncrypted();

View file

@ -25,10 +25,7 @@ Future<String?> getDatabaseCipher() async {
final list = Uint8List(32);
list.setAll(0, Iterable.generate(list.length, (i) => rng.nextInt(256)));
final newPassword = base64UrlEncode(list);
await secureStorage.write(
key: _passwordStorageKey,
value: newPassword,
);
await secureStorage.write(key: _passwordStorageKey, value: newPassword);
}
// workaround for if we just wrote to the key and it still doesn't exist
password = await secureStorage.read(key: _passwordStorageKey);

View file

@ -39,8 +39,9 @@ extension MatrixFileExtension on MatrixFile {
await SharePlus.instance.share(
ShareParams(
files: [XFile.fromData(bytes, name: name, mimeType: mimeType)],
sharePositionOrigin:
box == null ? null : box.localToGlobal(Offset.zero) & box.size,
sharePositionOrigin: box == null
? null
: box.localToGlobal(Offset.zero) & box.size,
),
);
return;

View file

@ -353,13 +353,15 @@ class MatrixLocals extends MatrixLocalizations {
String get cancelledSend => l10n.sendCanceled;
@override
String voiceMessage(String senderName, Duration? duration) =>
l10n.sentVoiceMessage(
senderName,
duration == null
? ''
: '${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}',
);
String voiceMessage(
String senderName,
Duration? duration,
) => l10n.sentVoiceMessage(
senderName,
duration == null
? ''
: '${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}',
);
@override
String get refreshingLastEvent => l10n.loadingPleaseWait;