From 807bb298886a38971e59d9fcec86509fbafb4771 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Fri, 5 Mar 2021 18:29:04 -0800 Subject: [PATCH] enable prefer_function_declarations_over_variables lint (#77398) --- analysis_options.yaml | 2 +- .../macrobenchmarks/test/frame_policy.dart | 5 +- .../module_host_with_custom_build_test.dart | 4 +- dev/devicelab/test/adb_test.dart | 4 -- .../gen_cupertino_localizations.dart | 8 +-- .../gen_material_localizations.dart | 8 +-- .../flutter/lib/src/cupertino/nav_bar.dart | 12 ++-- .../lib/src/foundation/assertions.dart | 8 ++- .../animated_icons/animated_icons.dart | 2 +- .../lib/src/material/range_slider.dart | 6 +- .../lib/src/painting/image_provider.dart | 4 +- .../src/rendering/list_wheel_viewport.dart | 8 +-- packages/flutter/lib/src/widgets/heroes.dart | 4 +- .../flutter/lib/src/widgets/navigator.dart | 6 +- .../flutter/lib/src/widgets/restoration.dart | 4 +- .../animation/iteration_patterns_test.dart | 36 ++++++------ .../test/animation/listener_helpers_test.dart | 4 +- .../flutter/test/cupertino/colors_test.dart | 2 +- .../flutter/test/cupertino/refresh_test.dart | 8 +-- .../cupertino/text_form_field_row_test.dart | 2 +- .../flutter/test/cupertino/theme_test.dart | 4 +- .../test/foundation/change_notifier_test.dart | 38 ++++++------- .../test/foundation/diagnostics_test.dart | 14 ++--- .../material/dropdown_form_field_test.dart | 2 +- .../flutter/test/material/dropdown_test.dart | 2 +- .../flutter/test/material/feedback_test.dart | 8 +-- .../test/material/input_decorator_test.dart | 4 +- .../test/material/popup_menu_test.dart | 4 +- .../test/material/range_slider_test.dart | 4 +- .../flutter/test/material/stepper_test.dart | 43 +++++++------- .../test/material/text_field_test.dart | 6 +- .../test/material/text_form_field_test.dart | 2 +- .../test/painting/image_cache_test.dart | 4 +- .../image_provider_and_image_cache_test.dart | 5 +- .../image_provider_network_image_test.dart | 4 +- .../image_provider_resize_image_test.dart | 5 +- .../test/painting/image_stream_test.dart | 32 +++++------ .../proxy_getters_and_setters_test.dart | 8 +-- .../flutter/test/rendering/stack_test.dart | 4 +- .../test/semantics/semantics_test.dart | 24 ++++---- .../test/services/channel_buffers_test.dart | 4 +- .../test/services/platform_views_test.dart | 2 +- .../test/widgets/animated_list_test.dart | 4 +- .../test/widgets/app_navigator_key_test.dart | 2 +- .../test/widgets/autocomplete_test.dart | 2 +- .../test/widgets/fade_in_image_test.dart | 8 +-- .../gesture_detector_semantics_test.dart | 4 +- .../test/widgets/gesture_detector_test.dart | 2 +- .../flutter/test/widgets/heroes_test.dart | 4 +- packages/flutter/test/widgets/image_test.dart | 56 +++++++++---------- .../test/widgets/list_view_builder_test.dart | 12 ++-- .../widgets/list_view_viewporting_test.dart | 20 +++---- .../widgets/list_wheel_scroll_view_test.dart | 2 +- .../test/widgets/mouse_region_test.dart | 8 +-- .../test/widgets/platform_view_test.dart | 16 +++--- .../flutter_driver/lib/src/common/error.dart | 6 +- .../test/src/real_tests/extension_test.dart | 2 +- .../lib/src/frame_timing_summarizer.dart | 3 +- .../lib/src/isolated/devfs_web.dart | 5 +- .../lib/src/localizations/gen_l10n.dart | 4 +- .../lib/src/runner/flutter_command.dart | 5 +- .../commands.shard/hermetic/doctor_test.dart | 2 +- .../commands.shard/permeable/create_test.dart | 2 +- .../application_package_test.dart | 2 +- .../test/general.shard/ios/mac_test.dart | 2 +- .../macos/application_package_test.dart | 3 +- .../test/general.shard/version_test.dart | 4 +- packages/flutter_tools/test/src/mocks.dart | 4 +- .../test/navigation/url_strategy_test.dart | 2 +- .../lib/src/common/logging.dart | 4 +- 70 files changed, 274 insertions(+), 276 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 05b4cf1b51..107c3084ff 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -159,7 +159,7 @@ linter: - prefer_final_locals - prefer_for_elements_to_map_fromIterable - prefer_foreach - # - prefer_function_declarations_over_variables # not yet tested + - prefer_function_declarations_over_variables - prefer_generic_function_type_aliases - prefer_if_elements_to_conditional_expressions - prefer_if_null_operators diff --git a/dev/benchmarks/macrobenchmarks/test/frame_policy.dart b/dev/benchmarks/macrobenchmarks/test/frame_policy.dart index d238f58536..c2b4b430ae 100644 --- a/dev/benchmarks/macrobenchmarks/test/frame_policy.dart +++ b/dev/benchmarks/macrobenchmarks/test/frame_policy.dart @@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/gestures.dart'; -import 'package:flutter/scheduler.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; @@ -21,9 +20,9 @@ void main() { await tester.pumpAndSettle(); final Offset location = tester.getCenter(find.byType(ListView)); int frameCount = 0; - final FrameCallback frameCounter = (Duration elapsed) { + void frameCounter(Duration elapsed) { frameCount += 1; - }; + } tester.binding.addPersistentFrameCallback(frameCounter); const int timeInSecond = 1; diff --git a/dev/devicelab/bin/tasks/module_host_with_custom_build_test.dart b/dev/devicelab/bin/tasks/module_host_with_custom_build_test.dart index f26abcf42c..6bc9489186 100644 --- a/dev/devicelab/bin/tasks/module_host_with_custom_build_test.dart +++ b/dev/devicelab/bin/tasks/module_host_with_custom_build_test.dart @@ -77,7 +77,7 @@ Future main() async { Directory(path.join(hostAppDir.path, 'gradle', 'wrapper')), ); - final Function clean = () async { + Future clean() async { section('Clean'); await inDirectory(hostAppDir, () async { await exec(gradlewExecutable, @@ -87,7 +87,7 @@ Future main() async { }, ); }); - }; + } if (!Platform.isWindows) { section('Make $gradlewExecutable executable'); diff --git a/dev/devicelab/test/adb_test.dart b/dev/devicelab/test/adb_test.dart index 81c13984d4..7947e97558 100644 --- a/dev/devicelab/test/adb_test.dart +++ b/dev/devicelab/test/adb_test.dart @@ -179,7 +179,6 @@ class FakeDevice extends AndroidDevice { FakeDevice({String deviceId}) : super(deviceId: deviceId); static String output = ''; - static ExitErrorFactory exitErrorFactory = () => null; static List commandLog = []; @@ -222,8 +221,5 @@ class FakeDevice extends AndroidDevice { arguments: arguments, environment: environment, )); - final dynamic exitError = exitErrorFactory(); - if (exitError != null) - throw exitError; } } diff --git a/dev/tools/localization/gen_cupertino_localizations.dart b/dev/tools/localization/gen_cupertino_localizations.dart index 8e281096f2..f93b012354 100644 --- a/dev/tools/localization/gen_cupertino_localizations.dart +++ b/dev/tools/localization/gen_cupertino_localizations.dart @@ -4,7 +4,7 @@ import 'localizations_utils.dart'; -HeaderGenerator generateCupertinoHeader = (String regenerateInstructions) { +String generateCupertinoHeader(String regenerateInstructions) { return ''' // Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -27,11 +27,11 @@ import '../cupertino_localizations.dart'; // These classes are constructed by the [getCupertinoTranslation] method at the // bottom of this file, and used by the [_GlobalCupertinoLocalizationsDelegate.load] // method defined in `flutter_localizations/lib/src/cupertino_localizations.dart`.'''; -}; +} /// Returns the source of the constructor for a GlobalCupertinoLocalizations /// subclass. -ConstructorGenerator generateCupertinoConstructor = (LocaleInfo locale) { +String generateCupertinoConstructor(LocaleInfo locale) { final String localeName = locale.originalString; return ''' /// Create an instance of the translation bundle for ${describeLocale(localeName)}. @@ -58,7 +58,7 @@ ConstructorGenerator generateCupertinoConstructor = (LocaleInfo locale) { singleDigitSecondFormat: singleDigitSecondFormat, decimalFormat: decimalFormat, );'''; -}; +} const String cupertinoFactoryName = 'getCupertinoTranslation'; diff --git a/dev/tools/localization/gen_material_localizations.dart b/dev/tools/localization/gen_material_localizations.dart index 3e2a0cbb23..31170cc1b2 100644 --- a/dev/tools/localization/gen_material_localizations.dart +++ b/dev/tools/localization/gen_material_localizations.dart @@ -4,7 +4,7 @@ import 'localizations_utils.dart'; -HeaderGenerator generateMaterialHeader = (String regenerateInstructions) { +String generateMaterialHeader(String regenerateInstructions) { return ''' // Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -27,11 +27,11 @@ import '../material_localizations.dart'; // These classes are constructed by the [getMaterialTranslation] method at the // bottom of this file, and used by the [_MaterialLocalizationsDelegate.load] // method defined in `flutter_localizations/lib/src/material_localizations.dart`.'''; -}; +} /// Returns the source of the constructor for a GlobalMaterialLocalizations /// subclass. -ConstructorGenerator generateMaterialConstructor = (LocaleInfo locale) { +String generateMaterialConstructor(LocaleInfo locale) { final String localeName = locale.originalString; return ''' /// Create an instance of the translation bundle for ${describeLocale(localeName)}. @@ -60,7 +60,7 @@ ConstructorGenerator generateMaterialConstructor = (LocaleInfo locale) { decimalFormat: decimalFormat, twoDigitZeroPaddedFormat: twoDigitZeroPaddedFormat, );'''; -}; +} const String materialFactoryName = 'getMaterialTranslation'; diff --git a/packages/flutter/lib/src/cupertino/nav_bar.dart b/packages/flutter/lib/src/cupertino/nav_bar.dart index 6f214cfb28..58266cd6a7 100644 --- a/packages/flutter/lib/src/cupertino/nav_bar.dart +++ b/packages/flutter/lib/src/cupertino/nav_bar.dart @@ -2223,7 +2223,7 @@ class _NavigationBarComponentsTransition { /// Navigation bars' hero rect tween that will move between the static bars /// but keep a constant size that's the bigger of both navigation bars. -CreateRectTween _linearTranslateWithLargestRectSizeTween = (Rect? begin, Rect? end) { +RectTween _linearTranslateWithLargestRectSizeTween(Rect? begin, Rect? end) { final Size largestSize = Size( math.max(begin!.size.width, end!.size.width), math.max(begin.size.height, end.size.height), @@ -2232,9 +2232,9 @@ CreateRectTween _linearTranslateWithLargestRectSizeTween = (Rect? begin, Rect? e begin: begin.topLeft & largestSize, end: end.topLeft & largestSize, ); -}; +} -final HeroPlaceholderBuilder _navBarHeroLaunchPadBuilder = ( +Widget _navBarHeroLaunchPadBuilder( BuildContext context, Size heroSize, Widget child, @@ -2258,10 +2258,10 @@ final HeroPlaceholderBuilder _navBarHeroLaunchPadBuilder = ( visible: false, child: child, ); -}; +} /// Navigation bars' hero flight shuttle builder. -final HeroFlightShuttleBuilder _navBarHeroFlightShuttleBuilder = ( +Widget _navBarHeroFlightShuttleBuilder( BuildContext flightContext, Animation animation, HeroFlightDirection flightDirection, @@ -2310,4 +2310,4 @@ final HeroFlightShuttleBuilder _navBarHeroFlightShuttleBuilder = ( topNavBar: fromNavBar, ); } -}; +} diff --git a/packages/flutter/lib/src/foundation/assertions.dart b/packages/flutter/lib/src/foundation/assertions.dart index 819ec3b090..f10da582ee 100644 --- a/packages/flutter/lib/src/foundation/assertions.dart +++ b/packages/flutter/lib/src/foundation/assertions.dart @@ -876,7 +876,9 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti /// /// Do not call [onError] directly, instead, call [reportError], which /// forwards to [onError] if it is not null. - static FlutterExceptionHandler? onError = (FlutterErrorDetails details) => presentError(details); + static FlutterExceptionHandler? onError = _defaultErrorHandler; + + static void _defaultErrorHandler(FlutterErrorDetails details) => presentError(details); /// Called by the Flutter framework before attempting to parse a [StackTrace]. /// @@ -901,7 +903,9 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti /// return stack; /// }; /// ``` - static StackTraceDemangler demangleStackTrace = (StackTrace stackTrace) => stackTrace; + static StackTraceDemangler demangleStackTrace = _defaultStackTraceDemangler; + + static StackTrace _defaultStackTraceDemangler(StackTrace stackTrace) => stackTrace; /// Called whenever the Flutter framework wants to present an error to the /// users. diff --git a/packages/flutter/lib/src/material/animated_icons/animated_icons.dart b/packages/flutter/lib/src/material/animated_icons/animated_icons.dart index be4c10cf86..08dfe2b70e 100644 --- a/packages/flutter/lib/src/material/animated_icons/animated_icons.dart +++ b/packages/flutter/lib/src/material/animated_icons/animated_icons.dart @@ -99,7 +99,7 @@ class AnimatedIcon extends StatelessWidget { /// horizontally (e.g back arrow will point right). final TextDirection? textDirection; - static final _UiPathFactory _pathFactory = () => ui.Path(); + static ui.Path _pathFactory() => ui.Path(); @override Widget build(BuildContext context) { diff --git a/packages/flutter/lib/src/material/range_slider.dart b/packages/flutter/lib/src/material/range_slider.dart index 54581c1ae3..5e6a96d17f 100644 --- a/packages/flutter/lib/src/material/range_slider.dart +++ b/packages/flutter/lib/src/material/range_slider.dart @@ -524,7 +524,7 @@ class _RangeSliderState extends State with TickerProviderStateMixin // immediately selected while the drag displacement is zero. If the first // non-zero displacement is negative, then the left thumb is selected, and if its // positive, then the right thumb is selected. - static final RangeThumbSelector _defaultRangeThumbSelector = ( + Thumb? _defaultRangeThumbSelector( TextDirection textDirection, RangeValues values, double tapValue, @@ -566,9 +566,7 @@ class _RangeSliderState extends State with TickerProviderStateMixin return Thumb.end; } return null; - }; - - + } @override Widget build(BuildContext context) { diff --git a/packages/flutter/lib/src/painting/image_provider.dart b/packages/flutter/lib/src/painting/image_provider.dart index 8425b9cb36..f9ca3234b2 100644 --- a/packages/flutter/lib/src/painting/image_provider.dart +++ b/packages/flutter/lib/src/painting/image_provider.dart @@ -758,14 +758,14 @@ class ResizeImage extends ImageProvider<_SizeAwareCacheKey> { @override ImageStreamCompleter load(_SizeAwareCacheKey key, DecoderCallback decode) { - final DecoderCallback decodeResize = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { + Future decodeResize(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { assert( cacheWidth == null && cacheHeight == null && allowUpscaling == null, 'ResizeImage cannot be composed with another ImageProvider that applies ' 'cacheWidth, cacheHeight, or allowUpscaling.' ); return decode(bytes, cacheWidth: width, cacheHeight: height, allowUpscaling: this.allowUpscaling); - }; + } final ImageStreamCompleter completer = imageProvider.load(key.providerCacheKey, decodeResize); if (!kReleaseMode) { completer.debugLabel = '${completer.debugLabel} - Resized(${key.width}×${key.height})'; diff --git a/packages/flutter/lib/src/rendering/list_wheel_viewport.dart b/packages/flutter/lib/src/rendering/list_wheel_viewport.dart index ce96eb4f76..ceac77450c 100644 --- a/packages/flutter/lib/src/rendering/list_wheel_viewport.dart +++ b/packages/flutter/lib/src/rendering/list_wheel_viewport.dart @@ -945,18 +945,18 @@ class RenderListWheelViewport Offset offsetToCenter, ) { // Paint child cylindrically, without [overAndUnderCenterOpacity]. - final PaintingContextCallback painter = (PaintingContext context, Offset offset) { + void painter(PaintingContext context, Offset offset) { context.paintChild( child, // Paint everything in the center (e.g. angle = 0), then transform. offset + offsetToCenter, ); - }; + } // Paint child cylindrically, with [overAndUnderCenterOpacity]. - final PaintingContextCallback opacityPainter = (PaintingContext context, Offset offset) { + void opacityPainter(PaintingContext context, Offset offset) { context.pushOpacity(offset, (overAndUnderCenterOpacity * 255).round(), painter); - }; + } context.pushTransform( needsCompositing, diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index f97459b598..a7f4739f0e 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -1031,7 +1031,7 @@ class HeroController extends NavigatorObserver { _flights.remove(flight.manifest.tag); } - static final HeroFlightShuttleBuilder _defaultHeroFlightShuttleBuilder = ( + Widget _defaultHeroFlightShuttleBuilder( BuildContext flightContext, Animation animation, HeroFlightDirection flightDirection, @@ -1040,7 +1040,7 @@ class HeroController extends NavigatorObserver { ) { final Hero toHero = toHeroContext.widget as Hero; return toHero.child; - }; + } } /// Enables or disables [Hero]es in the widget subtree. diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index 0400f847a2..e6e4eb09cb 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -3171,9 +3171,9 @@ class _RouteEntry extends RouteTransitionRecord { ); } - static final _RouteEntryPredicate isPresentPredicate = (_RouteEntry entry) => entry.isPresent; - static final _RouteEntryPredicate suitableForTransitionAnimationPredicate = (_RouteEntry entry) => entry.suitableForTransitionAnimation; - static final _RouteEntryPredicate willBePresentPredicate = (_RouteEntry entry) => entry.willBePresent; + static bool isPresentPredicate(_RouteEntry entry) => entry.isPresent; + static bool suitableForTransitionAnimationPredicate(_RouteEntry entry) => entry.suitableForTransitionAnimation; + static bool willBePresentPredicate(_RouteEntry entry) => entry.willBePresent; static _RouteEntryPredicate isRoutePredicate(Route route) { return (_RouteEntry entry) => entry.route == route; diff --git a/packages/flutter/lib/src/widgets/restoration.dart b/packages/flutter/lib/src/widgets/restoration.dart index 834c12d77d..9b04f4a68a 100644 --- a/packages/flutter/lib/src/widgets/restoration.dart +++ b/packages/flutter/lib/src/widgets/restoration.dart @@ -849,11 +849,11 @@ mixin RestorationMixin on State { if (!property.isRegistered) { property._register(restorationId, this); - final VoidCallback listener = () { + void listener() { if (bucket == null) return; _updateProperty(property); - }; + } property.addListener(listener); _properties[property] = listener; } diff --git a/packages/flutter/test/animation/iteration_patterns_test.dart b/packages/flutter/test/animation/iteration_patterns_test.dart index dab8726c3a..3131ec579c 100644 --- a/packages/flutter/test/animation/iteration_patterns_test.dart +++ b/packages/flutter/test/animation/iteration_patterns_test.dart @@ -18,15 +18,15 @@ void main() { ); final List log = []; - final VoidCallback listener1 = () { log.add('listener1'); }; - final VoidCallback listener3 = () { log.add('listener3'); }; - final VoidCallback listener4 = () { log.add('listener4'); }; - final VoidCallback listener2 = () { + void listener1() { log.add('listener1'); } + void listener3() { log.add('listener3'); } + void listener4() { log.add('listener4'); } + void listener2() { log.add('listener2'); controller.removeListener(listener1); controller.removeListener(listener3); controller.addListener(listener4); - }; + } controller.addListener(listener1); controller.addListener(listener2); @@ -51,15 +51,15 @@ void main() { ); final List log = []; - final AnimationStatusListener listener1 = (AnimationStatus status) { log.add('listener1'); }; - final AnimationStatusListener listener3 = (AnimationStatus status) { log.add('listener3'); }; - final AnimationStatusListener listener4 = (AnimationStatus status) { log.add('listener4'); }; - final AnimationStatusListener listener2 = (AnimationStatus status) { + void listener1(AnimationStatus status) { log.add('listener1'); } + void listener3(AnimationStatus status) { log.add('listener3'); } + void listener4(AnimationStatus status) { log.add('listener4'); } + void listener2(AnimationStatus status) { log.add('listener2'); controller.removeStatusListener(listener1); controller.removeStatusListener(listener3); controller.addStatusListener(listener4); - }; + } controller.addStatusListener(listener1); controller.addStatusListener(listener2); @@ -86,12 +86,12 @@ void main() { ); final List log = []; - final VoidCallback listener1 = () { log.add('listener1'); }; - final VoidCallback badListener = () { + void listener1() { log.add('listener1'); } + void badListener() { log.add('badListener'); throw ArgumentError(); - }; - final VoidCallback listener2 = () { log.add('listener2'); }; + } + void listener2() { log.add('listener2'); } controller.addListener(listener1); controller.addListener(badListener); @@ -109,12 +109,12 @@ void main() { ); final List log = []; - final AnimationStatusListener listener1 = (AnimationStatus status) { log.add('listener1'); }; - final AnimationStatusListener badListener = (AnimationStatus status) { + void listener1(AnimationStatus status) { log.add('listener1'); } + void badListener(AnimationStatus status) { log.add('badListener'); throw ArgumentError(); - }; - final AnimationStatusListener listener2 = (AnimationStatus status) { log.add('listener2'); }; + } + void listener2(AnimationStatus status) { log.add('listener2'); } controller.addStatusListener(listener1); controller.addStatusListener(badListener); diff --git a/packages/flutter/test/animation/listener_helpers_test.dart b/packages/flutter/test/animation/listener_helpers_test.dart index fd2042fe72..81cdcf25cc 100644 --- a/packages/flutter/test/animation/listener_helpers_test.dart +++ b/packages/flutter/test/animation/listener_helpers_test.dart @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; void main() { test('AnimationLocalStatusListenersMixin with AnimationLazyListenerMixin - removing unregistered listener is no-op', () { final _TestAnimationLocalStatusListeners uut = _TestAnimationLocalStatusListeners(); - final AnimationStatusListener fakeListener = (AnimationStatus status) { }; + void fakeListener(AnimationStatus status) { } uut.removeStatusListener(fakeListener); expect(uut.callsToStart, 0); expect(uut.callsToStop, 0); @@ -16,7 +16,7 @@ void main() { test('AnimationLocalListenersMixin with AnimationLazyListenerMixin - removing unregistered listener is no-op', () { final _TestAnimationLocalListeners uut = _TestAnimationLocalListeners(); - final VoidCallback fakeListener = () { }; + void fakeListener() { } uut.removeListener(fakeListener); expect(uut.callsToStart, 0); expect(uut.callsToStop, 0); diff --git a/packages/flutter/test/cupertino/colors_test.dart b/packages/flutter/test/cupertino/colors_test.dart index 937f956794..b719bc619b 100644 --- a/packages/flutter/test/cupertino/colors_test.dart +++ b/packages/flutter/test/cupertino/colors_test.dart @@ -496,7 +496,7 @@ void main() { setUp(() { color = null; }); testWidgets('dynamic color works in cupertino override theme', (WidgetTester tester) async { - final CupertinoDynamicColor Function() typedColor = () => color! as CupertinoDynamicColor; + CupertinoDynamicColor typedColor() => color! as CupertinoDynamicColor; await tester.pumpWidget( MaterialApp( diff --git a/packages/flutter/test/cupertino/refresh_test.dart b/packages/flutter/test/cupertino/refresh_test.dart index 4d8339a4b0..abe0e84b49 100644 --- a/packages/flutter/test/cupertino/refresh_test.dart +++ b/packages/flutter/test/cupertino/refresh_test.dart @@ -31,7 +31,7 @@ void main() { ); } - final VoidCallback uiTestGroup = () { + void uiTestGroup() { testWidgets("doesn't invoke anything without user interaction", (WidgetTester tester) async { await tester.pumpWidget( Directionality( @@ -956,9 +956,9 @@ void main() { initialFirstCellY + 50 ); }, variant: const TargetPlatformVariant({ TargetPlatform.iOS, TargetPlatform.macOS })); - }; + } - final VoidCallback stateMachineTestGroup = () { + void stateMachineTestGroup() { testWidgets('starts in inactive state', (WidgetTester tester) async { await tester.pumpWidget( Directionality( @@ -1345,7 +1345,7 @@ void main() { ); expect(tester.widget(find.byType(CupertinoActivityIndicator)).progress, 100.0 / 100.0); }); - }; + } group('UI tests long list', uiTestGroup); diff --git a/packages/flutter/test/cupertino/text_form_field_row_test.dart b/packages/flutter/test/cupertino/text_form_field_row_test.dart index fc53024dda..03fbd7fff1 100644 --- a/packages/flutter/test/cupertino/text_form_field_row_test.dart +++ b/packages/flutter/test/cupertino/text_form_field_row_test.dart @@ -93,7 +93,7 @@ void main() { testWidgets('Passes onEditingComplete to underlying CupertinoTextField', (WidgetTester tester) async { - final VoidCallback onEditingComplete = () {}; + void onEditingComplete() {} await tester.pumpWidget( CupertinoApp( diff --git a/packages/flutter/test/cupertino/theme_test.dart b/packages/flutter/test/cupertino/theme_test.dart index 4569d6b922..db2d503e88 100644 --- a/packages/flutter/test/cupertino/theme_test.dart +++ b/packages/flutter/test/cupertino/theme_test.dart @@ -217,7 +217,7 @@ void main() { } } - final VoidCallback dynamicColorsTestGroup = () { + void dynamicColorsTestGroup() { testWidgets('CupertinoTheme.of resolves colors', (WidgetTester tester) async { final CupertinoThemeData data = CupertinoThemeData(brightness: currentBrightness, primaryColor: CupertinoColors.systemRed); final CupertinoThemeData theme = await testTheme(tester, data); @@ -249,7 +249,7 @@ void main() { colorMatches(theme.textTheme.pickerTextStyle.color, CupertinoColors.label); colorMatches(theme.textTheme.dateTimePickerTextStyle.color, CupertinoColors.label); }); - }; + } currentBrightness = Brightness.light; group('light colors', dynamicColorsTestGroup); diff --git a/packages/flutter/test/foundation/change_notifier_test.dart b/packages/flutter/test/foundation/change_notifier_test.dart index 1ec3c64e35..eb19e4f785 100644 --- a/packages/flutter/test/foundation/change_notifier_test.dart +++ b/packages/flutter/test/foundation/change_notifier_test.dart @@ -34,13 +34,13 @@ class B extends A with ChangeNotifier { void main() { testWidgets('ChangeNotifier', (WidgetTester tester) async { final List log = []; - final VoidCallback listener = () { log.add('listener'); }; - final VoidCallback listener1 = () { log.add('listener1'); }; - final VoidCallback listener2 = () { log.add('listener2'); }; - final VoidCallback badListener = () { + void listener() { log.add('listener'); } + void listener1() { log.add('listener1'); } + void listener2() { log.add('listener2'); } + void badListener() { log.add('badListener'); throw ArgumentError(); - }; + } final TestNotifier test = TestNotifier(); @@ -111,15 +111,15 @@ void main() { final TestNotifier test = TestNotifier(); final List log = []; - final VoidCallback listener1 = () { log.add('listener1'); }; - final VoidCallback listener3 = () { log.add('listener3'); }; - final VoidCallback listener4 = () { log.add('listener4'); }; - final VoidCallback listener2 = () { + void listener1() { log.add('listener1'); } + void listener3() { log.add('listener3'); } + void listener4() { log.add('listener4'); } + void listener2() { log.add('listener2'); test.removeListener(listener1); test.removeListener(listener3); test.addListener(listener4); - }; + } test.addListener(listener1); test.addListener(listener2); @@ -141,8 +141,8 @@ void main() { final TestNotifier source = TestNotifier(); final List log = []; - final VoidCallback listener3 = () { log.add('listener3'); }; - final VoidCallback listener2 = () { log.add('listener2'); }; + void listener3() { log.add('listener3'); } + void listener2() { log.add('listener2'); } void listener1() { log.add('listener1'); source.addListener(listener2); @@ -167,7 +167,7 @@ void main() { log.add('selfRemovingListener'); source.removeListener(selfRemovingListener); } - final VoidCallback listener1 = () { log.add('listener1'); }; + void listener1() { log.add('listener1'); } source.addListener(listener1); source.addListener(selfRemovingListener); @@ -205,8 +205,8 @@ void main() { final List log = []; final Listenable merged = Listenable.merge([source1, source2]); - final VoidCallback listener1 = () { log.add('listener1'); }; - final VoidCallback listener2 = () { log.add('listener2'); }; + void listener1() { log.add('listener1'); } + void listener2() { log.add('listener2'); } merged.addListener(listener1); source1.notify(); @@ -237,7 +237,7 @@ void main() { final List log = []; final Listenable merged = Listenable.merge([null, source1, null, source2, null]); - final VoidCallback listener = () { log.add('listener'); }; + void listener() { log.add('listener'); } merged.addListener(listener); source1.notify(); @@ -252,7 +252,7 @@ void main() { final List log = []; final Listenable merged = Listenable.merge([source1, source2]); - final VoidCallback listener = () { log.add('listener'); }; + void listener() { log.add('listener'); } merged.addListener(listener); source1.notify(); @@ -279,7 +279,7 @@ void main() { final ValueNotifier notifier = ValueNotifier(2.0); final List log = []; - final VoidCallback listener = () { log.add(notifier.value); }; + void listener() { log.add(notifier.value); } notifier.addListener(listener); notifier.value = 3.0; @@ -325,7 +325,7 @@ void main() { final TestNotifier source1 = TestNotifier(); final TestNotifier source2 = TestNotifier(); - final VoidCallback fakeListener = () { }; + void fakeListener() { } final Listenable listenableUnderTest = Listenable.merge([source1, source2]); expect(source1.isListenedTo, isFalse); diff --git a/packages/flutter/test/foundation/diagnostics_test.dart b/packages/flutter/test/foundation/diagnostics_test.dart index a6cef4d934..e1f37e7df0 100644 --- a/packages/flutter/test/foundation/diagnostics_test.dart +++ b/packages/flutter/test/foundation/diagnostics_test.dart @@ -1197,7 +1197,7 @@ void main() { }); test('callback property test', () { - final Function onClick = () { }; + void onClick() { } final ObjectFlagProperty present = ObjectFlagProperty( 'onClick', onClick, @@ -1631,7 +1631,7 @@ void main() { }); test('has property test', () { - final Function onClick = () { }; + void onClick() { } final ObjectFlagProperty has = ObjectFlagProperty.has( 'onClick', onClick, @@ -1656,8 +1656,8 @@ void main() { test('iterable flags property test', () { // Normal property { - final Function onClick = () { }; - final Function onMove = () { }; + void onClick() { } + void onMove() { } final Map value = { 'click': onClick, 'move': onMove, @@ -1675,8 +1675,8 @@ void main() { // Reversed-order property { - final Function onClick = () { }; - final Function onMove = () { }; + void onClick() { } + void onMove() { } final Map value = { 'move': onMove, 'click': onClick, @@ -1692,7 +1692,7 @@ void main() { // Partially empty property { - final Function onClick = () { }; + void onClick() { } final Map value = { 'move': null, 'click': onClick, diff --git a/packages/flutter/test/material/dropdown_form_field_test.dart b/packages/flutter/test/material/dropdown_form_field_test.dart index cf2af53a17..87a83e3538 100644 --- a/packages/flutter/test/material/dropdown_form_field_test.dart +++ b/packages/flutter/test/material/dropdown_form_field_test.dart @@ -11,7 +11,7 @@ import 'package:flutter/material.dart'; import '../rendering/mock_canvas.dart'; const List menuItems = ['one', 'two', 'three', 'four']; -final ValueChanged onChanged = (_) { }; +void onChanged(T _) { } final Type dropdownButtonType = DropdownButton( onChanged: (_) { }, items: const >[], diff --git a/packages/flutter/test/material/dropdown_test.dart b/packages/flutter/test/material/dropdown_test.dart index 936fb87b4f..301fe35dad 100644 --- a/packages/flutter/test/material/dropdown_test.dart +++ b/packages/flutter/test/material/dropdown_test.dart @@ -14,7 +14,7 @@ import '../rendering/mock_canvas.dart'; import '../widgets/semantics_tester.dart'; const List menuItems = ['one', 'two', 'three', 'four']; -final ValueChanged onChanged = (_) { }; +void onChanged(T _) { } final Type dropdownButtonType = DropdownButton( onChanged: (_) { }, diff --git a/packages/flutter/test/material/feedback_test.dart b/packages/flutter/test/material/feedback_test.dart index 292739cd0e..06a016c41b 100644 --- a/packages/flutter/test/material/feedback_test.dart +++ b/packages/flutter/test/material/feedback_test.dart @@ -70,9 +70,9 @@ void main () { final SemanticsTester semanticsTester = SemanticsTester(tester); int callbackCount = 0; - final VoidCallback callback = () { + void callback() { callbackCount++; - }; + } await tester.pumpWidget(TestWidget( tapHandler: (BuildContext context) { @@ -132,9 +132,9 @@ void main () { testWidgets('forLongPress Wrapper', (WidgetTester tester) async { final SemanticsTester semanticsTester = SemanticsTester(tester); int callbackCount = 0; - final VoidCallback callback = () { + void callback() { callbackCount++; - }; + } await tester.pumpWidget(TestWidget( longPressHandler: (BuildContext context) { diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 547a16dba7..aeabd9b63c 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -965,7 +965,7 @@ void main() { final Key buildCounterKey = UniqueKey(); const String counterText = 'I show instead of count'; final Widget counter = Text('hello', key: counterKey); - final InputCounterWidgetBuilder buildCounter = ( + Widget buildCounter( BuildContext context, { required int currentLength, required int? maxLength, @@ -975,7 +975,7 @@ void main() { '${currentLength.toString()} of ${maxLength.toString()}', key: buildCounterKey, ); - }; + } await tester.pumpWidget(buildFrame( counterText: counterText, diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index e7dfcd5a97..78c3cc4190 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -466,12 +466,12 @@ void main() { child: Text('XXX'), ), ); - final WidgetPredicate popupMenu = (Widget widget) { + bool popupMenu(Widget widget) { final String widgetType = widget.runtimeType.toString(); // TODO(mraleph): Remove the old case below. return widgetType == '_PopupMenu' // normal case || widgetType == '_PopupMenu'; // for old versions of Dart that don't reify method type arguments - }; + } Future openMenu(TextDirection textDirection, Alignment alignment) async { return TestAsyncUtils.guard(() async { diff --git a/packages/flutter/test/material/range_slider_test.dart b/packages/flutter/test/material/range_slider_test.dart index 0ca15da0e1..315e193d77 100644 --- a/packages/flutter/test/material/range_slider_test.dart +++ b/packages/flutter/test/material/range_slider_test.dart @@ -1347,9 +1347,9 @@ void main() { int? divisions, bool enabled = true, }) { - final ValueChanged onChanged = (RangeValues newValues) { + void onChanged(RangeValues newValues) { values = newValues; - }; + } return MaterialApp( home: Scaffold( // The builder is used to pass the context from the MaterialApp widget diff --git a/packages/flutter/test/material/stepper_test.dart b/packages/flutter/test/material/stepper_test.dart index 4de65f56eb..0fee96921d 100644 --- a/packages/flutter/test/material/stepper_test.dart +++ b/packages/flutter/test/material/stepper_test.dart @@ -380,30 +380,29 @@ void main() { canceledPressed = true; } - final ControlsWidgetBuilder builder = - (BuildContext context, { VoidCallback? onStepContinue, VoidCallback? onStepCancel }) { - return Container( - margin: const EdgeInsets.only(top: 16.0), - child: ConstrainedBox( - constraints: const BoxConstraints.tightFor(height: 48.0), - child: Row( - children: [ - TextButton( - onPressed: onStepContinue, - child: const Text('Let us continue!'), + Widget builder(BuildContext context, { VoidCallback? onStepContinue, VoidCallback? onStepCancel }) { + return Container( + margin: const EdgeInsets.only(top: 16.0), + child: ConstrainedBox( + constraints: const BoxConstraints.tightFor(height: 48.0), + child: Row( + children: [ + TextButton( + onPressed: onStepContinue, + child: const Text('Let us continue!'), + ), + Container( + margin: const EdgeInsetsDirectional.only(start: 8.0), + child: TextButton( + onPressed: onStepCancel, + child: const Text('Cancel This!'), ), - Container( - margin: const EdgeInsetsDirectional.only(start: 8.0), - child: TextButton( - onPressed: onStepCancel, - child: const Text('Cancel This!'), - ), - ), - ], - ), + ), + ], ), - ); - }; + ), + ); + } await tester.pumpWidget( MaterialApp( diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index b64821e5dc..a02c46b7b0 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -252,7 +252,7 @@ void main() { }, variant: const TargetPlatformVariant({ TargetPlatform.macOS, TargetPlatform.windows, TargetPlatform.linux }), skip: kIsWeb); testWidgets('TextField passes onEditingComplete to EditableText', (WidgetTester tester) async { - final VoidCallback onEditingComplete = () { }; + void onEditingComplete() { } await tester.pumpWidget( MaterialApp( @@ -489,10 +489,10 @@ void main() { testWidgets('TextInputFormatter gets correct selection value', (WidgetTester tester) async { late TextEditingValue actualOldValue; late TextEditingValue actualNewValue; - final FormatEditUpdateCallback callBack = (TextEditingValue oldValue, TextEditingValue newValue) { + void callBack(TextEditingValue oldValue, TextEditingValue newValue) { actualOldValue = oldValue; actualNewValue = newValue; - }; + } final FocusNode focusNode = FocusNode(); final TextEditingController controller = TextEditingController(text: '123'); await tester.pumpWidget( diff --git a/packages/flutter/test/material/text_form_field_test.dart b/packages/flutter/test/material/text_form_field_test.dart index f67b31f66a..9557c99016 100644 --- a/packages/flutter/test/material/text_form_field_test.dart +++ b/packages/flutter/test/material/text_form_field_test.dart @@ -201,7 +201,7 @@ void main() { }); testWidgets('Passes onEditingComplete to underlying TextField', (WidgetTester tester) async { - final VoidCallback onEditingComplete = () { }; + void onEditingComplete() { } await tester.pumpWidget( MaterialApp( diff --git a/packages/flutter/test/painting/image_cache_test.dart b/packages/flutter/test/painting/image_cache_test.dart index fd3f2b6f59..06553a5203 100644 --- a/packages/flutter/test/painting/image_cache_test.dart +++ b/packages/flutter/test/painting/image_cache_test.dart @@ -136,9 +136,9 @@ void main() { }); test('Returns null if an error is caught resolving an image', () { - final DecoderCallback _basicDecoder = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { + Future _basicDecoder(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling ?? false); - }; + } final ErrorImageProvider errorImage = ErrorImageProvider(); expect(() => imageCache!.putIfAbsent(errorImage, () => errorImage.load(errorImage, _basicDecoder)), throwsA(isA())); bool caughtError = false; diff --git a/packages/flutter/test/painting/image_provider_and_image_cache_test.dart b/packages/flutter/test/painting/image_provider_and_image_cache_test.dart index 0920e7a0a7..785a8ebdaf 100644 --- a/packages/flutter/test/painting/image_provider_and_image_cache_test.dart +++ b/packages/flutter/test/painting/image_provider_and_image_cache_test.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'dart:typed_data'; +import 'dart:ui' as ui; import 'package:flutter/foundation.dart'; import 'package:flutter/painting.dart'; @@ -16,9 +17,9 @@ import 'mocks_for_image_cache.dart'; void main() { TestRenderingFlutterBinding(); - final DecoderCallback _basicDecoder = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { + Future _basicDecoder(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling ?? false); - }; + } FlutterExceptionHandler? oldError; setUp(() { diff --git a/packages/flutter/test/painting/image_provider_network_image_test.dart b/packages/flutter/test/painting/image_provider_network_image_test.dart index 7917fdbef8..efc333f2dd 100644 --- a/packages/flutter/test/painting/image_provider_network_image_test.dart +++ b/packages/flutter/test/painting/image_provider_network_image_test.dart @@ -18,9 +18,9 @@ import '../rendering/rendering_tester.dart'; void main() { TestRenderingFlutterBinding(); - final DecoderCallback _basicDecoder = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { + Future _basicDecoder(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling ?? false); - }; + } late _FakeHttpClient httpClient; diff --git a/packages/flutter/test/painting/image_provider_resize_image_test.dart b/packages/flutter/test/painting/image_provider_resize_image_test.dart index 44788024d2..46fecb6e68 100644 --- a/packages/flutter/test/painting/image_provider_resize_image_test.dart +++ b/packages/flutter/test/painting/image_provider_resize_image_test.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'dart:typed_data'; +import 'dart:ui' as ui; import 'package:flutter/painting.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -98,12 +99,12 @@ void main() { final MemoryImage memoryImage = MemoryImage(bytes); final ResizeImage resizeImage = ResizeImage(memoryImage, width: 123, height: 321); - final DecoderCallback decode = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { + Future decode(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { expect(cacheWidth, 123); expect(cacheHeight, 321); expect(allowUpscaling, false); return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling); - }; + } resizeImage.load(await resizeImage.obtainKey(ImageConfiguration.empty), decode); }); diff --git a/packages/flutter/test/painting/image_stream_test.dart b/packages/flutter/test/painting/image_stream_test.dart index f10460d981..607d8a587f 100644 --- a/packages/flutter/test/painting/image_stream_test.dart +++ b/packages/flutter/test/painting/image_stream_test.dart @@ -105,7 +105,7 @@ void main() { await tester.idle(); expect(mockCodec.numFramesAsked, 0); - final ImageListener listener = (ImageInfo image, bool synchronousCall) { }; + void listener(ImageInfo image, bool synchronousCall) { } imageStream.addListener(ImageStreamListener(listener)); await tester.idle(); expect(mockCodec.numFramesAsked, 1); @@ -120,7 +120,7 @@ void main() { scale: 1.0, ); - final ImageListener listener = (ImageInfo image, bool synchronousCall) { }; + void listener(ImageInfo image, bool synchronousCall) { } imageStream.addListener(ImageStreamListener(listener)); await tester.idle(); expect(mockCodec.numFramesAsked, 0); @@ -143,7 +143,7 @@ void main() { await tester.idle(); expect(mockCodec.numFramesAsked, 0); - final ImageListener listener = (ImageInfo image, bool synchronousCall) { }; + void listener(ImageInfo image, bool synchronousCall) { } final ImageStreamListener streamListener = ImageStreamListener(listener); imageStream.addListener(streamListener); await tester.idle(); @@ -291,7 +291,7 @@ void main() { scale: 1.0, ); - final ImageListener listener = (ImageInfo image, bool synchronousCall) { }; + void listener(ImageInfo image, bool synchronousCall) { } imageStream.addListener(ImageStreamListener(listener)); codecCompleter.complete(mockCodec); // MultiFrameImageStreamCompleter only sets an error handler for the next @@ -467,7 +467,7 @@ void main() { scale: 1.0, ); - final ImageListener listener = (ImageInfo image, bool synchronousCall) { }; + void listener(ImageInfo image, bool synchronousCall) { } imageStream.addListener(ImageStreamListener(listener)); final ImageStreamCompleterHandle handle = imageStream.keepAlive(); @@ -508,13 +508,13 @@ void main() { ); final List emittedImages1 = []; - final ImageListener listener1 = (ImageInfo image, bool synchronousCall) { + void listener1(ImageInfo image, bool synchronousCall) { emittedImages1.add(image); - }; + } final List emittedImages2 = []; - final ImageListener listener2 = (ImageInfo image, bool synchronousCall) { + void listener2(ImageInfo image, bool synchronousCall) { emittedImages2.add(image); - }; + } imageStream.addListener(ImageStreamListener(listener1)); imageStream.addListener(ImageStreamListener(listener2)); @@ -554,7 +554,7 @@ void main() { scale: 1.0, ); - final ImageListener listener = (ImageInfo image, bool synchronousCall) { }; + void listener(ImageInfo image, bool synchronousCall) { } imageStream.addListener(ImageStreamListener(listener)); codecCompleter.complete(mockCodec); @@ -587,7 +587,7 @@ void main() { scale: 1.0, ); - final ImageListener listener = (ImageInfo image, bool synchronousCall) { }; + void listener(ImageInfo image, bool synchronousCall) { } imageStream.addListener(ImageStreamListener(listener)); codecCompleter.complete(mockCodec); @@ -623,9 +623,9 @@ void main() { ); dynamic capturedException; - final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { + void errorListener(dynamic exception, StackTrace? stackTrace) { capturedException = exception; - }; + } streamUnderTest.addListener(ImageStreamListener( (ImageInfo image, bool synchronousCall) { }, @@ -658,7 +658,7 @@ void main() { scale: 1.0, ); - final ImageListener listener = (ImageInfo image, bool synchronousCall) { }; + void listener(ImageInfo image, bool synchronousCall) { } imageStream.addListener(ImageStreamListener(listener)); codecCompleter.complete(mockCodec); @@ -723,9 +723,9 @@ void main() { ); int onImageCount = 0; - final ImageListener activeListener = (ImageInfo image, bool synchronousCall) { + void activeListener(ImageInfo image, bool synchronousCall) { onImageCount += 1; - }; + } bool lastListenerDropped = false; imageStream.addOnLastListenerRemovedCallback(() { lastListenerDropped = true; diff --git a/packages/flutter/test/rendering/proxy_getters_and_setters_test.dart b/packages/flutter/test/rendering/proxy_getters_and_setters_test.dart index 39edd0123e..402034d0d5 100644 --- a/packages/flutter/test/rendering/proxy_getters_and_setters_test.dart +++ b/packages/flutter/test/rendering/proxy_getters_and_setters_test.dart @@ -51,16 +51,16 @@ void main() { }); test('RenderShaderMask getters and setters', () { - final ShaderCallback callback1 = (Rect bounds) { + Shader callback1(Rect bounds) { assert(false); // The test should not call this. const LinearGradient gradient = LinearGradient(colors: [Colors.red]); return gradient.createShader(Rect.zero); - }; - final ShaderCallback callback2 = (Rect bounds) { + } + Shader callback2(Rect bounds) { assert(false); // The test should not call this. const LinearGradient gradient = LinearGradient(colors: [Colors.blue]); return gradient.createShader(Rect.zero); - }; + } final RenderShaderMask box = RenderShaderMask(shaderCallback: callback1); expect(box.shaderCallback, equals(callback1)); box.shaderCallback = callback2; diff --git a/packages/flutter/test/rendering/stack_test.dart b/packages/flutter/test/rendering/stack_test.dart index 41d51a0c89..679dcfba1e 100644 --- a/packages/flutter/test/rendering/stack_test.dart +++ b/packages/flutter/test/rendering/stack_test.dart @@ -106,9 +106,9 @@ void main() { ); final List visitedChildren = []; - final RenderObjectVisitor visitor = (RenderObject child) { + void visitor(RenderObject child) { visitedChildren.add(child); - }; + } stack.visitChildrenForSemantics(visitor); diff --git a/packages/flutter/test/semantics/semantics_test.dart b/packages/flutter/test/semantics/semantics_test.dart index 0a29d9a801..6faedf3551 100644 --- a/packages/flutter/test/semantics/semantics_test.dart +++ b/packages/flutter/test/semantics/semantics_test.dart @@ -616,18 +616,18 @@ void main() { config.isFocused = true; config.isTextField = true; - final VoidCallback onShowOnScreen = () { }; - final VoidCallback onScrollDown = () { }; - final VoidCallback onScrollUp = () { }; - final VoidCallback onScrollLeft = () { }; - final VoidCallback onScrollRight = () { }; - final VoidCallback onLongPress = () { }; - final VoidCallback onDecrease = () { }; - final VoidCallback onIncrease = () { }; - final MoveCursorHandler onMoveCursorForwardByCharacter = (bool _) { }; - final MoveCursorHandler onMoveCursorBackwardByCharacter = (bool _) { }; - final VoidCallback onTap = () { }; - final VoidCallback onCustomAction = () { }; + void onShowOnScreen() { } + void onScrollDown() { } + void onScrollUp() { } + void onScrollLeft() { } + void onScrollRight() { } + void onLongPress() { } + void onDecrease() { } + void onIncrease() { } + void onMoveCursorForwardByCharacter(bool _) { } + void onMoveCursorBackwardByCharacter(bool _) { } + void onTap() { } + void onCustomAction() { } config.onShowOnScreen = onShowOnScreen; config.onScrollDown = onScrollDown; diff --git a/packages/flutter/test/services/channel_buffers_test.dart b/packages/flutter/test/services/channel_buffers_test.dart index 5b4d7ef24e..ced7a1b380 100644 --- a/packages/flutter/test/services/channel_buffers_test.dart +++ b/packages/flutter/test/services/channel_buffers_test.dart @@ -30,9 +30,9 @@ void main() { final TestChannelBuffersFlutterBinding binding = TestChannelBuffersFlutterBinding(); expect(binding.defaultBinaryMessenger, isNotNull); bool didCallCallback = false; - final ui.PlatformMessageResponseCallback callback = (ByteData? responseData) { + void callback(ByteData? responseData) { didCallCallback = true; - }; + } const String payload = 'bar'; final ByteData data = _makeByteData(payload); ui.channelBuffers.push(channel, data, callback); diff --git a/packages/flutter/test/services/platform_views_test.dart b/packages/flutter/test/services/platform_views_test.dart index d4386920c2..4a3228fea9 100644 --- a/packages/flutter/test/services/platform_views_test.dart +++ b/packages/flutter/test/services/platform_views_test.dart @@ -148,7 +148,7 @@ void main() { test('OnPlatformViewCreated callback', () async { viewsController.registerViewType('webview'); final List createdViews = []; - final PlatformViewCreatedCallback callback = (int id) { createdViews.add(id); }; + void callback(int id) { createdViews.add(id); } final AndroidViewController controller1 = PlatformViewsService.initAndroidView( id: 0, diff --git a/packages/flutter/test/widgets/animated_list_test.dart b/packages/flutter/test/widgets/animated_list_test.dart index 73a061f937..e928d1fc7f 100644 --- a/packages/flutter/test/widgets/animated_list_test.dart +++ b/packages/flutter/test/widgets/animated_list_test.dart @@ -8,14 +8,14 @@ import 'package:flutter/widgets.dart'; void main() { testWidgets('AnimatedList', (WidgetTester tester) async { - final AnimatedListItemBuilder builder = (BuildContext context, int index, Animation animation) { + Widget builder(BuildContext context, int index, Animation animation) { return SizedBox( height: 100.0, child: Center( child: Text('item $index'), ), ); - }; + } final GlobalKey listKey = GlobalKey(); await tester.pumpWidget( diff --git a/packages/flutter/test/widgets/app_navigator_key_test.dart b/packages/flutter/test/widgets/app_navigator_key_test.dart index cb4a10f097..66da485c59 100644 --- a/packages/flutter/test/widgets/app_navigator_key_test.dart +++ b/packages/flutter/test/widgets/app_navigator_key_test.dart @@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; -final RouteFactory generateRoute = (RouteSettings settings) => PageRouteBuilder( +Route generateRoute(RouteSettings settings) => PageRouteBuilder( settings: settings, pageBuilder: (BuildContext context, Animation animation1, Animation animation2) { return const Placeholder(); diff --git a/packages/flutter/test/widgets/autocomplete_test.dart b/packages/flutter/test/widgets/autocomplete_test.dart index 3a1b67a902..008537a933 100644 --- a/packages/flutter/test/widgets/autocomplete_test.dart +++ b/packages/flutter/test/widgets/autocomplete_test.dart @@ -212,7 +212,7 @@ void main() { late Iterable lastOptions; late AutocompleteOnSelected lastOnSelected; late User lastUserSelected; - late final AutocompleteOptionToString displayStringForOption = (User option) => option.name; + String displayStringForOption(User option) => option.name; late FocusNode focusNode; late TextEditingController textEditingController; diff --git a/packages/flutter/test/widgets/fade_in_image_test.dart b/packages/flutter/test/widgets/fade_in_image_test.dart index 420495b051..d659fc5ff3 100644 --- a/packages/flutter/test/widgets/fade_in_image_test.dart +++ b/packages/flutter/test/widgets/fade_in_image_test.dart @@ -320,13 +320,13 @@ Future main() async { ); bool called = false; - final DecoderCallback decode = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { + Future decode(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { expect(cacheWidth, 20); expect(cacheHeight, 30); expect(allowUpscaling, false); called = true; return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling); - }; + } final ImageProvider resizeImage = image.placeholder; expect(image.placeholder, isA()); expect(called, false); @@ -343,13 +343,13 @@ Future main() async { ); bool called = false; - final DecoderCallback decode = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { + Future decode(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { expect(cacheWidth, null); expect(cacheHeight, null); expect(allowUpscaling, false); called = true; return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight); - }; + } // image.placeholder should be an instance of MemoryImage instead of ResizeImage final ImageProvider memoryImage = image.placeholder; expect(image.placeholder, isA()); diff --git a/packages/flutter/test/widgets/gesture_detector_semantics_test.dart b/packages/flutter/test/widgets/gesture_detector_semantics_test.dart index 266fdd70f6..72ba4205d3 100644 --- a/packages/flutter/test/widgets/gesture_detector_semantics_test.dart +++ b/packages/flutter/test/widgets/gesture_detector_semantics_test.dart @@ -117,7 +117,7 @@ void main() { final Set logs = {}; final GlobalKey detectorKey = GlobalKey(); - final VoidCallback performLayout = () { + void performLayout() { detectorKey.currentState!.replaceGestureRecognizers({ TapGestureRecognizer: GestureRecognizerFactoryWithHandlers( () => TapGestureRecognizer(), @@ -126,7 +126,7 @@ void main() { }, ), }); - }; + } bool hasLayoutPerformer = false; late VoidCallback introduceLayoutPerformer; diff --git a/packages/flutter/test/widgets/gesture_detector_test.dart b/packages/flutter/test/widgets/gesture_detector_test.dart index 3a9830bd6e..658b8e9fe0 100644 --- a/packages/flutter/test/widgets/gesture_detector_test.dart +++ b/packages/flutter/test/widgets/gesture_detector_test.dart @@ -252,7 +252,7 @@ void main() { }, variant: buttonVariant); testWidgets('cache render object', (WidgetTester tester) async { - final GestureTapCallback inputCallback = () { }; + void inputCallback() { } await tester.pumpWidget( Center( diff --git a/packages/flutter/test/widgets/heroes_test.dart b/packages/flutter/test/widgets/heroes_test.dart index f77f86d29c..64d85c2df5 100644 --- a/packages/flutter/test/widgets/heroes_test.dart +++ b/packages/flutter/test/widgets/heroes_test.dart @@ -2244,7 +2244,7 @@ Future main() async { testWidgets('On an iOS back swipe and snap, only a single flight should take place', (WidgetTester tester) async { int shuttlesBuilt = 0; - final HeroFlightShuttleBuilder shuttleBuilder = ( + Widget shuttleBuilder( BuildContext flightContext, Animation animation, HeroFlightDirection flightDirection, @@ -2253,7 +2253,7 @@ Future main() async { ) { shuttlesBuilt += 1; return const Text("I'm flying in a jetplane"); - }; + } final GlobalKey navigatorKey = GlobalKey(); await tester.pumpWidget( diff --git a/packages/flutter/test/widgets/image_test.dart b/packages/flutter/test/widgets/image_test.dart index 544e6ffee5..e0b450598d 100644 --- a/packages/flutter/test/widgets/image_test.dart +++ b/packages/flutter/test/widgets/image_test.dart @@ -477,13 +477,13 @@ void main() { dynamic capturedException; StackTrace? capturedStackTrace; ImageInfo? capturedImage; - final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { + void errorListener(dynamic exception, StackTrace? stackTrace) { capturedException = exception; capturedStackTrace = stackTrace; - }; - final ImageListener listener = (ImageInfo info, bool synchronous) { + } + void listener(ImageInfo info, bool synchronous) { capturedImage = info; - }; + } final Exception testException = Exception('cannot resolve host'); final StackTrace testStack = StackTrace.current; @@ -519,13 +519,13 @@ void main() { dynamic reportedException; StackTrace? reportedStackTrace; ImageInfo? capturedImage; - final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { + void errorListener(dynamic exception, StackTrace? stackTrace) { capturedException = exception; capturedStackTrace = stackTrace; - }; - final ImageListener listener = (ImageInfo info, bool synchronous) { + } + void listener(ImageInfo info, bool synchronous) { capturedImage = info; - }; + } FlutterError.onError = (FlutterErrorDetails flutterError) { reportedException = flutterError.exception; reportedStackTrace = flutterError.stack; @@ -568,13 +568,13 @@ void main() { dynamic capturedException; StackTrace? capturedStackTrace; ImageInfo? capturedImage; - final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { + void errorListener(dynamic exception, StackTrace? stackTrace) { capturedException = exception; capturedStackTrace = stackTrace; - }; - final ImageListener listener = (ImageInfo info, bool synchronous) { + } + void listener(ImageInfo info, bool synchronous) { capturedImage = info; - }; + } final Exception testException = Exception('cannot resolve host'); final StackTrace testStack = StackTrace.current; @@ -611,14 +611,14 @@ void main() { StackTrace? capturedStackTrace; ImageInfo? capturedImage; int errorListenerCalled = 0; - final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { + void errorListener(dynamic exception, StackTrace? stackTrace) { capturedException = exception; capturedStackTrace = stackTrace; errorListenerCalled++; - }; - final ImageListener listener = (ImageInfo info, bool synchronous) { + } + void listener(ImageInfo info, bool synchronous) { capturedImage = info; - }; + } final Exception testException = Exception('cannot resolve host'); final StackTrace testStack = StackTrace.current; @@ -656,14 +656,14 @@ void main() { dynamic reportedException; StackTrace? reportedStackTrace; ImageInfo? capturedImage; - final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { + void errorListener(dynamic exception, StackTrace? stackTrace) { errorListenerCalled = true; reportedException = exception; reportedStackTrace = stackTrace; - }; - final ImageListener listener = (ImageInfo info, bool synchronous) { + } + void listener(ImageInfo info, bool synchronous) { capturedImage = info; - }; + } final Exception testException = Exception('cannot resolve host'); final StackTrace testStack = StackTrace.current; @@ -698,12 +698,12 @@ void main() { testWidgets('Removing listener removes one listener and error listener', (WidgetTester tester) async { int errorListenerCalled = 0; ImageInfo? capturedImage; - final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { + void errorListener(dynamic exception, StackTrace? stackTrace) { errorListenerCalled++; - }; - final ImageListener listener = (ImageInfo info, bool synchronous) { + } + void listener(ImageInfo info, bool synchronous) { capturedImage = info; - }; + } final Exception testException = Exception('cannot resolve host'); final StackTrace testStack = StackTrace.current; @@ -805,10 +805,10 @@ void main() { testWidgets('Precache completes with onError on error', (WidgetTester tester) async { dynamic capturedException; StackTrace? capturedStackTrace; - final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { + void errorListener(dynamic exception, StackTrace? stackTrace) { capturedException = exception; capturedStackTrace = stackTrace; - }; + } final Exception testException = Exception('cannot resolve host'); final StackTrace testStack = StackTrace.current; @@ -1419,8 +1419,8 @@ void main() { ), )); - final bool Function(_TestImageProvider) loadCalled = (_TestImageProvider provider) => provider.loadCalled; - final bool Function(_TestImageProvider) loadNotCalled = (_TestImageProvider provider) => !provider.loadCalled; + bool loadCalled(_TestImageProvider provider) => provider.loadCalled; + bool loadNotCalled(_TestImageProvider provider) => !provider.loadCalled; expect(find.bySemanticsLabel('5'), findsOneWidget); expect(imageProviders.length, 12); diff --git a/packages/flutter/test/widgets/list_view_builder_test.dart b/packages/flutter/test/widgets/list_view_builder_test.dart index 1a60777fd0..4cd39ce17b 100644 --- a/packages/flutter/test/widgets/list_view_builder_test.dart +++ b/packages/flutter/test/widgets/list_view_builder_test.dart @@ -68,7 +68,7 @@ void main() { // so if our widget is 200 pixels tall, it should fit exactly 3 times. // but if we are offset by 300 pixels, there will be 4, numbered 1-4. - final IndexedWidgetBuilder itemBuilder = (BuildContext context, int index) { + Widget itemBuilder(BuildContext context, int index) { callbackTracker.add(index); return SizedBox( key: ValueKey(index), @@ -76,7 +76,7 @@ void main() { height: 400.0, // should be overridden by itemExtent child: Text('$index', textDirection: TextDirection.ltr), ); - }; + } Widget buildWidget() { return Directionality( @@ -141,7 +141,7 @@ void main() { // so if our widget is 200 pixels wide, it should fit exactly 4 times. // but if we are offset by 300 pixels, there will be 5, numbered 1-5. - final IndexedWidgetBuilder itemBuilder = (BuildContext context, int index) { + Widget itemBuilder(BuildContext context, int index) { callbackTracker.add(index); return SizedBox( key: ValueKey(index), @@ -149,7 +149,7 @@ void main() { height: 500.0, // this should be ignored child: Text('$index'), ); - }; + } Widget buildWidget() { return Directionality( @@ -215,10 +215,10 @@ void main() { // items are 300 tall. Scrolling should cause two or three items // to be built. - final IndexedWidgetBuilder itemBuilder = (BuildContext context, int index) { + Widget itemBuilder(BuildContext context, int index) { callbackTracker.add(index); return Text('$index', key: ValueKey(index), textDirection: TextDirection.ltr); - }; + } final Widget testWidget = Directionality( textDirection: TextDirection.ltr, diff --git a/packages/flutter/test/widgets/list_view_viewporting_test.dart b/packages/flutter/test/widgets/list_view_viewporting_test.dart index 4b2f5a451d..39fd983145 100644 --- a/packages/flutter/test/widgets/list_view_viewporting_test.dart +++ b/packages/flutter/test/widgets/list_view_viewporting_test.dart @@ -68,7 +68,7 @@ void main() { // so if our widget is 200 pixels tall, it should fit exactly 3 times. // but if we are offset by 300 pixels, there will be 4, numbered 1-4. - final IndexedWidgetBuilder itemBuilder = (BuildContext context, int index) { + Widget itemBuilder(BuildContext context, int index) { callbackTracker.add(index); return SizedBox( key: ValueKey(index), @@ -76,7 +76,7 @@ void main() { height: 200.0, child: Text('$index', textDirection: TextDirection.ltr), ); - }; + } Widget builder() { return Directionality( @@ -131,7 +131,7 @@ void main() { // so if our widget is 200 pixels wide, it should fit exactly 4 times. // but if we are offset by 300 pixels, there will be 5, numbered 1-5. - final IndexedWidgetBuilder itemBuilder = (BuildContext context, int index) { + Widget itemBuilder(BuildContext context, int index) { callbackTracker.add(index); return SizedBox( key: ValueKey(index), @@ -139,7 +139,7 @@ void main() { width: 200.0, child: Text('$index', textDirection: TextDirection.ltr), ); - }; + } Widget builder() { return Directionality( @@ -182,7 +182,7 @@ void main() { final List callbackTracker = []; final List text = []; - final IndexedWidgetBuilder itemBuilder = (BuildContext context, int index) { + Widget itemBuilder(BuildContext context, int index) { callbackTracker.add(index); return SizedBox( key: ValueKey(index), @@ -190,7 +190,7 @@ void main() { height: 220.0, child: Text('$index', textDirection: TextDirection.ltr), ); - }; + } void collectText(Widget widget) { if (widget is Text) @@ -233,7 +233,7 @@ void main() { late StateSetter setState; ThemeData themeData = ThemeData.light(); - final IndexedWidgetBuilder itemBuilder = (BuildContext context, int index) { + Widget itemBuilder(BuildContext context, int index) { return Container( key: ValueKey(index), width: 500.0, // this should be ignored @@ -241,7 +241,7 @@ void main() { color: Theme.of(context).primaryColor, child: Text('$index', textDirection: TextDirection.ltr), ); - }; + } final Widget viewport = ListView.builder( itemBuilder: itemBuilder, @@ -273,7 +273,7 @@ void main() { }); testWidgets('ListView padding', (WidgetTester tester) async { - final IndexedWidgetBuilder itemBuilder = (BuildContext context, int index) { + Widget itemBuilder(BuildContext context, int index) { return Container( key: ValueKey(index), width: 500.0, // this should be ignored @@ -281,7 +281,7 @@ void main() { color: Colors.green[500], child: Text('$index', textDirection: TextDirection.ltr), ); - }; + } await tester.pumpWidget( Directionality( diff --git a/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart b/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart index bab3573f5a..ebe1b375a0 100644 --- a/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart +++ b/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart @@ -880,7 +880,7 @@ void main() { group('scroll notifications', () { testWidgets('no onSelectedItemChanged callback on first build', (WidgetTester tester) async { bool itemChangeCalled = false; - final ValueChanged onItemChange = (_) { itemChangeCalled = true; }; + void onItemChange(int _) { itemChangeCalled = true; } await tester.pumpWidget( Directionality( diff --git a/packages/flutter/test/widgets/mouse_region_test.dart b/packages/flutter/test/widgets/mouse_region_test.dart index 5d918c1a31..121dafb4be 100644 --- a/packages/flutter/test/widgets/mouse_region_test.dart +++ b/packages/flutter/test/widgets/mouse_region_test.dart @@ -1424,8 +1424,8 @@ void main() { await gesture.addPointer(location: const Offset(5, 5)); addTearDown(gesture.removePointer); - final PointerHoverEventListener onHover = (_) {}; - final VoidCallback onPaintChild = () { logs.add('paint'); }; + void onHover(PointerHoverEvent _) {} + void onPaintChild() { logs.add('paint'); } await tester.pumpWidget(_Scaffold( topLeft: SizedBox( @@ -1471,7 +1471,7 @@ void main() { await gesture.addPointer(location: const Offset(100, 100)); addTearDown(gesture.removePointer); - final VoidCallback onPaintChild = () { logPaints.add('paint'); }; + void onPaintChild() { logPaints.add('paint'); } await tester.pumpWidget(_Scaffold( topLeft: SizedBox( @@ -1521,7 +1521,7 @@ void main() { await gesture.addPointer(location: const Offset(100, 100)); addTearDown(gesture.removePointer); - final VoidCallback onPaintChild = () { logPaints.add('paint'); }; + void onPaintChild() { logPaints.add('paint'); } await tester.pumpWidget(_Scaffold( topLeft: SizedBox( diff --git a/packages/flutter/test/widgets/platform_view_test.dart b/packages/flutter/test/widgets/platform_view_test.dart index f77193bd1a..866e1a6c20 100644 --- a/packages/flutter/test/widgets/platform_view_test.dart +++ b/packages/flutter/test/widgets/platform_view_test.dart @@ -870,10 +870,10 @@ void main() { viewsController.registerViewType('webview'); int factoryInvocationCount = 0; - final ValueGetter constructRecognizer = () { + EagerGestureRecognizer constructRecognizer() { factoryInvocationCount += 1; return EagerGestureRecognizer(); - }; + } await tester.pumpWidget( AndroidView( @@ -1919,10 +1919,10 @@ void main() { viewsController.registerViewType('webview'); int factoryInvocationCount = 0; - final ValueGetter constructRecognizer = () { + EagerGestureRecognizer constructRecognizer() { factoryInvocationCount += 1; return EagerGestureRecognizer(); - }; + } await tester.pumpWidget( UiKitView( @@ -2194,10 +2194,10 @@ void main() { testWidgets('PlatformViewRenderBox reconstructed with same gestureRecognizers', (WidgetTester tester) async { int factoryInvocationCount = 0; - final ValueGetter constructRecognizer = () { + EagerGestureRecognizer constructRecognizer() { ++ factoryInvocationCount; return EagerGestureRecognizer(); - }; + } final PlatformViewSurface platformViewSurface = PlatformViewSurface( controller: controller, @@ -2218,10 +2218,10 @@ void main() { testWidgets('PlatformViewSurface rebuilt with same gestureRecognizers', (WidgetTester tester) async { int factoryInvocationCount = 0; - final ValueGetter constructRecognizer = () { + EagerGestureRecognizer constructRecognizer() { ++ factoryInvocationCount; return EagerGestureRecognizer(); - }; + } await tester.pumpWidget( PlatformViewSurface( diff --git a/packages/flutter_driver/lib/src/common/error.dart b/packages/flutter_driver/lib/src/common/error.dart index 8086778d00..c8c6eb1260 100644 --- a/packages/flutter_driver/lib/src/common/error.dart +++ b/packages/flutter_driver/lib/src/common/error.dart @@ -50,10 +50,12 @@ typedef DriverLogCallback = void Function(String source, String message); /// messages from the driver subsystem. /// /// The default implementation prints `"$source: $message"` to stderr. -DriverLogCallback driverLog = (String source, String message) { +DriverLogCallback driverLog = _defaultDriverLogger; + +void _defaultDriverLogger(String source, String message) { try { stderr.writeln('$source: $message'); } on FileSystemException { // May encounter IO error: https://github.com/flutter/flutter/issues/69314 } -}; +} diff --git a/packages/flutter_driver/test/src/real_tests/extension_test.dart b/packages/flutter_driver/test/src/real_tests/extension_test.dart index a3f175fcdd..5a43b59a19 100644 --- a/packages/flutter_driver/test/src/real_tests/extension_test.dart +++ b/packages/flutter_driver/test/src/real_tests/extension_test.dart @@ -1035,7 +1035,7 @@ void main() { group('extension commands', () { int invokes = 0; - final VoidCallback stubCallback = () => invokes++; + void stubCallback() => invokes++; final Widget debugTree = Directionality( textDirection: TextDirection.ltr, diff --git a/packages/flutter_test/lib/src/frame_timing_summarizer.dart b/packages/flutter_test/lib/src/frame_timing_summarizer.dart index e85e4b1f20..e43bce2938 100644 --- a/packages/flutter_test/lib/src/frame_timing_summarizer.dart +++ b/packages/flutter_test/lib/src/frame_timing_summarizer.dart @@ -35,8 +35,7 @@ class FrameTimingSummarizer { ); final List vsyncOverheadSorted = List.from(vsyncOverhead)..sort(); - final Duration Function(Duration, Duration) add = - (Duration a, Duration b) => a + b; + Duration add(Duration a, Duration b) => a + b; return FrameTimingSummarizer._( frameBuildTime: frameBuildTime, frameRasterizerTime: frameRasterizerTime, diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index 317c7d6ac1..ac1e57ea22 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -241,8 +241,7 @@ class WebAssetServer implements AssetReader { // load the through the isolate APIs. final Directory directory = await _loadDwdsDirectory(globals.fs, globals.logger); - final shelf.Middleware middleware = - (FutureOr Function(shelf.Request) innerHandler) { + shelf.Handler middleware(FutureOr Function(shelf.Request) innerHandler) { return (shelf.Request request) async { if (request.url.path.endsWith('dwds/src/injected/client.js')) { final Uri uri = directory.uri.resolve('src/injected/client.js'); @@ -254,7 +253,7 @@ class WebAssetServer implements AssetReader { } return innerHandler(request); }; - }; + } logging.Logger.root.onRecord.listen((logging.LogRecord event) { globals.printTrace('${event.loggerName}: ${event.message}'); diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart index 3df003bf32..a65dc2e5fb 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart @@ -420,13 +420,13 @@ String _generateLookupBody( bool useDeferredLoading, String fileName, ) { - final String Function(LocaleInfo) generateSwitchClauseTemplate = (LocaleInfo locale) { + String generateSwitchClauseTemplate(LocaleInfo locale) { return (useDeferredLoading ? switchClauseDeferredLoadingTemplate : switchClauseTemplate) .replaceAll('@(localeClass)', '$className${locale.camelCase()}') .replaceAll('@(appClass)', className) .replaceAll('@(library)', '${fileName}_${locale.languageCode}'); - }; + } return lookupBodyTemplate .replaceAll('@(lookupAllCodesSpecified)', _generateLookupByAllCodes( allBundles, diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index 28a1e27139..598c67249a 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -14,7 +14,6 @@ import '../application_package.dart'; import '../base/common.dart'; import '../base/context.dart'; import '../base/io.dart' as io; -import '../base/signals.dart'; import '../base/terminal.dart'; import '../base/user_messages.dart'; import '../base/utils.dart'; @@ -1068,7 +1067,7 @@ abstract class FlutterCommand extends Command { } void _registerSignalHandlers(String commandPath, DateTime startTime) { - final SignalHandler handler = (io.ProcessSignal s) { + void handler(io.ProcessSignal s) { globals.cache.releaseLock(); _sendPostUsage( commandPath, @@ -1076,7 +1075,7 @@ abstract class FlutterCommand extends Command { startTime, globals.systemClock.now(), ); - }; + } globals.signals.addHandler(io.ProcessSignal.SIGTERM, handler); globals.signals.addHandler(io.ProcessSignal.SIGINT, handler); } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart index b4c5e79a75..d015e57191 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart @@ -37,7 +37,7 @@ import '../../src/context.dart'; import '../../src/fakes.dart'; import '../../src/testbed.dart'; -final Generator _kNoColorOutputPlatform = () => FakePlatform( +FakePlatform _kNoColorOutputPlatform() => FakePlatform( localeName: 'en_US.UTF-8', environment: {}, stdoutSupportsAnsi: false, diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart index ce2fd1fc33..d4e90b9039 100755 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -40,7 +40,7 @@ const String frameworkRevision = '12345678'; const String frameworkChannel = 'omega'; const String _kDisabledPlatformRequestedMessage = 'currently not supported on your local environment.'; // TODO(fujino): replace FakePlatform.fromPlatform() with FakePlatform() -final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false; +FakePlatform _kNoColorTerminalPlatform() => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false; final Map noColorTerminalOverride = { Platform: _kNoColorTerminalPlatform, }; diff --git a/packages/flutter_tools/test/general.shard/application_package_test.dart b/packages/flutter_tools/test/general.shard/application_package_test.dart index 36c33a6434..8e962082b9 100644 --- a/packages/flutter_tools/test/general.shard/application_package_test.dart +++ b/packages/flutter_tools/test/general.shard/application_package_test.dart @@ -25,7 +25,7 @@ import '../src/common.dart'; import '../src/context.dart'; import '../src/fakes.dart'; -final Generator _kNoColorTerminalPlatform = () => FakePlatform(stdoutSupportsAnsi: false); +FakePlatform _kNoColorTerminalPlatform() => FakePlatform(stdoutSupportsAnsi: false); final Map noColorTerminalOverride = { Platform: _kNoColorTerminalPlatform, }; diff --git a/packages/flutter_tools/test/general.shard/ios/mac_test.dart b/packages/flutter_tools/test/general.shard/ios/mac_test.dart index 4cc138214b..1e73f9bc9e 100644 --- a/packages/flutter_tools/test/general.shard/ios/mac_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/mac_test.dart @@ -22,7 +22,7 @@ import '../../src/common.dart'; import '../../src/context.dart'; import '../../src/fakes.dart'; -final Generator _kNoColorTerminalPlatform = () => FakePlatform(stdoutSupportsAnsi: false); +FakePlatform _kNoColorTerminalPlatform() => FakePlatform(stdoutSupportsAnsi: false); final Map noColorTerminalOverride = { Platform: _kNoColorTerminalPlatform, }; diff --git a/packages/flutter_tools/test/general.shard/macos/application_package_test.dart b/packages/flutter_tools/test/general.shard/macos/application_package_test.dart index d838d69099..2607ae22f6 100644 --- a/packages/flutter_tools/test/general.shard/macos/application_package_test.dart +++ b/packages/flutter_tools/test/general.shard/macos/application_package_test.dart @@ -198,8 +198,7 @@ void main() { class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {} -final Generator _kNoColorTerminalPlatform = - () => FakePlatform(stdoutSupportsAnsi: false); +FakePlatform _kNoColorTerminalPlatform() => FakePlatform(stdoutSupportsAnsi: false); final Map noColorTerminalOverride = { Platform: _kNoColorTerminalPlatform, }; diff --git a/packages/flutter_tools/test/general.shard/version_test.dart b/packages/flutter_tools/test/general.shard/version_test.dart index 688f9e76ff..fe91232bef 100644 --- a/packages/flutter_tools/test/general.shard/version_test.dart +++ b/packages/flutter_tools/test/general.shard/version_test.dart @@ -797,7 +797,7 @@ void fakeData( throw StateError('Unexpected call to Cache.setStampFor(${invocation.positionalArguments}, ${invocation.namedArguments})'); }); - final Answering syncAnswer = (Invocation invocation) { + ProcessResult syncAnswer(Invocation invocation) { bool argsAre(String a1, [ String a2, String a3, String a4, String a5, String a6, String a7, String a8, String a9 ]) { const ListEquality equality = ListEquality(); final List args = invocation.positionalArguments.single as List; @@ -828,7 +828,7 @@ void fakeData( } throw StateError('Unexpected call to ProcessManager.run(${invocation.positionalArguments}, ${invocation.namedArguments})'); - }; + } when(pm.runSync(any, workingDirectory: anyNamed('workingDirectory'))).thenAnswer(syncAnswer); when(pm.run(any, workingDirectory: anyNamed('workingDirectory'))).thenAnswer((Invocation invocation) async { diff --git a/packages/flutter_tools/test/src/mocks.dart b/packages/flutter_tools/test/src/mocks.dart index 9444cec7cc..7fd1c7c2fc 100644 --- a/packages/flutter_tools/test/src/mocks.dart +++ b/packages/flutter_tools/test/src/mocks.dart @@ -87,11 +87,13 @@ typedef _ProcessFactory = Process Function(List command); /// A ProcessManager that starts Processes by delegating to a ProcessFactory. class MockProcessManager extends Mock implements ProcessManager { - _ProcessFactory processFactory = (List commands) => FakeProcess(); + _ProcessFactory processFactory = _defaulProcessFactory; bool canRunSucceeds = true; bool runSucceeds = true; List commands; + static Process _defaulProcessFactory(List commands) => FakeProcess(); + @override bool canRun(dynamic command, { String workingDirectory }) => canRunSucceeds; diff --git a/packages/flutter_web_plugins/test/navigation/url_strategy_test.dart b/packages/flutter_web_plugins/test/navigation/url_strategy_test.dart index b3f9de79cd..7e0c6896a7 100644 --- a/packages/flutter_web_plugins/test/navigation/url_strategy_test.dart +++ b/packages/flutter_web_plugins/test/navigation/url_strategy_test.dart @@ -143,7 +143,7 @@ class TestPlatformLocation extends PlatformLocation { String hash = ''; @override - Object? Function() state = () => null; + Object? get state => null; /// Mocks the base href of the document. String baseHref = ''; diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/common/logging.dart b/packages/fuchsia_remote_debug_protocol/lib/src/common/logging.dart index a4dc66d298..4dd4eaee82 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/common/logging.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/common/logging.dart @@ -50,12 +50,12 @@ typedef LoggingFunction = void Function(LogMessage log); /// '[${log.levelName}]::${log.tag}--${log.time}: ${log.message}' /// /// Exits with status code 1 if the `log` is [LoggingLevel.severe]. -LoggingFunction defaultLoggingFunction = (LogMessage log) { +void defaultLoggingFunction(LogMessage log) { print('[${log.levelName}]::${log.tag}--${log.time}: ${log.message}'); if (log.level == LoggingLevel.severe) { exit(1); } -}; +} /// Represents a logging message created by the logger. ///