From f998c9577edafe867d90e4f7cf3d74d95d12f505 Mon Sep 17 00:00:00 2001 From: Brett Morgan Date: Wed, 27 Apr 2022 09:24:19 +1000 Subject: [PATCH] Add `unawaited_futures` (#1148) --- .../flutter_module_using_plugin/lib/main.dart | 2 +- .../multiple_flutters_module/lib/main.dart | 2 +- .../flutter_module_using_plugin/lib/main.dart | 2 +- analysis_options.yaml | 1 + .../fluent_ui/lib/src/unsplash/unsplash.dart | 5 +++-- .../material/lib/src/unsplash/unsplash.dart | 5 +++-- .../linting_tool/lib/model/profiles_store.dart | 2 +- .../linting_tool/lib/pages/saved_lints_page.dart | 2 +- .../linting_tool/lib/repository/hive_service.dart | 8 ++++---- .../lib/widgets/lint_expansion_tile.dart | 4 ++-- .../lib/src/screens/navigator.dart | 2 +- .../lib/simple_animations_package.dart | 14 +++++++------- 12 files changed, 26 insertions(+), 23 deletions(-) diff --git a/add_to_app/android_view/flutter_module_using_plugin/lib/main.dart b/add_to_app/android_view/flutter_module_using_plugin/lib/main.dart index ff9cca454..15bfd5e82 100644 --- a/add_to_app/android_view/flutter_module_using_plugin/lib/main.dart +++ b/add_to_app/android_view/flutter_module_using_plugin/lib/main.dart @@ -167,7 +167,7 @@ class Contents extends StatelessWidget { // a browser. final url = Uri.parse('https://flutter.dev/docs'); if (await launcher.canLaunchUrl(url)) { - launcher.launchUrl(url); + await launcher.launchUrl(url); } }, child: const Text('Open Flutter Docs'), diff --git a/add_to_app/multiple_flutters/multiple_flutters_module/lib/main.dart b/add_to_app/multiple_flutters/multiple_flutters_module/lib/main.dart index 235f10932..237cb11c1 100644 --- a/add_to_app/multiple_flutters/multiple_flutters_module/lib/main.dart +++ b/add_to_app/multiple_flutters/multiple_flutters_module/lib/main.dart @@ -97,7 +97,7 @@ class _MyHomePageState extends State { // a browser. final url = Uri.parse('https://flutter.dev/docs'); if (await launcher.canLaunchUrl(url)) { - launcher.launchUrl(url); + await launcher.launchUrl(url); } }, child: const Text('Open Flutter Docs'), diff --git a/add_to_app/plugin/flutter_module_using_plugin/lib/main.dart b/add_to_app/plugin/flutter_module_using_plugin/lib/main.dart index 8a162ec0a..57a47a700 100644 --- a/add_to_app/plugin/flutter_module_using_plugin/lib/main.dart +++ b/add_to_app/plugin/flutter_module_using_plugin/lib/main.dart @@ -166,7 +166,7 @@ class Contents extends StatelessWidget { // a browser. final url = Uri.parse('https://flutter.dev/docs'); if (await launcher.canLaunchUrl(url)) { - launcher.launchUrl(url); + await launcher.launchUrl(url); } }, child: const Text('Open Flutter Docs'), diff --git a/analysis_options.yaml b/analysis_options.yaml index 85f6fbe91..daef00116 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -16,4 +16,5 @@ linter: package_prefixed_library_names: true test_types_in_equals: true throw_in_finally: true + unawaited_futures: true unnecessary_statements: true diff --git a/desktop_photo_search/fluent_ui/lib/src/unsplash/unsplash.dart b/desktop_photo_search/fluent_ui/lib/src/unsplash/unsplash.dart index 5de769812..df486e93e 100644 --- a/desktop_photo_search/fluent_ui/lib/src/unsplash/unsplash.dart +++ b/desktop_photo_search/fluent_ui/lib/src/unsplash/unsplash.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; import 'dart:convert'; import 'dart:typed_data'; @@ -86,10 +87,10 @@ class Unsplash { }); _log.info('GET ${photo.links!.downloadLocation}'); - http.get(Uri.parse(photo.links!.downloadLocation!), headers: { + unawaited(http.get(Uri.parse(photo.links!.downloadLocation!), headers: { 'Accept-Version': 'v1', 'Authorization': 'Client-ID $_accessKey', - }); + })); return futureBytes; } diff --git a/desktop_photo_search/material/lib/src/unsplash/unsplash.dart b/desktop_photo_search/material/lib/src/unsplash/unsplash.dart index 5de769812..df486e93e 100644 --- a/desktop_photo_search/material/lib/src/unsplash/unsplash.dart +++ b/desktop_photo_search/material/lib/src/unsplash/unsplash.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; import 'dart:convert'; import 'dart:typed_data'; @@ -86,10 +87,10 @@ class Unsplash { }); _log.info('GET ${photo.links!.downloadLocation}'); - http.get(Uri.parse(photo.links!.downloadLocation!), headers: { + unawaited(http.get(Uri.parse(photo.links!.downloadLocation!), headers: { 'Accept-Version': 'v1', 'Authorization': 'Client-ID $_accessKey', - }); + })); return futureBytes; } diff --git a/experimental/linting_tool/lib/model/profiles_store.dart b/experimental/linting_tool/lib/model/profiles_store.dart index f20eb0c42..5526a584f 100644 --- a/experimental/linting_tool/lib/model/profiles_store.dart +++ b/experimental/linting_tool/lib/model/profiles_store.dart @@ -144,7 +144,7 @@ class ProfilesStore extends ChangeNotifier { /// Save file to disk if path was provided. if (savePath != null) { - file.saveTo(savePath); + await file.saveTo(savePath); return true; } diff --git a/experimental/linting_tool/lib/pages/saved_lints_page.dart b/experimental/linting_tool/lib/pages/saved_lints_page.dart index 8bde62442..42da7781d 100644 --- a/experimental/linting_tool/lib/pages/saved_lints_page.dart +++ b/experimental/linting_tool/lib/pages/saved_lints_page.dart @@ -104,7 +104,7 @@ class SavedLintsPage extends StatelessWidget { break; case 'Delete': - profilesStore.deleteProfile(profile); + await profilesStore.deleteProfile(profile); break; default: } diff --git a/experimental/linting_tool/lib/repository/hive_service.dart b/experimental/linting_tool/lib/repository/hive_service.dart index 0708f389c..f46dcf791 100644 --- a/experimental/linting_tool/lib/repository/hive_service.dart +++ b/experimental/linting_tool/lib/repository/hive_service.dart @@ -13,7 +13,7 @@ class HiveService { List existingProducts = await getBoxes(boxName); if (!existingProducts.contains(item)) { - openBox.add(item); + await openBox.add(item); return true; } return false; @@ -28,7 +28,7 @@ class HiveService { for (var item in items) { if (!existingProducts.contains(item)) { - openBox.add(item); + await openBox.add(item); } } } @@ -42,7 +42,7 @@ class HiveService { for (var box in boxes) { if (box == item) { - openBox.deleteAt(boxes.indexOf(item)); + await openBox.deleteAt(boxes.indexOf(item)); } } } @@ -56,7 +56,7 @@ class HiveService { for (var box in boxes) { if (box == item) { - openBox.putAt(boxes.indexOf(item), newItem); + await openBox.putAt(boxes.indexOf(item), newItem); } } } diff --git a/experimental/linting_tool/lib/widgets/lint_expansion_tile.dart b/experimental/linting_tool/lib/widgets/lint_expansion_tile.dart index 29b0f826a..647a717d0 100644 --- a/experimental/linting_tool/lib/widgets/lint_expansion_tile.dart +++ b/experimental/linting_tool/lib/widgets/lint_expansion_tile.dart @@ -139,7 +139,7 @@ class _LintExpansionTileState extends State { }, ); if (destinationProfileType == ProfileType.newProfile) { - showDialog( + await showDialog( context: context, builder: (context) { return _NewProfileDialog(rule: rule); @@ -147,7 +147,7 @@ class _LintExpansionTileState extends State { ); } else if (destinationProfileType == ProfileType.existingProfile) { - showDialog( + await showDialog( context: context, builder: (context) { return _ExistingProfileDialog(rule: rule); diff --git a/navigation_and_routing/lib/src/screens/navigator.dart b/navigation_and_routing/lib/src/screens/navigator.dart index f2dffbdd0..863361da5 100644 --- a/navigation_and_routing/lib/src/screens/navigator.dart +++ b/navigation_and_routing/lib/src/screens/navigator.dart @@ -79,7 +79,7 @@ class _BookstoreNavigatorState extends State { var signedIn = await authState.signIn( credentials.username, credentials.password); if (signedIn) { - routeState.go('/books/popular'); + await routeState.go('/books/popular'); } }, ), diff --git a/web/particle_background/lib/simple_animations_package.dart b/web/particle_background/lib/simple_animations_package.dart index 7dc6c8437..7f2b5efdb 100644 --- a/web/particle_background/lib/simple_animations_package.dart +++ b/web/particle_background/lib/simple_animations_package.dart @@ -372,7 +372,7 @@ class _ControlledAnimationState extends State await Future.delayed(widget.delay!); } _waitForDelay = false; - executeInstruction(); + await executeInstruction(); } @override @@ -391,23 +391,23 @@ class _ControlledAnimationState extends State _controller.stop(); } if (widget.playback == Playback.PLAY_FORWARD) { - _controller.forward(); + await _controller.forward(); } if (widget.playback == Playback.PLAY_REVERSE) { - _controller.reverse(); + await _controller.reverse(); } if (widget.playback == Playback.START_OVER_FORWARD) { - _controller.forward(from: 0.0); + await _controller.forward(from: 0.0); } if (widget.playback == Playback.START_OVER_REVERSE) { - _controller.reverse(from: 1.0); + await _controller.reverse(from: 1.0); } if (widget.playback == Playback.LOOP) { - _controller.repeat(); + await _controller.repeat(); } if (widget.playback == Playback.MIRROR && !_isCurrentlyMirroring) { _isCurrentlyMirroring = true; - _controller.repeat(reverse: true); + await _controller.repeat(reverse: true); } if (widget.playback != Playback.MIRROR) {