chore: Avoid unnecessary lambdas

This commit is contained in:
Christian Kußowski 2026-02-20 14:19:03 +01:00
commit a0a03941c2
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
13 changed files with 19 additions and 32 deletions

View file

@ -17,6 +17,8 @@ linter:
- unnecessary_statements - unnecessary_statements
- avoid_bool_literals_in_conditional_expressions - avoid_bool_literals_in_conditional_expressions
- prefer_single_quotes - prefer_single_quotes
- prefer_const_declarations
- unnecessary_lambdas
analyzer: analyzer:
plugins: plugins:

View file

@ -155,8 +155,7 @@ class ChatEventList extends StatelessWidget {
highlightMarker: highlightMarker:
controller.scrollToEventIdMarker == event.eventId, controller.scrollToEventIdMarker == event.eventId,
onSelect: controller.onSelectMessage, onSelect: controller.onSelectMessage,
scrollToEventId: (String eventId) => scrollToEventId: controller.scrollToEventId,
controller.scrollToEventId(eventId),
longPressSelect: controller.selectedEvents.isNotEmpty, longPressSelect: controller.selectedEvents.isNotEmpty,
selected: controller.selectedEvents.any( selected: controller.selectedEvents.any(
(e) => e.eventId == event.eventId, (e) => e.eventId == event.eventId,
@ -164,7 +163,7 @@ class ChatEventList extends StatelessWidget {
singleSelected: singleSelected:
controller.selectedEvents.singleOrNull?.eventId == controller.selectedEvents.singleOrNull?.eventId ==
event.eventId, event.eventId,
onEdit: () => controller.editSelectedEventAction(), onEdit: controller.editSelectedEventAction,
timeline: timeline, timeline: timeline,
displayReadMarker: displayReadMarker:
i > 0 && controller.readMarkerEventId == event.eventId, i > 0 && controller.readMarkerEventId == event.eventId,

View file

@ -207,7 +207,7 @@ class MessageContent extends StatelessWidget {
.split(';') .split(';')
.first .first
.split(',') .split(',')
.map((s) => double.tryParse(s)) .map(double.tryParse)
.toList(); .toList();
if (latlong.length == 2 && if (latlong.length == 2 &&
latlong.first != null && latlong.first != null &&

View file

@ -66,7 +66,7 @@ class MessageReactions extends StatelessWidget {
if (evt != null) { if (evt != null) {
showFutureLoadingDialog( showFutureLoadingDialog(
context: context, context: context,
future: () => evt.redactEvent(), future: evt.redactEvent,
); );
} }
} else { } else {

View file

@ -25,7 +25,7 @@ class PollWidget extends StatelessWidget {
}); });
void _endPoll(BuildContext context) => void _endPoll(BuildContext context) =>
showFutureLoadingDialog(context: context, future: () => event.endPoll()); showFutureLoadingDialog(context: context, future: event.endPoll);
void _toggleVote(BuildContext context, String answerId, int maxSelection) { void _toggleVote(BuildContext context, String answerId, int maxSelection) {
final userId = event.room.client.userID!; final userId = event.room.client.userID!;

View file

@ -145,9 +145,7 @@ class RecordingViewModelState extends State<RecordingViewModel> {
} }
void cancel() { void cancel() {
setState(() { setState(_reset);
_reset();
});
} }
void pause() { void pause() {

View file

@ -181,9 +181,7 @@ class ChatAccessSettingsPageView extends StatelessWidget {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
localAddresses.remove(room.canonicalAlias); localAddresses.remove(room.canonicalAlias);
localAddresses.removeWhere( localAddresses.removeWhere(altAliases.contains);
(alias) => altAliases.contains(alias),
);
return Column( return Column(
mainAxisSize: .min, mainAxisSize: .min,
children: localAddresses children: localAddresses

View file

@ -35,7 +35,7 @@ class ChatListViewBody extends StatelessWidget {
key: ValueKey(activeSpace), key: ValueKey(activeSpace),
spaceId: activeSpace, spaceId: activeSpace,
onBack: controller.clearActiveSpace, onBack: controller.clearActiveSpace,
onChatTab: (room) => controller.onChatTap(room), onChatTab: controller.onChatTap,
activeChat: controller.activeChat, activeChat: controller.activeChat,
); );
} }
@ -123,7 +123,7 @@ class ChatListViewBody extends StatelessWidget {
if (!controller.isSearchMode && if (!controller.isSearchMode &&
AppSettings.showPresences.value) AppSettings.showPresences.value)
GestureDetector( GestureDetector(
onLongPress: () => controller.dismissStatusList(), onLongPress: controller.dismissStatusList,
child: StatusMessageList( child: StatusMessageList(
onStatusEdit: controller.setStatus, onStatusEdit: controller.setStatus,
), ),

View file

@ -194,9 +194,7 @@ class MyCallingPage extends State<Calling> {
call.onCallStateChanged.stream.listen(_handleCallState); call.onCallStateChanged.stream.listen(_handleCallState);
call.onCallEventChanged.stream.listen((event) { call.onCallEventChanged.stream.listen((event) {
if (event == CallStateChange.kFeedsChanged) { if (event == CallStateChange.kFeedsChanged) {
setState(() { setState(call.tryRemoveStopedStreams);
call.tryRemoveStopedStreams();
});
} else if (event == CallStateChange.kLocalHoldUnhold || } else if (event == CallStateChange.kLocalHoldUnhold ||
event == CallStateChange.kRemoteHoldUnhold) { event == CallStateChange.kRemoteHoldUnhold) {
setState(() {}); setState(() {});

View file

@ -4,10 +4,10 @@ import 'package:matrix/matrix.dart';
IconData _getIconFromName(String displayname) { IconData _getIconFromName(String displayname) {
final name = displayname.toLowerCase(); final name = displayname.toLowerCase();
if ({'android'}.any((s) => name.contains(s))) { if ({'android'}.any(name.contains)) {
return Icons.phone_android_outlined; return Icons.phone_android_outlined;
} }
if ({'ios', 'ipad', 'iphone', 'ipod'}.any((s) => name.contains(s))) { if ({'ios', 'ipad', 'iphone', 'ipod'}.any(name.contains)) {
return Icons.phone_iphone_outlined; return Icons.phone_iphone_outlined;
} }
if ({ if ({
@ -19,16 +19,10 @@ IconData _getIconFromName(String displayname) {
'/_matrix', '/_matrix',
'safari', 'safari',
'opera', 'opera',
}.any((s) => name.contains(s))) { }.any(name.contains)) {
return Icons.web_outlined; return Icons.web_outlined;
} }
if ({ if ({'desktop', 'windows', 'macos', 'linux', 'ubuntu'}.any(name.contains)) {
'desktop',
'windows',
'macos',
'linux',
'ubuntu',
}.any((s) => name.contains(s))) {
return Icons.desktop_mac_outlined; return Icons.desktop_mac_outlined;
} }
return Icons.device_unknown_outlined; return Icons.device_unknown_outlined;

View file

@ -35,7 +35,7 @@ extension StreamExtension on Stream {
}; };
final subscription = listen( final subscription = listen(
(_) => onMessage?.call(), (_) => onMessage?.call(),
onDone: () => controller.close(), onDone: controller.close,
onError: (e, s) => controller.addError(e, s), onError: (e, s) => controller.addError(e, s),
); );
// add proper cleanup to the subscription and the controller, to not memory leak // add proper cleanup to the subscription and the controller, to not memory leak

View file

@ -105,9 +105,7 @@ extension UiaRequestManager on MatrixState {
launchUrl(url, mode: LaunchMode.inAppBrowserView); launchUrl(url, mode: LaunchMode.inAppBrowserView);
final completer = Completer(); final completer = Completer();
final listener = AppLifecycleListener( final listener = AppLifecycleListener(onResume: completer.complete);
onResume: () => completer.complete(),
);
await completer.future; await completer.future;
listener.dispose(); listener.dispose();

View file

@ -66,7 +66,7 @@ class UrlLauncher {
.split(';') .split(';')
.first .first
.split(',') .split(',')
.map((s) => double.tryParse(s)) .map(double.tryParse)
.toList(); .toList();
if (latlong.length == 2 && if (latlong.length == 2 &&
latlong.first != null && latlong.first != null &&