Add lint rule to warn for unawaited futures

This commit is contained in:
Neeraj Gupta 2022-11-06 15:46:14 +05:30
parent 46fe951e0d
commit 943c5edfb6
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
13 changed files with 47 additions and 29 deletions

View file

@ -32,6 +32,7 @@ linter:
- directives_ordering
- always_use_package_imports
- sort_child_properties_last
- unawaited_futures
analyzer:
errors:
@ -59,6 +60,8 @@ analyzer:
unnecessary_const: error
cancel_subscriptions: error
unawaited_futures: info # convert to warning after fixing existing issues
invalid_dependency: info
use_build_context_synchronously: ignore # experimental lint, requires many changes
prefer_interpolation_to_compose_strings: ignore # later too many warnings

View file

@ -537,7 +537,7 @@ class Configuration {
Future<void> setBackupOverMobileData(bool value) async {
await _preferences.setBool(keyShouldBackupOverMobileData, value);
if (value) {
SyncService.instance.sync();
SyncService.instance.sync().ignore();
}
}
@ -562,7 +562,7 @@ class Configuration {
Future<void> setShouldBackupVideos(bool value) async {
await _preferences.setBool(keyShouldBackupVideos, value);
if (value) {
SyncService.instance.sync();
SyncService.instance.sync().ignore();
} else {
SyncService.instance.onVideoBackupPaused();
}

View file

@ -188,7 +188,9 @@ Future _runWithLogs(Function() function, {String prefix = ""}) async {
}
Future<void> _scheduleHeartBeat(
SharedPreferences prefs, bool isBackground) async {
SharedPreferences prefs,
bool isBackground,
) async {
await prefs.setInt(
isBackground ? kLastBGTaskHeartBeatTime : kLastFGTaskHeartBeatTime,
DateTime.now().microsecondsSinceEpoch,

View file

@ -30,13 +30,13 @@ class UserRemoteFlagService {
bool shouldShowRecoveryVerification() {
if (!_prefs.containsKey(needRecoveryKeyVerification)) {
// fetch the status from remote
unawaited(_refreshRecoveryVerificationFlag());
_refreshRecoveryVerificationFlag().ignore();
return false;
} else {
final bool shouldShow = _prefs.getBool(needRecoveryKeyVerification)!;
if (shouldShow) {
// refresh the status to check if user marked it as done on another device
unawaited(_refreshRecoveryVerificationFlag());
_refreshRecoveryVerificationFlag().ignore();
}
return shouldShow;
}

View file

@ -531,7 +531,7 @@ class UserService {
);
} catch (e) {
await dialog.hide();
showErrorDialog(
await showErrorDialog(
context,
"Incorrect recovery key",
"The recovery key you entered is incorrect",

View file

@ -1,5 +1,7 @@
// @dart=2.9
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart';
@ -128,13 +130,15 @@ class _PasswordReentryPageState extends State<PasswordReentryPage> {
}
await dialog.hide();
Bus.instance.fire(SubscriptionPurchasedEvent());
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (BuildContext context) {
return const HomeWidget();
},
unawaited(
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (BuildContext context) {
return const HomeWidget();
},
),
(route) => false,
),
(route) => false,
);
},
),

View file

@ -116,7 +116,7 @@ class _TrashButtonWidgetState extends State<TrashButtonWidget> {
),
),
),
onPressed: () async {
onPressed: () {
routeToPage(
context,
TrashPage(),

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:photos/services/local_sync_service.dart';
@ -17,10 +19,12 @@ class PreserveFooterWidget extends StatelessWidget {
if (LocalSyncService.instance.hasGrantedLimitedPermissions()) {
await PhotoManager.presentLimited();
} else {
routeToPage(
context,
const BackupFolderSelectionPage(
buttonText: "Preserve",
unawaited(
routeToPage(
context,
const BackupFolderSelectionPage(
buttonText: "Preserve",
),
),
);
}

View file

@ -117,7 +117,7 @@ class AboutMenuItemWidget extends StatelessWidget {
pressedColor: getEnteColorScheme(context).fillFaint,
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
onTap: () async {
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {

View file

@ -1,5 +1,7 @@
// @dart=2.9
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_sodium/flutter_sodium.dart';
import 'package:photos/services/local_authentication_service.dart';
@ -49,16 +51,18 @@ class AccountSectionWidget extends StatelessWidget {
try {
recoveryKey = await _getOrCreateRecoveryKey(context);
} catch (e) {
showGenericErrorDialog(context);
await showGenericErrorDialog(context);
return;
}
routeToPage(
context,
RecoveryKeyPage(
recoveryKey,
"OK",
showAppBar: true,
onDone: () {},
unawaited(
routeToPage(
context,
RecoveryKeyPage(
recoveryKey,
"OK",
showAppBar: true,
onDone: () {},
),
),
);
}

View file

@ -91,7 +91,7 @@ class DangerSectionWidget extends StatelessWidget {
],
);
showDialog(
await showDialog(
context: context,
builder: (BuildContext context) {
return alert;

View file

@ -265,7 +265,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
],
);
showDialog(
await showDialog(
context: context,
builder: (BuildContext context) {
return alert;

View file

@ -162,7 +162,8 @@ Future<void> _downloadAndDecryptThumbnail(FileDownloadItem item) async {
if (cachedThumbnail.existsSync()) {
await cachedThumbnail.delete();
}
cachedThumbnail.writeAsBytes(data);
// data is already cached in-memory, no need to await on dist write
unawaited(cachedThumbnail.writeAsBytes(data));
if (_map.containsKey(file.uploadedFileID)) {
try {
item.completer.complete(data);