Enable unawaited_futures lint

This commit is contained in:
Ming Ming 2022-07-29 00:59:26 +08:00
parent 724b384fd1
commit 65d4268954
23 changed files with 177 additions and 120 deletions

View file

@ -2,6 +2,7 @@ include: package:flutter_lints/flutter.yaml
linter:
rules:
unawaited_futures: true
depend_on_referenced_packages: false
prefer_interpolation_to_compose_strings: false
no_leading_underscores_for_local_identifiers: false

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
@ -113,12 +115,14 @@ class ListFavoriteBloc
emit(ListFavoriteBlocSuccess(ev.account, remote));
if (cache != null) {
unawaited(
CacheFavorite(_c)(ev.account, remote.map((f) => f.fileId!))
.onError((e, stackTrace) {
_log.shout(
"[_onEventQuery] Failed while CacheFavorite", e, stackTrace);
return -1;
});
}),
);
}
} catch (e, stackTrace) {
_log.severe("[_onEventQuery] Exception while request", e, stackTrace);

View file

@ -122,11 +122,11 @@ class _DownlaodHandlerAndroid extends _DownloadHandlerBase {
duration: k.snackBarDurationNormal,
));
} finally {
itemSubscription?.cancel();
unawaited(itemSubscription?.cancel());
}
}
} finally {
subscription?.cancel();
unawaited(subscription?.cancel());
if (successes.isNotEmpty) {
await _onDownloadSuccessful(successes.map((e) => e.item1).toList(),
successes.map((e) => e.item2).toList(), id);

View file

@ -21,13 +21,15 @@ Future<List<T>> waitOr<T>(
}
for (final p in futures.withIndex()) {
unawaited(
p.item2.then((value) {
results[p.item1] = value;
onResult();
}).onError((error, stackTrace) {
results[p.item1] = onError(error!, stackTrace);
onResult();
});
}),
);
}
return completer.future;
}

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:bloc_concurrency/bloc_concurrency.dart';
import 'package:flutter/material.dart';
@ -13,7 +15,7 @@ void main() async {
if (platform_k.isMobile) {
// reset orientation override just in case, see #59
SystemChrome.setPreferredOrientations([]);
unawaited(SystemChrome.setPreferredOrientations([]));
}
BlocOverrides.runZoned(
() => runApp(const MyApp()),

View file

@ -85,7 +85,8 @@ class _AndroidDownload extends itf.Download {
throw error!;
}
} finally {
fileWrite.close();
await fileWrite.flush();
await fileWrite.close();
}
if (shouldInterrupt) {
throw JobCanceledException();
@ -98,7 +99,7 @@ class _AndroidDownload extends itf.Download {
subDir: parentDir,
);
} finally {
file.delete();
await file.delete();
}
}

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:devicelocale/devicelocale.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
@ -86,8 +88,8 @@ class _Service {
} catch (e, stackTrace) {
_log.shout("[call] Uncaught exception", e, stackTrace);
}
onCancelSubscription.cancel();
onDataSubscription.cancel();
await onCancelSubscription.cancel();
await onDataSubscription.cancel();
await KiwiContainer().resolve<DiContainer>().sqliteDb.close();
service.stopBackgroundService();
_log.info("[call] Service stopped");
@ -228,7 +230,9 @@ class _MetadataTask {
_log.shout("[call] Uncaught exception", e, stackTrace);
}
if (_processedIds.isNotEmpty) {
NativeEvent.fire(FileExifUpdatedEvent(_processedIds).toEvent());
unawaited(
NativeEvent.fire(FileExifUpdatedEvent(_processedIds).toEvent()),
);
_processedIds = [];
}

View file

