refactor: Avoid unnecessary bool comparison

This commit is contained in:
Christian Kußowski 2026-02-19 08:53:18 +01:00
parent d08364688e
commit 1cd3a91037
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
15 changed files with 26 additions and 25 deletions

View file

@ -24,3 +24,7 @@ dart_code_linter:
rules:
- avoid-dynamic
- avoid-redundant-async
- avoid-unnecessary-type-assertions
- avoid-unnecessary-type-casts
- avoid-unrelated-type-assertions
- no-boolean-literal-compare

View file

@ -161,8 +161,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
Widget body = const Center(child: CircularProgressIndicator.adaptive());
titleText = L10n.of(context).loadingPleaseWait;
if (bootstrap.newSsssKey?.recoveryKey != null &&
_recoveryKeyStored == false) {
if (bootstrap.newSsssKey?.recoveryKey != null && _recoveryKeyStored) {
final key = bootstrap.newSsssKey!.recoveryKey;
titleText = L10n.of(context).recoveryKey;
return LoginScaffold(

View file

@ -249,9 +249,9 @@ class ChatController extends State<ChatPageWithRoom>
}
if (!scrollController.hasClients) return;
if (timeline?.allowNewEvent == false ||
scrollController.position.pixels > 0 && _scrolledUp == false) {
scrollController.position.pixels > 0 && _scrolledUp) {
setState(() => _scrolledUp = true);
} else if (scrollController.position.pixels <= 0 && _scrolledUp == true) {
} else if (scrollController.position.pixels <= 0 && _scrolledUp) {
setState(() => _scrolledUp = false);
setReadMarker();
}
@ -919,7 +919,7 @@ class ChatController extends State<ChatPageWithRoom>
final clients = Matrix.of(context).currentBundle;
for (final event in selectedEvents) {
if (!event.status.isSent) return false;
if (event.canRedact == false &&
if (event.canRedact &&
!(clients!.any((cl) => event.senderId == cl!.userID))) {
return false;
}

View file

@ -317,7 +317,7 @@ class ChatInputRow extends StatelessWidget {
autofocus: !PlatformInfos.isMobile,
keyboardType: TextInputType.multiline,
textInputAction:
AppSettings.sendOnEnter.value == true &&
AppSettings.sendOnEnter.value &&
PlatformInfos.isMobile
? TextInputAction.send
: null,

View file

@ -364,7 +364,7 @@ class ChatView extends StatelessWidget {
? theme.colorScheme.tertiaryContainer
: theme.colorScheme.surfaceContainerHigh,
borderRadius: BorderRadius.circular(32),
child: controller.room.isAbandonedDMRoom == true
child: controller.room.isAbandonedDMRoom
? Row(
mainAxisAlignment: .spaceEvenly,
children: [

View file

@ -179,7 +179,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
matrixFile.mimeType.toLowerCase() == 'audio/ogg') {
Logs().v('Convert ogg audio file for iOS...');
final convertedFile = File('${file.path}.caf');
if (await convertedFile.exists() == false) {
if (await convertedFile.exists()) {
OpusCaf().convertOpusToCaf(file.path, convertedFile.path);
}
file = convertedFile;

View file

@ -55,7 +55,7 @@ class RecordingViewModelState extends State<RecordingViewModel> {
return;
}
}
if (await AudioRecorder().hasPermission() == false) return;
if (await AudioRecorder().hasPermission()) return;
final audioRecorder = _audioRecorder ??= AudioRecorder();
setState(() {});
@ -76,7 +76,7 @@ class RecordingViewModelState extends State<RecordingViewModel> {
}
final result = await audioRecorder.hasPermission();
if (result != true) {
if (!result) {
showOkAlertDialog(
context: context,
title: L10n.of(context).oopsSomethingWentWrong,

View file

@ -320,7 +320,7 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
try {
await room.client.setRoomVisibilityOnDirectory(
room.id,
visibility: visibility == true ? Visibility.public : Visibility.private,
visibility: visibility ? Visibility.public : Visibility.private,
);
setState(() {});
} catch (e, s) {

View file

@ -168,9 +168,8 @@ class ChatListController extends State<ChatList>
initialText: searchServer,
keyboardType: TextInputType.url,
autocorrect: false,
validator: (server) => server.contains('.') == true
? null
: L10n.of(context).invalidServerName,
validator: (server) =>
server.contains('.') ? null : L10n.of(context).invalidServerName,
);
if (newServer == null) return;
Matrix.of(context).store.setString(_serverStoreNamespace, newServer);
@ -203,10 +202,9 @@ class ChatListController extends State<ChatList>
if (searchQuery.isValidMatrixId &&
searchQuery.sigil == '#' &&
roomSearchResult.chunk.any(
!roomSearchResult.chunk.any(
(room) => room.canonicalAlias == searchQuery,
) ==
false) {
)) {
final response = await client.getRoomIdByAlias(searchQuery);
final roomId = response.roomId;
if (roomId != null) {

View file

@ -314,7 +314,7 @@ extension on CachedPresence {
? DateTime.now()
: DateTime.fromMillisecondsSinceEpoch(0));
LinearGradient get gradient => presence.isOnline == true
LinearGradient get gradient => presence.isOnline
? LinearGradient(
colors: [Colors.green, Colors.green.shade200, Colors.green.shade900],
begin: Alignment.topLeft,

View file

@ -110,7 +110,7 @@ class ImageViewerController extends State<ImageViewer> {
/// Go back if user swiped it away
void onInteractionEnds(ScaleEndDetails endDetails) {
if (PlatformInfos.usesTouchscreen == false) {
if (!PlatformInfos.usesTouchscreen) {
if (endDetails.velocity.pixelsPerSecond.dy >
MediaQuery.sizeOf(context).height * maxScaleFactor) {
Navigator.of(context, rootNavigator: false).pop();

View file

@ -73,7 +73,7 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last,
);
final file = File('${tempDir.path}/${fileName}_${videoFile.name}');
if (await file.exists() == false) {
if (!await file.exists()) {
await file.writeAsBytes(videoFile.bytes);
}
videoPlayerController = VideoPlayerController.file(file);

View file

@ -172,7 +172,7 @@ class SettingsController extends State<Settings> {
final needsBootstrap =
await client.encryption?.keyManager.isCached() == false ||
client.encryption?.crossSigning.enabled == false ||
crossSigning == false;
!crossSigning;
final isUnknownSession = client.isUnknownSession;
setState(() {
showChatBackupBanner = needsBootstrap || isUnknownSession;

View file

@ -50,7 +50,7 @@ Future<String?> getDatabaseCipher() async {
void _sendNoEncryptionWarning(Object exception) async {
final isStored = AppSettings.noEncryptionWarningShown.value;
if (isStored == true) return;
if (isStored) return;
final l10n = await lookupL10n(PlatformDispatcher.instance.locale);
ClientManager.sendInitNotification(

View file

@ -117,7 +117,7 @@ class VoipPlugin with WidgetsBindingObserver implements WebRTCDelegate {
await matrix.store.setString(
'wasForeground',
wasForeground == true ? 'true' : 'false',
wasForeground ? 'true' : 'false',
);
FlutterForegroundTask.setOnLockScreenVisibility(true);
FlutterForegroundTask.wakeUpScreen();