Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unawaited futures (lint) #995

Merged
merged 19 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ linter:
require_trailing_commas: false
depend_on_referenced_packages: false

unawaited_futures: false
unawaited_futures: true
use_build_context_synchronously: false
use_setters_to_change_properties: false
avoid_equals_and_hash_code_on_mutable_classes: false
Expand Down
2 changes: 1 addition & 1 deletion flutterw
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
##
## Flutter start up script for UN*X
## Version: v1.3.1
## Date: 2022-12-22 21:01:55
## Date: 2023-02-08 20:22:59
##
## Use this flutter wrapper to bundle Flutter within your project to make
## sure everybody builds with the same version.
Expand Down
2 changes: 1 addition & 1 deletion lib/common/components/password_input_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _PasswordInputDialogState extends State<PasswordInputDialog> {
});
}
if (res == null) {
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
final dic = I18n.of(context)!.translationsForLocale();
Expand Down
2 changes: 1 addition & 1 deletion lib/mocks/substrate_api/mock_assets_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MockAssetsApi extends AssetsApi {
@override
Future<void> fetchBalance() async {
Log.d('api: fetching mock balance', 'MockAssetsApi');
store.assets.setAccountBalances(
await store.assets.setAccountBalances(
store.account.currentAccountPubKey,
Map.of({store.settings.networkState!.tokenSymbol: balancesInfo}),
needCache: false,
Expand Down
6 changes: 4 additions & 2 deletions lib/page-encointer/ceremony_box/ceremony_box.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
Expand Down Expand Up @@ -195,13 +197,13 @@ Widget getMeetupInfoWidget(BuildContext context, AppStore store) {
}

Future<void> awaitDataUpdateWithDialog(BuildContext context, AppStore store) async {
showCupertinoDialog<void>(
unawaited(showCupertinoDialog<void>(
context: context,
builder: (_) => CupertinoAlertDialog(
title: Text(I18n.of(context)!.translationsForLocale().home.updatingAppState),
content: const CupertinoActivityIndicator(),
),
);
));

await store.dataUpdate.executeUpdate().whenComplete(() => Navigator.of(context).pop());
}
2 changes: 1 addition & 1 deletion lib/page-encointer/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _EncointerHomePageState extends State<EncointerHomePage> {
onTap: (index) async {
if (_tabList[index].key == TabKey.scan) {
// Push `ScanPage.Route`instead of changing the Page.
Navigator.of(context).pushNamed(
await Navigator.of(context).pushNamed(
ScanPage.route,
arguments: ScanPageParams(scannerContext: QrScannerContext.mainPage),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/page-encointer/meetup/ceremony_step1_count.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CeremonyStep1Count extends StatelessWidget {

Future<void> _pushStep2ScanPage(BuildContext context, int count) async {
store.encointer.communityAccount!.setParticipantCountVote(count);
Navigator.of(context).push(
await Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) => CeremonyStep2Scan(
store,
Expand Down
5 changes: 2 additions & 3 deletions lib/page/account/create/add_account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
setState(() {
_submitting = false;
});
_showErrorCreatingAccountDialog(context);
return;
return _showErrorCreatingAccountDialog(context);
}

final addresses = await webApi.account.encodeAddress([acc['pubKey'] as String]);
Expand All @@ -77,7 +76,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
}

static Future<void> _showErrorCreatingAccountDialog(BuildContext context) async {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
7 changes: 3 additions & 4 deletions lib/page/account/create/create_account_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ class CreateAccountForm extends StatelessWidget {
final acc = await webApi.account.importAccount();

if (acc['error'] != null) {
_showErrorCreatingAccountDialog(context);
return;
return _showErrorCreatingAccountDialog(context);
}

final addresses = await webApi.account.encodeAddress([acc['pubKey'] as String]);
await store.addAccount(acc, store.account.newAccount.password, addresses[0]);

final pubKey = acc['pubKey'] as String?;
store.setCurrentAccount(pubKey);
await store.setCurrentAccount(pubKey);

await store.loadAccountCache();

Expand Down Expand Up @@ -121,7 +120,7 @@ class CreateAccountForm extends StatelessWidget {
}

Future<void> _showErrorCreatingAccountDialog(BuildContext context) async {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
2 changes: 1 addition & 1 deletion lib/page/account/create/create_pin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _CreatePinPageState extends State<CreatePinPage> {
});

// Even if we do not choose a community, we go back to the home screen.
Navigator.pushAndRemoveUntil<void>(
await Navigator.pushAndRemoveUntil<void>(
context,
CupertinoPageRoute<void>(builder: (context) => const EncointerHomePage()),
(route) => false,
Expand Down
15 changes: 8 additions & 7 deletions lib/page/account/import/import_account_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -38,15 +40,15 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
setState(() {
_submitting = true;
});
showCupertinoDialog<void>(
unawaited(showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text(I18n.of(context)!.translationsForLocale().home.loading),
content: const SizedBox(height: 64, child: CupertinoActivityIndicator()),
);
},
);
));

/// import account
final acc = await webApi.account.importAccount(
Expand All @@ -64,7 +66,7 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
msg = '${I18n.of(context)!.translationsForLocale().account.importInvalid}: $_keyType';
}

showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand All @@ -85,7 +87,6 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
);
},
);
return;
}
await _checkAccountDuplicate(acc);
return;
Expand All @@ -98,7 +99,7 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
context.read<AppStore>().account.pubKeyAddressMap[context.read<AppStore>().settings.endpoint.ss58]!;
final address = pubKeyMap[acc['pubKey']];
if (address != null) {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down Expand Up @@ -169,11 +170,11 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
});

if (context.read<AppStore>().account.isFirstAccount) {
Navigator.pushNamed(context, CreatePinPage.route, arguments: CreatePinPageParams(_importAccount));
await Navigator.pushNamed(context, CreatePinPage.route, arguments: CreatePinPageParams(_importAccount));
} else {
context.read<AppStore>().account.setNewAccountPin(context.read<AppStore>().settings.cachedPin);
await _importAccount();
Navigator.pushAndRemoveUntil<void>(
await Navigator.pushAndRemoveUntil<void>(
context,
CupertinoPageRoute<void>(builder: (context) => const EncointerHomePage()),
(route) => false,
Expand Down
2 changes: 1 addition & 1 deletion lib/page/assets/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class _AssetsState extends State<Assets> {

Future<void> switchAccount(AccountData account) async {
if (account.pubKey != widget.store.account.currentAccountPubKey) {
widget.store.setCurrentAccount(account.pubKey);
await widget.store.setCurrentAccount(account.pubKey);
await widget.store.loadAccountCache();

webApi.fetchAccountData();
Expand Down
2 changes: 1 addition & 1 deletion lib/page/assets/receive/receive_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _ReceivePageState extends State<ReceivePage> {
}
}

webApi.encointer.getAllBalances(store.account.currentAddress).then((balances) {
await webApi.encointer.getAllBalances(store.account.currentAddress).then((balances) {
final cid = store.encointer.chosenCid;

if (cid == null) {
Expand Down
10 changes: 6 additions & 4 deletions lib/page/network_select_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
Expand Down Expand Up @@ -43,15 +45,15 @@ class _NetworkSelectPageState extends State<NetworkSelectPage> {
setState(() {
_networkChanging = true;
});
showCupertinoDialog<void>(
unawaited(showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text(I18n.of(context)!.translationsForLocale().home.loading),
content: const SizedBox(height: 64, child: CupertinoActivityIndicator()),
);
},
);
));

await context.read<AppStore>().settings.reloadNetwork(_selectedNetwork);

Expand All @@ -69,7 +71,7 @@ class _NetworkSelectPageState extends State<NetworkSelectPage> {
final isCurrentNetwork = _selectedNetwork.info == context.read<AppStore>().settings.endpoint.info;
if (address != context.read<AppStore>().account.currentAddress || !isCurrentNetwork) {
/// set current account
context.read<AppStore>().setCurrentAccount(i.pubKey);
await context.read<AppStore>().setCurrentAccount(i.pubKey);

if (isCurrentNetwork) {
await context.read<AppStore>().loadAccountCache();
Expand All @@ -88,7 +90,7 @@ class _NetworkSelectPageState extends State<NetworkSelectPage> {
if (!isCurrentNetwork) {
await _reloadNetwork();
}
Navigator.of(context).pushNamed(CreateAccountEntryPage.route);
await Navigator.of(context).pushNamed(CreateAccountEntryPage.route);
}

Future<void> _showPasswordDialog(BuildContext context) async {
Expand Down
4 changes: 2 additions & 2 deletions lib/page/profile/account/account_manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ class _AccountManagePageState extends State<AccountManagePage> {
final seed =
await _appStore.account.decryptSeed(accountToBeEdited.pubKey, AccountStore.seedTypeMnemonic, password);

Navigator.of(context).pushNamed(ExportResultPage.route, arguments: {
await Navigator.of(context).pushNamed(ExportResultPage.route, arguments: {
'key': seed,
'type': AccountStore.seedTypeMnemonic,
});
} else {
// Assume that the account was imported via `RawSeed` if mnemonic does not exist.
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
4 changes: 2 additions & 2 deletions lib/page/profile/account/change_password_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _ChangePassword extends State<ChangePasswordPage> {
passOld,
);
if (passChecked == null) {
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down Expand Up @@ -86,7 +86,7 @@ class _ChangePassword extends State<ChangePasswordPage> {
store.account.updateSeed(accountData.pubKey, _passOldCtrl.text, _passCtrl.text);
});
}
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
4 changes: 2 additions & 2 deletions lib/page/profile/account/export_account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ExportAccountPage extends StatelessWidget {
_passCtrl.text,
);
if (res == null) {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand All @@ -49,7 +49,7 @@ class ExportAccountPage extends StatelessWidget {
Navigator.of(context).pop();
final seed =
await store.account.decryptSeed(store.account.currentAccount.pubKey, seedType, _passCtrl.text.trim());
Navigator.of(context).pushNamed(ExportResultPage.route, arguments: {
await Navigator.of(context).pushNamed(ExportResultPage.route, arguments: {
'key': seed!,
'type': seedType,
});
Expand Down
6 changes: 3 additions & 3 deletions lib/page/profile/contacts/contact_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,17 @@ class EndorseButton extends StatelessWidget {
final bootstrappers = community?.bootstrappers;
final dic = I18n.of(context)!.translationsForLocale();
if (bootstrappers != null && bootstrappers.contains(contact.address)) {
_popupDialog(context, dic.profile.cantEndorseBootstrapper);
await _popupDialog(context, dic.profile.cantEndorseBootstrapper);
} else if (store.encointer.currentPhase != CeremonyPhase.Registering) {
_popupDialog(context, dic.profile.canEndorseInRegisteringPhaseOnly);
await _popupDialog(context, dic.profile.canEndorseInRegisteringPhaseOnly);
} else {
await submitEndorseNewcomer(context, store, api, store.encointer.chosenCid, contact.address);
}
}
}

Future<void> _popupDialog(BuildContext context, String content) async {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
11 changes: 5 additions & 6 deletions lib/page/profile/contacts/contact_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _Contact extends State<ContactPage> {
// create new contact
final exist = context.read<AppStore>().settings.contactList.indexWhere((i) => i.address == addr);
if (exist > -1) {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand All @@ -71,23 +71,22 @@ class _Contact extends State<ContactPage> {
);
},
);
return;
} else {
context.read<AppStore>().settings.addContact(con);
await context.read<AppStore>().settings.addContact(con);
}
} else {
// edit contact
context.read<AppStore>().settings.updateContact(con);
await context.read<AppStore>().settings.updateContact(con);
}

// get contact info
if (_isObservation!) {
webApi.account.encodeAddress([pubKey]);
await webApi.account.encodeAddress([pubKey]);
} else {
// if this address was used as observation and current account,
// we need to change current account
if (pubKey == context.read<AppStore>().account.currentAccountPubKey) {
webApi.account.changeCurrentAccount(fetchData: true);
await webApi.account.changeCurrentAccount(fetchData: true);
}
}
Navigator.of(context).pop();
Expand Down
2 changes: 1 addition & 1 deletion lib/page/profile/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Future<void> showRemoveAccountsDialog(BuildContext context, AppStore store) {
await store.account.removeAccount(acc);
}

Navigator.pushAndRemoveUntil(
await Navigator.pushAndRemoveUntil(
context,
CupertinoPageRoute<void>(builder: (context) => const CreateAccountEntryPage()),
(route) => false,
Expand Down
2 changes: 1 addition & 1 deletion lib/page/profile/settings/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _Settings extends State<SettingsPage> {
onWillPop: () async {
final code = _langOptions[_selected];
if (code != context.read<AppStore>().settings.localeCode) {
context.read<AppStore>().settings.setLocalCode(code);
await context.read<AppStore>().settings.setLocalCode(code);
context.read<AppStore>().settings.changeLang(context, code);
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/page/reap_voucher/dialogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Future<ChangeResult> changeWithLoadingDialog(
BuildContext context,
Future<ChangeResult> Function() changeFn,
) async {
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
Loading