@ -99,6 +99,7 @@ class ShareHandler {
Future<void> _shareAsFile(Account account, List<File> files) async {
assert(platform_k.isAndroid);
final controller = StreamController<String>();
unawaited(
showDialog(
context: context,
builder: (context) => StreamBuilder(
@ -108,6 +109,7 @@ class ShareHandler {
(snapshot.hasData ? " ${snapshot.data}" : ""),
),
),
),
);
final results = <Tuple2<File, dynamic>>[];
for (final pair in files.withIndex()) {
@ -144,7 +146,7 @@ class ShareHandler {
final share = AndroidFileShare(
results.map((e) => e.item2 as String).toList(),
results.map((e) => e.item1.contentType).toList());
share.share();
return share.share();
}
Future<void> _shareAsLink(
@ -207,7 +209,7 @@ class ShareHandler {
if (platform_k.isAndroid) {
final textShare = AndroidTextShare(share.url!);
textShare.share();
await textShare.share();
}
} catch (e, stackTrace) {
_log.shout(

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
@ -154,9 +156,8 @@ class _AccountPickerDialogState extends State<AccountPickerDialog> {
_log.shout(
"[_removeAccount] Failed while removing account pref", e, stackTrace);
}
Pref()
..setAccounts3(accounts)
..setCurrentAccountIndex(newAccountIndex);
unawaited(Pref().setAccounts3(accounts));
unawaited(Pref().setCurrentAccountIndex(newAccountIndex));
// check if the same account (server + userId) still exists in known
// accounts

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:kiwi/kiwi.dart';
@ -212,7 +214,7 @@ class _AlbumBrowserState extends State<AlbumBrowser>
await _setAlbum(album);
if (album.shares?.isNotEmpty == true) {
_showSharedAlbumInfoDialog();
unawaited(_showSharedAlbumInfoDialog());
}
}

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
@ -237,7 +239,9 @@ mixin AlbumBrowserMixin<T extends StatefulWidget>
stackTrace);
}
if (newAlbum != null && mounted) {
album_browser_util.pushReplacement(context, account, newAlbum!);
unawaited(
album_browser_util.pushReplacement(context, account, newAlbum!),
);
}
}

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@ -215,11 +217,13 @@ class _AlbumImporterState extends State<AlbumImporter> {
}
void _onImportPressed(BuildContext context) async {
unawaited(
showDialog(
barrierDismissible: false,
context: context,
builder: (context) =>
ProcessingDialog(text: L10n.global().albumImporterProgressText),
),
);
try {
await _createAllAlbums(context);

View file

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:math' as math;
import 'package:android_intent_plus/android_intent.dart';
@ -140,7 +141,7 @@ class EnhanceHandler {
],
),
);
Pref().setHasShownEnhanceInfo(true);
unawaited(Pref().setHasShownEnhanceInfo(true));
}
Future<_Algorithm?> _pickAlgorithm(BuildContext context) =>

View file

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
@ -360,8 +361,10 @@ class _HomeAlbumsState extends State<HomeAlbums>
if (album.provider is AlbumDynamicProvider) {
// open the album automatically to refresh its content, otherwise it'll
// be empty
unawaited(
Navigator.of(context).pushNamed(DynamicAlbumBrowser.routeName,
arguments: DynamicAlbumBrowserArguments(widget.account, album));
arguments: DynamicAlbumBrowserArguments(widget.account, album)),
);
}
} catch (e, stacktrace) {
_log.shout("[_onNewAlbumItemTap] Failed", e, stacktrace);

View file

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:collection';
import 'dart:math' as math;
import 'dart:ui';
@ -542,7 +543,7 @@ class _HomePhotosState extends State<HomePhotos>
Future<void> _startupSync() async {
if (!_hasResyncedFavorites.value) {
_hasResyncedFavorites.value = true;
StartupSync.runInIsolate(widget.account);
unawaited(StartupSync.runInIsolate(widget.account));
}
}

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/api.dart';
@ -102,7 +104,7 @@ class _ImageEditorState extends State<ImageEditor> {
Widget _buildContent(BuildContext context) {
return WillPopScope(
onWillPop: () async {
_onBackButton(context);
unawaited(_onBackButton(context));
return false;
},
child: ColoredBox(

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:kiwi/kiwi.dart';
@ -371,7 +373,9 @@ class _SettingsState extends State<Settings> {
_shouldProcessExifWifiOnly = oldValue;
});
} else {
ServiceConfig.setProcessExifWifiOnly(value);
// this is not very important since the config will be synced during
// service startup
ServiceConfig.setProcessExifWifiOnly(value).ignore();
}
}
@ -602,9 +606,9 @@ class _AccountSettingsState extends State<AccountSettingsWidget> {
return;
}
if (result.isEmpty) {
_setLabel(null);
return _setLabel(null);
} else {
_setLabel(result);
return _setLabel(result);
}
}
@ -872,7 +876,8 @@ class _ViewerSettingsState extends State<_ViewerSettings> {
);
}
void _onScreenBrightnessChanged(BuildContext context, bool value) async {
Future<void> _onScreenBrightnessChanged(
BuildContext context, bool value) async {
if (value) {
var brightness = 0.5;
try {
@ -932,13 +937,13 @@ class _ViewerSettingsState extends State<_ViewerSettings> {
);
if (value != null) {
_setScreenBrightness(value);
unawaited(_setScreenBrightness(value));
}
} finally {
ScreenBrightness().resetScreenBrightness();
unawaited(ScreenBrightness().resetScreenBrightness());
}
} else {
_setScreenBrightness(-1);
unawaited(_setScreenBrightness(-1));
}
}
@ -1187,7 +1192,7 @@ class _EnhancementSettingsState extends State<EnhancementSettings> {
return;
}
_setMaxResolution(width, height);
unawaited(_setMaxResolution(width, height));
}
Future<void> _setMaxResolution(int width, int height) async {

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
@ -282,9 +284,11 @@ class _SignInState extends State<SignIn> {
});
try {
await _persistAccount(account);
unawaited(
Navigator.pushNamedAndRemoveUntil(
context, Home.routeName, (route) => false,
arguments: HomeArguments(account));
arguments: HomeArguments(account)),
);
} catch (_) {
setState(() {
_isConnecting = false;
@ -307,9 +311,8 @@ class _SignInState extends State<SignIn> {
_log.shout("[_connect] Failed reading pref for account: $account", e,
stackTrace);
}
Pref()
..setAccounts3(accounts)
..setCurrentAccountIndex(accounts.indexOf(account));
unawaited(Pref().setAccounts3(accounts));
unawaited(Pref().setCurrentAccountIndex(accounts.indexOf(account)));
}
final _formKey = GlobalKey<FormState>();

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:logging/logging.dart';
@ -253,7 +255,7 @@ class _SlideshowViewerState extends State<SlideshowViewer>
}
_setupSlideTransition(newPage);
SystemChrome.restoreSystemUIOverlays();
unawaited(SystemChrome.restoreSystemUIOverlays());
}
void _setupSlideTransition(int index) {

View file

@ -50,7 +50,7 @@ class _SplashState extends State<Splash> {
_isUpgrading = false;
});
}
_exit();
unawaited(_exit());
}
@override
@ -115,16 +115,18 @@ class _SplashState extends State<Splash> {
_log.info("[_exit]");
final account = Pref().getCurrentAccount();
if (isNeedSetup()) {
Navigator.pushReplacementNamed(context, Setup.routeName);
unawaited(Navigator.pushReplacementNamed(context, Setup.routeName));
} else if (account == null) {
Navigator.pushReplacementNamed(context, SignIn.routeName);
unawaited(Navigator.pushReplacementNamed(context, SignIn.routeName));
} else {
unawaited(
Navigator.pushReplacementNamed(context, Home.routeName,
arguments: HomeArguments(account));
arguments: HomeArguments(account)),
);
if (platform_k.isAndroid) {
final initialRoute = await Activity.consumeInitialRoute();
if (initialRoute != null) {
Navigator.pushNamed(context, initialRoute);
unawaited(Navigator.pushNamed(context, initialRoute));
}
}
}
@ -138,7 +140,7 @@ class _SplashState extends State<Splash> {
Future<void> _handleUpgrade() async {
try {
final lastVersion = Pref().getLastVersionOr(k.version);
_showChangelogIfAvailable(lastVersion);
unawaited(_showChangelogIfAvailable(lastVersion));
// begin upgrade while showing the changelog
try {
_log.info("[_handleUpgrade] Upgrade: $lastVersion -> ${k.version}");
@ -181,9 +183,8 @@ class _SplashState extends State<Splash> {
await CompatV46.insertDbAccounts(Pref(), c.sqliteDb);
} catch (e, stackTrace) {
_log.shout("[_upgrade46] Failed while clearDefaultCache", e, stackTrace);
Pref()
..setAccounts3(null)
..setCurrentAccountIndex(null);
unawaited(Pref().setAccounts3(null));
unawaited(Pref().setCurrentAccountIndex(null));
await showDialog(
context: context,
builder: (context) => AlertDialog(

View file

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
@ -267,6 +268,7 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
}
void _onEmptyTrashPressed(BuildContext context) async {
unawaited(
showDialog(
context: context,
builder: (_) => AlertDialog(
@ -282,6 +284,7 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
),
],
),
),
);
}
@ -326,11 +329,13 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
}
Future<void> _onSelectionAppBarDeletePressed(BuildContext context) async {
unawaited(
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text(L10n.global().deletePermanentlyConfirmationDialogTitle),
content: Text(L10n.global().deletePermanentlyConfirmationDialogContent),
content:
Text(L10n.global().deletePermanentlyConfirmationDialogContent),
actions: [
TextButton(
onPressed: () {
@ -341,6 +346,7 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
),
],
),
),
);
}

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:kiwi/kiwi.dart';
import 'package:logging/logging.dart';
@ -188,11 +190,13 @@ class _TrashbinViewerState extends State<TrashbinViewer> {
Future<void> _onDeletePressed(BuildContext context) async {
final file = widget.streamFiles[_viewerController.currentPage];
_log.info("[_onDeletePressed] Deleting file permanently: ${file.path}");
unawaited(
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text(L10n.global().deletePermanentlyConfirmationDialogTitle),
content: Text(L10n.global().deletePermanentlyConfirmationDialogContent),
content:
Text(L10n.global().deletePermanentlyConfirmationDialogContent),
actions: [
TextButton(
onPressed: () {
@ -203,6 +207,7 @@ class _TrashbinViewerState extends State<TrashbinViewer> {
),
],
),
),
);
}

View file

@ -638,14 +638,15 @@ class _ViewerState extends State<Viewer>
if (result == null) {
return;
}
Pref()
..setSlideshowDuration(result.duration.inSeconds)
..setSlideshowShuffle(result.isShuffle)
..setSlideshowRepeat(result.isRepeat);
unawaited(Pref().setSlideshowDuration(result.duration.inSeconds));
unawaited(Pref().setSlideshowShuffle(result.isShuffle));
unawaited(Pref().setSlideshowRepeat(result.isRepeat));
unawaited(
Navigator.of(context).pushNamed(
SlideshowViewer.routeName,
arguments: SlideshowViewerArguments(widget.account, widget.streamFiles,
_viewerController.currentPage, result),
),
);
}