From 6b1bc456f4e6e4ee148670edeb76175d7ec970c6 Mon Sep 17 00:00:00 2001 From: Nate Wilson Date: Thu, 17 Oct 2024 13:25:14 -0600 Subject: [PATCH] Arrow syntax for getters (#156483) This egotistical PR aims to draw attention to a [style guideline](https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#use--for-getters-and-callbacks-that-just-return-literals-or-switch-expressions) that I changed: > #### Use `=>` for getters and callbacks that just return literals or switch expressions
There was an opportunity for valuable discussion in #154753 about how this structure affects readability, but I shut it down pretty quick since there was a lot of other stuff going on there. Interested to hear thoughts from @Piinks and others. --- .../test/measure_scroll_smoothness.dart | 22 +++++----- .../lib/src/filtered_child_animation.dart | 14 +++---- dev/conductor/core/lib/src/repository.dart | 10 ++--- dev/devicelab/lib/framework/ab.dart | 10 ++--- dev/tools/gen_defaults/lib/fab_template.dart | 28 ++++++------- .../draggable_scrollable_sheet.0.dart | 19 ++------- .../lib/widgets/page_view/page_view.0.dart | 19 ++------- ...ti_child_render_object_widget_mixin.0.dart | 10 ++--- examples/platform_view/lib/main.dart | 18 ++++---- .../lib/src/cupertino/date_picker.dart | 11 +++-- .../lib/src/foundation/diagnostics.dart | 12 +++--- .../src/material/bottom_navigation_bar.dart | 10 ++--- .../lib/src/material/button_theme.dart | 26 +++++------- packages/flutter/lib/src/material/drawer.dart | 20 ++++----- .../src/material/floating_action_button.dart | 28 ++++++------- .../flutter/lib/src/material/ink_well.dart | 20 ++++----- .../lib/src/material/input_decorator.dart | 14 +++---- .../flutter/lib/src/material/list_tile.dart | 26 +++++------- .../lib/src/material/range_slider.dart | 14 +++---- packages/flutter/lib/src/material/slider.dart | 14 +++---- .../flutter/lib/src/rendering/editable.dart | 10 ++--- .../lib/src/rendering/shifted_box.dart | 14 +++---- packages/flutter/lib/src/widgets/actions.dart | 10 ++--- .../lib/src/widgets/scroll_physics.dart | 10 ++--- .../flutter/lib/src/widgets/scrollable.dart | 14 +++---- .../flutter/lib/src/widgets/scrollbar.dart | 11 +++-- .../flutter/lib/src/widgets/shortcuts.dart | 4 +- .../src/widgets/sliver_resizing_header.dart | 12 +++--- .../flutter_tools/lib/src/android/java.dart | 14 +++---- packages/flutter_tools/lib/src/base/os.dart | 18 ++++---- .../flutter_tools/lib/src/build_info.dart | 28 ++++++------- .../flutter_tools/lib/src/dart/analysis.dart | 12 +++--- .../lib/src/doctor_validator.dart | 42 ++++++++----------- .../flutter_tools/lib/src/flutter_cache.dart | 8 ++-- .../lib/src/macos/swift_packages.dart | 20 ++++----- .../commands.shard/hermetic/doctor_test.dart | 12 +++--- 36 files changed, 239 insertions(+), 345 deletions(-) diff --git a/dev/benchmarks/complex_layout/test/measure_scroll_smoothness.dart b/dev/benchmarks/complex_layout/test/measure_scroll_smoothness.dart index 987933b6b6..9a3bcf5140 100644 --- a/dev/benchmarks/complex_layout/test/measure_scroll_smoothness.dart +++ b/dev/benchmarks/complex_layout/test/measure_scroll_smoothness.dart @@ -67,18 +67,16 @@ class ResampleFlagVariant extends TestVariant { final Set values = Set.from(TestScenario.values); late TestScenario currentValue; - bool get resample { - return switch (currentValue) { - TestScenario.resampleOn90Hz || TestScenario.resampleOn59Hz => true, - TestScenario.resampleOff90Hz || TestScenario.resampleOff59Hz => false, - }; - } - double get frequency { - return switch (currentValue) { - TestScenario.resampleOn90Hz || TestScenario.resampleOff90Hz => 90.0, - TestScenario.resampleOn59Hz || TestScenario.resampleOff59Hz => 59.0, - }; - } + + bool get resample => switch (currentValue) { + TestScenario.resampleOn90Hz || TestScenario.resampleOn59Hz => true, + TestScenario.resampleOff90Hz || TestScenario.resampleOff59Hz => false, + }; + + double get frequency => switch (currentValue) { + TestScenario.resampleOn90Hz || TestScenario.resampleOff90Hz => 90.0, + TestScenario.resampleOn59Hz || TestScenario.resampleOff59Hz => 59.0, + }; Map? result; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart b/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart index a245f8fc46..fb07f88da0 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart @@ -59,14 +59,12 @@ class _FilteredChildAnimationPageState extends State setState(() => _filterType = selected ? type : null); } - String get _title { - return switch (_filterType) { - FilterType.opacity => 'Fading Child Animation', - FilterType.rotateTransform => 'Transformed Child Animation', - FilterType.rotateFilter => 'Matrix Filtered Child Animation', - null => 'Static Child', - }; - } + String get _title => switch (_filterType) { + FilterType.opacity => 'Fading Child Animation', + FilterType.rotateTransform => 'Transformed Child Animation', + FilterType.rotateFilter => 'Matrix Filtered Child Animation', + null => 'Static Child', + }; static Widget _makeChild(int rows, int cols, double fontSize, bool complex) { final BoxDecoration decoration = BoxDecoration( diff --git a/dev/conductor/core/lib/src/repository.dart b/dev/conductor/core/lib/src/repository.dart index f2508ad534..b775b468fa 100644 --- a/dev/conductor/core/lib/src/repository.dart +++ b/dev/conductor/core/lib/src/repository.dart @@ -32,12 +32,10 @@ class Remote { final RemoteName _name; /// The name of the remote. - String get name { - return switch (_name) { - RemoteName.upstream => 'upstream', - RemoteName.mirror => 'mirror', - }; - } + String get name => switch (_name) { + RemoteName.upstream => 'upstream', + RemoteName.mirror => 'mirror', + }; /// The URL of the remote. final String url; diff --git a/dev/devicelab/lib/framework/ab.dart b/dev/devicelab/lib/framework/ab.dart index 160d1ec610..3c38d557c3 100644 --- a/dev/devicelab/lib/framework/ab.dart +++ b/dev/devicelab/lib/framework/ab.dart @@ -207,12 +207,10 @@ class ABTest { return buffer.toString(); } - Set get _allScoreKeys { - return { - ..._aResults.keys, - ..._bResults.keys, - }; - } + Set get _allScoreKeys => { + ..._aResults.keys, + ..._bResults.keys, + }; /// Returns the summary as a tab-separated spreadsheet. /// diff --git a/dev/tools/gen_defaults/lib/fab_template.dart b/dev/tools/gen_defaults/lib/fab_template.dart index 6914611953..3cfda820ba 100644 --- a/dev/tools/gen_defaults/lib/fab_template.dart +++ b/dev/tools/gen_defaults/lib/fab_template.dart @@ -53,24 +53,20 @@ class _${blockName}DefaultsM3 extends FloatingActionButtonThemeData { @override Color? get hoverColor => ${componentColor("md.comp.fab.primary.hover.state-layer")}; @override - ShapeBorder? get shape { - return switch (type) { - _FloatingActionButtonType.regular => ${shape("md.comp.fab.primary.container")}, - _FloatingActionButtonType.small => ${shape("md.comp.fab.primary.small.container")}, - _FloatingActionButtonType.large => ${shape("md.comp.fab.primary.large.container")}, - _FloatingActionButtonType.extended => ${shape("md.comp.extended-fab.primary.container")}, - }; - } + ShapeBorder? get shape => switch (type) { + _FloatingActionButtonType.regular => ${shape("md.comp.fab.primary.container")}, + _FloatingActionButtonType.small => ${shape("md.comp.fab.primary.small.container")}, + _FloatingActionButtonType.large => ${shape("md.comp.fab.primary.large.container")}, + _FloatingActionButtonType.extended => ${shape("md.comp.extended-fab.primary.container")}, + }; @override - double? get iconSize { - return switch (type) { - _FloatingActionButtonType.regular => ${getToken("md.comp.fab.primary.icon.size")}, - _FloatingActionButtonType.small => ${getToken("md.comp.fab.primary.small.icon.size")}, - _FloatingActionButtonType.large => ${getToken("md.comp.fab.primary.large.icon.size")}, - _FloatingActionButtonType.extended => ${getToken("md.comp.extended-fab.primary.icon.size")}, - }; - } + double? get iconSize => switch (type) { + _FloatingActionButtonType.regular => ${getToken("md.comp.fab.primary.icon.size")}, + _FloatingActionButtonType.small => ${getToken("md.comp.fab.primary.small.icon.size")}, + _FloatingActionButtonType.large => ${getToken("md.comp.fab.primary.large.icon.size")}, + _FloatingActionButtonType.extended => ${getToken("md.comp.extended-fab.primary.icon.size")}, + }; @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); @override TextStyle? get extendedTextStyle => ${textStyle("md.comp.extended-fab.primary.label-text")}; diff --git a/examples/api/lib/widgets/draggable_scrollable_sheet/draggable_scrollable_sheet.0.dart b/examples/api/lib/widgets/draggable_scrollable_sheet/draggable_scrollable_sheet.0.dart index f904102678..3fb7a8453d 100644 --- a/examples/api/lib/widgets/draggable_scrollable_sheet/draggable_scrollable_sheet.0.dart +++ b/examples/api/lib/widgets/draggable_scrollable_sheet/draggable_scrollable_sheet.0.dart @@ -85,21 +85,10 @@ class _DraggableScrollableSheetExampleState extends State kIsWeb || switch (defaultTargetPlatform) { + TargetPlatform.macOS || TargetPlatform.linux || TargetPlatform.windows => true, + TargetPlatform.android || TargetPlatform.iOS || TargetPlatform.fuchsia => false, + }; } /// A draggable widget that accepts vertical drag gestures diff --git a/examples/api/lib/widgets/page_view/page_view.0.dart b/examples/api/lib/widgets/page_view/page_view.0.dart index 336a48a04e..5ce7044eef 100644 --- a/examples/api/lib/widgets/page_view/page_view.0.dart +++ b/examples/api/lib/widgets/page_view/page_view.0.dart @@ -102,21 +102,10 @@ class _PageViewExampleState extends State with TickerProviderSt ); } - bool get _isOnDesktopAndWeb { - if (kIsWeb) { - return true; - } - switch (defaultTargetPlatform) { - case TargetPlatform.macOS: - case TargetPlatform.linux: - case TargetPlatform.windows: - return true; - case TargetPlatform.android: - case TargetPlatform.iOS: - case TargetPlatform.fuchsia: - return false; - } - } + bool get _isOnDesktopAndWeb => kIsWeb || switch (defaultTargetPlatform) { + TargetPlatform.macOS || TargetPlatform.linux || TargetPlatform.windows => true, + TargetPlatform.android || TargetPlatform.iOS || TargetPlatform.fuchsia => false, + }; } /// Page indicator for desktop and web platforms. diff --git a/examples/api/lib/widgets/slotted_render_object_widget/slotted_multi_child_render_object_widget_mixin.0.dart b/examples/api/lib/widgets/slotted_render_object_widget/slotted_multi_child_render_object_widget_mixin.0.dart index f884ec8a42..983f096724 100644 --- a/examples/api/lib/widgets/slotted_render_object_widget/slotted_multi_child_render_object_widget_mixin.0.dart +++ b/examples/api/lib/widgets/slotted_render_object_widget/slotted_multi_child_render_object_widget_mixin.0.dart @@ -97,12 +97,10 @@ class RenderDiagonal extends RenderBox // Returns children in hit test order. @override - Iterable get children { - return [ - if (_topLeft != null) _topLeft!, - if (_bottomRight != null) _bottomRight!, - ]; - } + Iterable get children => [ + if (_topLeft != null) _topLeft!, + if (_bottomRight != null) _bottomRight!, + ]; // LAYOUT diff --git a/examples/platform_view/lib/main.dart b/examples/platform_view/lib/main.dart index 5efefe72ff..25106e975e 100644 --- a/examples/platform_view/lib/main.dart +++ b/examples/platform_view/lib/main.dart @@ -47,16 +47,14 @@ class _MyHomePageState extends State { }); } - static Widget get _buttonText { - return switch (defaultTargetPlatform) { - TargetPlatform.android => const Text('Continue in Android view'), - TargetPlatform.iOS => const Text('Continue in iOS view'), - TargetPlatform.windows => const Text('Continue in Windows view'), - TargetPlatform.macOS => const Text('Continue in macOS view'), - TargetPlatform.linux => const Text('Continue in Linux view'), - TargetPlatform.fuchsia => throw UnimplementedError('Platform not yet implemented'), - }; - } + static Widget get _buttonText => switch (defaultTargetPlatform) { + TargetPlatform.android => const Text('Continue in Android view'), + TargetPlatform.iOS => const Text('Continue in iOS view'), + TargetPlatform.windows => const Text('Continue in Windows view'), + TargetPlatform.macOS => const Text('Continue in macOS view'), + TargetPlatform.linux => const Text('Continue in Linux view'), + TargetPlatform.fuchsia => throw UnimplementedError('Platform not yet implemented'), + }; Future _launchPlatformCount() async { final int? platformCounter = diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart index 5dcb413ae2..0e89098938 100644 --- a/packages/flutter/lib/src/cupertino/date_picker.dart +++ b/packages/flutter/lib/src/cupertino/date_picker.dart @@ -2076,12 +2076,11 @@ class CupertinoTimerPicker extends StatefulWidget { class _CupertinoTimerPickerState extends State { late TextDirection textDirection; late CupertinoLocalizations localizations; - int get textDirectionFactor { - return switch (textDirection) { - TextDirection.ltr => 1, - TextDirection.rtl => -1, - }; - } + + int get textDirectionFactor => switch (textDirection) { + TextDirection.ltr => 1, + TextDirection.rtl => -1, + }; // The currently selected values of the picker. int? selectedHour; diff --git a/packages/flutter/lib/src/foundation/diagnostics.dart b/packages/flutter/lib/src/foundation/diagnostics.dart index c6d11d42b3..6847d1433f 100644 --- a/packages/flutter/lib/src/foundation/diagnostics.dart +++ b/packages/flutter/lib/src/foundation/diagnostics.dart @@ -2143,13 +2143,11 @@ class FlagProperty extends DiagnosticsProperty { } @override - DiagnosticLevel get level { - return switch (value) { - true when ifTrue == null => DiagnosticLevel.hidden, - false when ifFalse == null => DiagnosticLevel.hidden, - _ => super.level, - }; - } + DiagnosticLevel get level => switch (value) { + true when ifTrue == null => DiagnosticLevel.hidden, + false when ifFalse == null => DiagnosticLevel.hidden, + _ => super.level, + }; } /// Property with an `Iterable` [value] that can be displayed with diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index 2f6b0b1a2c..5924e0feb1 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -864,12 +864,10 @@ class _BottomNavigationBarState extends State with TickerPr // // Unselected labels are shown by default for [BottomNavigationBarType.fixed], // and hidden by default for [BottomNavigationBarType.shifting]. - bool get _defaultShowUnselected { - return switch (_effectiveType) { - BottomNavigationBarType.shifting => false, - BottomNavigationBarType.fixed => true, - }; - } + bool get _defaultShowUnselected => switch (_effectiveType) { + BottomNavigationBarType.shifting => false, + BottomNavigationBarType.fixed => true, + }; @override void initState() { diff --git a/packages/flutter/lib/src/material/button_theme.dart b/packages/flutter/lib/src/material/button_theme.dart index e558e8fdda..733ecd2611 100644 --- a/packages/flutter/lib/src/material/button_theme.dart +++ b/packages/flutter/lib/src/material/button_theme.dart @@ -254,13 +254,11 @@ class ButtonThemeData with Diagnosticable { /// /// * [getPadding], which is used to calculate padding for the button's /// child (typically the button's label). - EdgeInsetsGeometry get padding { - return _padding ?? switch (textTheme) { - ButtonTextTheme.normal => const EdgeInsets.symmetric(horizontal: 16.0), - ButtonTextTheme.accent => const EdgeInsets.symmetric(horizontal: 16.0), - ButtonTextTheme.primary => const EdgeInsets.symmetric(horizontal: 24.0), - }; - } + EdgeInsetsGeometry get padding => _padding ?? switch (textTheme) { + ButtonTextTheme.normal => const EdgeInsets.symmetric(horizontal: 16.0), + ButtonTextTheme.accent => const EdgeInsets.symmetric(horizontal: 16.0), + ButtonTextTheme.primary => const EdgeInsets.symmetric(horizontal: 24.0), + }; final EdgeInsetsGeometry? _padding; /// The shape of a button's material. @@ -277,14 +275,12 @@ class ButtonThemeData with Diagnosticable { /// /// * [getShape], which is used to calculate the shape of the button's /// [Material]. - ShapeBorder get shape { - return _shape ?? switch (textTheme) { - ButtonTextTheme.normal || ButtonTextTheme.accent => - const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2.0))), - ButtonTextTheme.primary => - const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))), - }; - } + ShapeBorder get shape => _shape ?? switch (textTheme) { + ButtonTextTheme.normal || ButtonTextTheme.accent => + const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2.0))), + ButtonTextTheme.primary => + const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))), + }; final ShapeBorder? _shape; /// If true, then a [DropdownButton] menu's width will match the button's diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart index 0013821c4e..82f9db2ee8 100644 --- a/packages/flutter/lib/src/material/drawer.dart +++ b/packages/flutter/lib/src/material/drawer.dart @@ -638,19 +638,15 @@ class DrawerControllerState extends State with SingleTickerPro ); } - AlignmentDirectional get _drawerOuterAlignment { - return switch (widget.alignment) { - DrawerAlignment.start => AlignmentDirectional.centerStart, - DrawerAlignment.end => AlignmentDirectional.centerEnd, - }; - } + AlignmentDirectional get _drawerOuterAlignment => switch (widget.alignment) { + DrawerAlignment.start => AlignmentDirectional.centerStart, + DrawerAlignment.end => AlignmentDirectional.centerEnd, + }; - AlignmentDirectional get _drawerInnerAlignment { - return switch (widget.alignment) { - DrawerAlignment.start => AlignmentDirectional.centerEnd, - DrawerAlignment.end => AlignmentDirectional.centerStart, - }; - } + AlignmentDirectional get _drawerInnerAlignment => switch (widget.alignment) { + DrawerAlignment.start => AlignmentDirectional.centerEnd, + DrawerAlignment.end => AlignmentDirectional.centerStart, + }; Widget _buildDrawer(BuildContext context) { final bool isDesktop = switch (Theme.of(context).platform) { diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index fff3dc4662..258d74e69b 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -822,24 +822,20 @@ class _FABDefaultsM3 extends FloatingActionButtonThemeData { @override Color? get hoverColor => _colors.onPrimaryContainer.withOpacity(0.08); @override - ShapeBorder? get shape { - return switch (type) { - _FloatingActionButtonType.regular => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))), - _FloatingActionButtonType.small => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))), - _FloatingActionButtonType.large => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))), - _FloatingActionButtonType.extended => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))), - }; - } + ShapeBorder? get shape => switch (type) { + _FloatingActionButtonType.regular => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))), + _FloatingActionButtonType.small => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))), + _FloatingActionButtonType.large => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(28.0))), + _FloatingActionButtonType.extended => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0))), + }; @override - double? get iconSize { - return switch (type) { - _FloatingActionButtonType.regular => 24.0, - _FloatingActionButtonType.small => 24.0, - _FloatingActionButtonType.large => 36.0, - _FloatingActionButtonType.extended => 24.0, - }; - } + double? get iconSize => switch (type) { + _FloatingActionButtonType.regular => 24.0, + _FloatingActionButtonType.small => 24.0, + _FloatingActionButtonType.large => 36.0, + _FloatingActionButtonType.extended => 24.0, + }; @override EdgeInsetsGeometry? get extendedPadding => EdgeInsetsDirectional.only(start: hasChild && _isExtended ? 16.0 : 20.0, end: 20.0); @override TextStyle? get extendedTextStyle => _textTheme.labelLarge; diff --git a/packages/flutter/lib/src/material/ink_well.dart b/packages/flutter/lib/src/material/ink_well.dart index 3be70f7542..c978c727af 100644 --- a/packages/flutter/lib/src/material/ink_well.dart +++ b/packages/flutter/lib/src/material/ink_well.dart @@ -1092,12 +1092,10 @@ class _InkResponseState extends State<_InkResponseStateWidget> }); } - bool get _shouldShowFocus { - return switch (MediaQuery.maybeNavigationModeOf(context)) { - NavigationMode.traditional || null => enabled && _hasFocus, - NavigationMode.directional => _hasFocus, - }; - } + bool get _shouldShowFocus => switch (MediaQuery.maybeNavigationModeOf(context)) { + NavigationMode.traditional || null => enabled && _hasFocus, + NavigationMode.directional => _hasFocus, + }; void updateFocusHighlights() { final bool showFocus = switch (FocusManager.instance.highlightMode) { @@ -1275,12 +1273,10 @@ class _InkResponseState extends State<_InkResponseStateWidget> updateHighlight(_HighlightType.hover, value: _hovering); } - bool get _canRequestFocus { - return switch (MediaQuery.maybeNavigationModeOf(context)) { - NavigationMode.traditional || null => enabled && widget.canRequestFocus, - NavigationMode.directional => true, - }; - } + bool get _canRequestFocus => switch (MediaQuery.maybeNavigationModeOf(context)) { + NavigationMode.traditional || null => enabled && widget.canRequestFocus, + NavigationMode.directional => true, + }; @override Widget build(BuildContext context) { diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 75df5507b8..df07ee4630 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2097,14 +2097,12 @@ class _InputDecoratorState extends State with TickerProviderStat .merge(decoration.errorStyle); } - Set get materialState { - return { - if (!decoration.enabled) MaterialState.disabled, - if (isFocused) MaterialState.focused, - if (isHovering) MaterialState.hovered, - if (_hasError) MaterialState.error, - }; - } + Set get materialState => { + if (!decoration.enabled) MaterialState.disabled, + if (isFocused) MaterialState.focused, + if (isHovering) MaterialState.hovered, + if (_hasError) MaterialState.error, + }; InputBorder _getDefaultBorder(ThemeData themeData, InputDecorationTheme defaults) { diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index ad9f6d40f6..55d8008a69 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -1546,12 +1546,10 @@ class _LisTileDefaultsM2 extends ListTileThemeData { Color? get tileColor => Colors.transparent; @override - TextStyle? get titleTextStyle { - return switch (style!) { - ListTileStyle.drawer => _textTheme.bodyLarge, - ListTileStyle.list => _textTheme.titleMedium, - }; - } + TextStyle? get titleTextStyle => switch (style!) { + ListTileStyle.drawer => _textTheme.bodyLarge, + ListTileStyle.list => _textTheme.titleMedium, + }; @override TextStyle? get subtitleTextStyle => _textTheme.bodyMedium! @@ -1564,15 +1562,13 @@ class _LisTileDefaultsM2 extends ListTileThemeData { Color? get selectedColor => _theme.colorScheme.primary; @override - Color? get iconColor { - return switch (_theme.brightness) { - // For the sake of backwards compatibility, the default for unselected - // tiles is Colors.black45 rather than colorScheme.onSurface.withAlpha(0x73). - Brightness.light => Colors.black45, - // null -> use current icon theme color - Brightness.dark => null, - }; - } + Color? get iconColor => switch (_theme.brightness) { + // For the sake of backwards compatibility, the default for unselected + // tiles is Colors.black45 rather than colorScheme.onSurface.withAlpha(0x73). + Brightness.light => Colors.black45, + // null -> use current icon theme color + Brightness.dark => null, + }; } // BEGIN GENERATED TOKEN PROPERTIES - LisTile diff --git a/packages/flutter/lib/src/material/range_slider.dart b/packages/flutter/lib/src/material/range_slider.dart index 5c61108eb1..067f011d41 100644 --- a/packages/flutter/lib/src/material/range_slider.dart +++ b/packages/flutter/lib/src/material/range_slider.dart @@ -1106,14 +1106,12 @@ class _RenderRangeSlider extends RenderBox with RelayoutWhenSystemFontsChangeMix } } - bool get showValueIndicator { - return switch (_sliderTheme.showValueIndicator!) { - ShowValueIndicator.onlyForDiscrete => isDiscrete, - ShowValueIndicator.onlyForContinuous => !isDiscrete, - ShowValueIndicator.always => true, - ShowValueIndicator.never => false, - }; - } + bool get showValueIndicator => switch (_sliderTheme.showValueIndicator!) { + ShowValueIndicator.onlyForDiscrete => isDiscrete, + ShowValueIndicator.onlyForContinuous => !isDiscrete, + ShowValueIndicator.always => true, + ShowValueIndicator.never => false, + }; Size get _thumbSize => _sliderTheme.rangeThumbShape!.getPreferredSize(isEnabled, isDiscrete); diff --git a/packages/flutter/lib/src/material/slider.dart b/packages/flutter/lib/src/material/slider.dart index b4404e12c4..0d4843bd93 100644 --- a/packages/flutter/lib/src/material/slider.dart +++ b/packages/flutter/lib/src/material/slider.dart @@ -1391,14 +1391,12 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin { } } - bool get showValueIndicator { - return switch (_sliderTheme.showValueIndicator!) { - ShowValueIndicator.onlyForDiscrete => isDiscrete, - ShowValueIndicator.onlyForContinuous => !isDiscrete, - ShowValueIndicator.always => true, - ShowValueIndicator.never => false, - }; - } + bool get showValueIndicator => switch (_sliderTheme.showValueIndicator!) { + ShowValueIndicator.onlyForDiscrete => isDiscrete, + ShowValueIndicator.onlyForContinuous => !isDiscrete, + ShowValueIndicator.always => true, + ShowValueIndicator.never => false, + }; double get _adjustmentUnit { switch (_platform) { diff --git a/packages/flutter/lib/src/rendering/editable.dart b/packages/flutter/lib/src/rendering/editable.dart index 8061bc3835..4b2a973bb7 100644 --- a/packages/flutter/lib/src/rendering/editable.dart +++ b/packages/flutter/lib/src/rendering/editable.dart @@ -1670,12 +1670,10 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, Axis get _viewportAxis => _isMultiline ? Axis.vertical : Axis.horizontal; - Offset get _paintOffset { - return switch (_viewportAxis) { - Axis.horizontal => Offset(-offset.pixels, 0.0), - Axis.vertical => Offset(0.0, -offset.pixels), - }; - } + Offset get _paintOffset => switch (_viewportAxis) { + Axis.horizontal => Offset(-offset.pixels, 0.0), + Axis.vertical => Offset(0.0, -offset.pixels), + }; double get _viewportExtent { assert(hasSize); diff --git a/packages/flutter/lib/src/rendering/shifted_box.dart b/packages/flutter/lib/src/rendering/shifted_box.dart index bde334853c..a32ab7ff14 100644 --- a/packages/flutter/lib/src/rendering/shifted_box.dart +++ b/packages/flutter/lib/src/rendering/shifted_box.dart @@ -670,14 +670,12 @@ class RenderConstrainedOverflowBox extends RenderAligningShiftedBox { } @override - bool get sizedByParent { - return switch (fit) { - OverflowBoxFit.max => true, - // If deferToChild, the size will be as small as its child when non-overflowing, - // thus it cannot be sizedByParent. - OverflowBoxFit.deferToChild => false, - }; - } + bool get sizedByParent => switch (fit) { + OverflowBoxFit.max => true, + // If deferToChild, the size will be as small as its child when non-overflowing, + // thus it cannot be sizedByParent. + OverflowBoxFit.deferToChild => false, + }; @override @protected diff --git a/packages/flutter/lib/src/widgets/actions.dart b/packages/flutter/lib/src/widgets/actions.dart index dfdb409448..c46ca8be73 100644 --- a/packages/flutter/lib/src/widgets/actions.dart +++ b/packages/flutter/lib/src/widgets/actions.dart @@ -1338,12 +1338,10 @@ class _FocusableActionDetectorState extends State { } } - bool get _canRequestFocus { - return switch (MediaQuery.maybeNavigationModeOf(context)) { - NavigationMode.traditional || null => widget.enabled, - NavigationMode.directional => true, - }; - } + bool get _canRequestFocus => switch (MediaQuery.maybeNavigationModeOf(context)) { + NavigationMode.traditional || null => widget.enabled, + NavigationMode.directional => true, + }; // This global key is needed to keep only the necessary widgets in the tree // while maintaining the subtree's state. diff --git a/packages/flutter/lib/src/widgets/scroll_physics.dart b/packages/flutter/lib/src/widgets/scroll_physics.dart index 836d425214..e6a0db784b 100644 --- a/packages/flutter/lib/src/widgets/scroll_physics.dart +++ b/packages/flutter/lib/src/widgets/scroll_physics.dart @@ -787,12 +787,10 @@ class BouncingScrollPhysics extends ScrollPhysics { double get dragStartDistanceMotionThreshold => 3.5; @override - double get maxFlingVelocity { - return switch (decelerationRate) { - ScrollDecelerationRate.fast => kMaxFlingVelocity * 8.0, - ScrollDecelerationRate.normal => super.maxFlingVelocity, - }; - } + double get maxFlingVelocity => switch (decelerationRate) { + ScrollDecelerationRate.fast => kMaxFlingVelocity * 8.0, + ScrollDecelerationRate.normal => super.maxFlingVelocity, + }; @override SpringDescription get spring { diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index 27bf6ee2fc..57b55cb8fd 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -570,14 +570,12 @@ class ScrollableState extends State with TickerProviderStateMixin, R /// /// Used by [EdgeDraggingAutoScroller] to progress the position forward when a /// drag gesture reaches the edge of the [Viewport]. - Offset get deltaToScrollOrigin { - return switch (axisDirection) { - AxisDirection.up => Offset(0, -position.pixels), - AxisDirection.down => Offset(0, position.pixels), - AxisDirection.left => Offset(-position.pixels, 0), - AxisDirection.right => Offset(position.pixels, 0), - }; - } + Offset get deltaToScrollOrigin => switch (axisDirection) { + AxisDirection.up => Offset(0, -position.pixels), + AxisDirection.down => Offset(0, position.pixels), + AxisDirection.left => Offset(-position.pixels, 0), + AxisDirection.right => Offset(position.pixels, 0), + }; ScrollController get _effectiveScrollController => widget.controller ?? _fallbackScrollController!; diff --git a/packages/flutter/lib/src/widgets/scrollbar.dart b/packages/flutter/lib/src/widgets/scrollbar.dart index adc181d57b..9925d47f6e 100644 --- a/packages/flutter/lib/src/widgets/scrollbar.dart +++ b/packages/flutter/lib/src/widgets/scrollbar.dart @@ -395,12 +395,11 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter { // Track Offsets // The track is offset by only padding. double get _totalTrackMainAxisOffsets => _isVertical ? padding.vertical : padding.horizontal; - double get _leadingTrackMainAxisOffset { - return switch (_resolvedOrientation) { - ScrollbarOrientation.left || ScrollbarOrientation.right => padding.top, - ScrollbarOrientation.top || ScrollbarOrientation.bottom => padding.left, - }; - } + + double get _leadingTrackMainAxisOffset => switch (_resolvedOrientation) { + ScrollbarOrientation.left || ScrollbarOrientation.right => padding.top, + ScrollbarOrientation.top || ScrollbarOrientation.bottom => padding.left, + }; Rect? _thumbRect; // The current scroll position + _leadingThumbMainAxisOffset diff --git a/packages/flutter/lib/src/widgets/shortcuts.dart b/packages/flutter/lib/src/widgets/shortcuts.dart index 29b0fbe25d..cad42abfe2 100644 --- a/packages/flutter/lib/src/widgets/shortcuts.dart +++ b/packages/flutter/lib/src/widgets/shortcuts.dart @@ -545,9 +545,7 @@ class SingleActivator with Diagnosticable, MenuSerializableShortcut implements S final bool includeRepeats; @override - Iterable get triggers { - return [trigger]; - } + Iterable get triggers => [trigger]; bool _shouldAcceptModifiers(Set pressed) { return control == pressed.intersection(_controlSynonyms).isNotEmpty diff --git a/packages/flutter/lib/src/widgets/sliver_resizing_header.dart b/packages/flutter/lib/src/widgets/sliver_resizing_header.dart index 0be79c3f5b..b3e51a56d7 100644 --- a/packages/flutter/lib/src/widgets/sliver_resizing_header.dart +++ b/packages/flutter/lib/src/widgets/sliver_resizing_header.dart @@ -136,13 +136,11 @@ class _RenderSliverResizingHeader extends RenderSliver with SlottedContainerRend RenderBox? get child => childForSlot(_Slot.child); @override - Iterable get children { - return [ - if (minExtentPrototype != null) minExtentPrototype!, - if (maxExtentPrototype != null) maxExtentPrototype!, - if (child != null) child!, - ]; - } + Iterable get children => [ + if (minExtentPrototype != null) minExtentPrototype!, + if (maxExtentPrototype != null) maxExtentPrototype!, + if (child != null) child!, + ]; double boxExtent(RenderBox box) { assert(box.hasSize); diff --git a/packages/flutter_tools/lib/src/android/java.dart b/packages/flutter_tools/lib/src/android/java.dart index 47fa7d9f61..44d3f83647 100644 --- a/packages/flutter_tools/lib/src/android/java.dart +++ b/packages/flutter_tools/lib/src/android/java.dart @@ -123,14 +123,12 @@ class Java { /// /// This map should be used as the environment when invoking any Java-dependent /// processes, such as Gradle or Android SDK tools (avdmanager, sdkmanager, etc.) - Map get environment { - return { - if (javaHome != null) javaHomeEnvironmentVariable: javaHome!, - 'PATH': _fileSystem.path.dirname(binaryPath) + - _os.pathVarSeparator + - _platform.environment['PATH']!, - }; - } + Map get environment => { + if (javaHome != null) javaHomeEnvironmentVariable: javaHome!, + 'PATH': _fileSystem.path.dirname(binaryPath) + + _os.pathVarSeparator + + _platform.environment['PATH']!, + }; /// Returns the version of java in the format \d(.\d)+(.\d)+ /// Returns null if version could not be determined. diff --git a/packages/flutter_tools/lib/src/base/os.dart b/packages/flutter_tools/lib/src/base/os.dart index c2ecba17d7..7bee75b492 100644 --- a/packages/flutter_tools/lib/src/base/os.dart +++ b/packages/flutter_tools/lib/src/base/os.dart @@ -633,16 +633,14 @@ enum HostPlatform { windows_x64, windows_arm64; - String get platformName { - return switch (this) { - HostPlatform.darwin_x64 => 'x64', - HostPlatform.darwin_arm64 => 'arm64', - HostPlatform.linux_x64 => 'x64', - HostPlatform.linux_arm64 => 'arm64', - HostPlatform.windows_x64 => 'x64', - HostPlatform.windows_arm64 => 'arm64', - }; - } + String get platformName => switch (this) { + HostPlatform.darwin_x64 => 'x64', + HostPlatform.darwin_arm64 => 'arm64', + HostPlatform.linux_x64 => 'x64', + HostPlatform.linux_arm64 => 'arm64', + HostPlatform.windows_x64 => 'x64', + HostPlatform.windows_arm64 => 'arm64', + }; } String getNameForHostPlatform(HostPlatform platform) { diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart index a9477c746c..50e076beaa 100644 --- a/packages/flutter_tools/lib/src/build_info.dart +++ b/packages/flutter_tools/lib/src/build_info.dart @@ -649,23 +649,19 @@ enum AndroidArch { x86, x86_64; - String get archName { - return switch (this) { - AndroidArch.armeabi_v7a => 'armeabi-v7a', - AndroidArch.arm64_v8a => 'arm64-v8a', - AndroidArch.x86_64 => 'x86_64', - AndroidArch.x86 => 'x86' - }; - } + String get archName => switch (this) { + AndroidArch.armeabi_v7a => 'armeabi-v7a', + AndroidArch.arm64_v8a => 'arm64-v8a', + AndroidArch.x86_64 => 'x86_64', + AndroidArch.x86 => 'x86', + }; - String get platformName { - return switch (this) { - AndroidArch.armeabi_v7a => 'android-arm', - AndroidArch.arm64_v8a => 'android-arm64', - AndroidArch.x86_64 => 'android-x64', - AndroidArch.x86 => 'android-x86' - }; - } + String get platformName => switch (this) { + AndroidArch.armeabi_v7a => 'android-arm', + AndroidArch.arm64_v8a => 'android-arm64', + AndroidArch.x86_64 => 'android-x64', + AndroidArch.x86 => 'android-x86', + }; } /// The default set of iOS device architectures to build for. diff --git a/packages/flutter_tools/lib/src/dart/analysis.dart b/packages/flutter_tools/lib/src/dart/analysis.dart index c848d56881..201e9057ff 100644 --- a/packages/flutter_tools/lib/src/dart/analysis.dart +++ b/packages/flutter_tools/lib/src/dart/analysis.dart @@ -240,13 +240,11 @@ class AnalysisError implements Comparable { String get _separator => _platform.isWindows ? '-' : '•'; - String get colorSeverity { - return switch (writtenError.severityLevel) { - AnalysisSeverity.error => _terminal.color(writtenError.severity, TerminalColor.red), - AnalysisSeverity.warning => _terminal.color(writtenError.severity, TerminalColor.yellow), - AnalysisSeverity.info || AnalysisSeverity.none => writtenError.severity, - }; - } + String get colorSeverity => switch (writtenError.severityLevel) { + AnalysisSeverity.error => _terminal.color(writtenError.severity, TerminalColor.red), + AnalysisSeverity.warning => _terminal.color(writtenError.severity, TerminalColor.yellow), + AnalysisSeverity.info || AnalysisSeverity.none => writtenError.severity, + }; String get type => writtenError.type; String get code => writtenError.code; diff --git a/packages/flutter_tools/lib/src/doctor_validator.dart b/packages/flutter_tools/lib/src/doctor_validator.dart index 72fdb2a38c..37da16eb1f 100644 --- a/packages/flutter_tools/lib/src/doctor_validator.dart +++ b/packages/flutter_tools/lib/src/doctor_validator.dart @@ -161,14 +161,12 @@ class ValidationResult { final String? statusInfo; final List messages; - String get leadingBox { - return switch (type) { - ValidationType.crash => '[☠]', - ValidationType.missing => '[✗]', - ValidationType.success => '[✓]', - ValidationType.notAvailable || ValidationType.partial => '[!]', - }; - } + String get leadingBox => switch (type) { + ValidationType.crash => '[☠]', + ValidationType.missing => '[✗]', + ValidationType.success => '[✓]', + ValidationType.notAvailable || ValidationType.partial => '[!]', + }; String get coloredLeadingBox { return globals.terminal.color(leadingBox, switch (type) { @@ -179,15 +177,13 @@ class ValidationResult { } /// The string representation of the type. - String get typeStr { - return switch (type) { - ValidationType.crash => 'crash', - ValidationType.missing => 'missing', - ValidationType.success => 'installed', - ValidationType.notAvailable => 'notAvailable', - ValidationType.partial => 'partial', - }; - } + String get typeStr => switch (type) { + ValidationType.crash => 'crash', + ValidationType.missing => 'missing', + ValidationType.success => 'installed', + ValidationType.notAvailable => 'notAvailable', + ValidationType.partial => 'partial', + }; @override String toString() { @@ -237,13 +233,11 @@ class ValidationMessage { bool get isInformation => type == ValidationMessageType.information; - String get indicator { - return switch (type) { - ValidationMessageType.error => '✗', - ValidationMessageType.hint => '!', - ValidationMessageType.information => '•', - }; - } + String get indicator => switch (type) { + ValidationMessageType.error => '✗', + ValidationMessageType.hint => '!', + ValidationMessageType.information => '•', + }; String get coloredIndicator { return globals.terminal.color(indicator, switch (type) { diff --git a/packages/flutter_tools/lib/src/flutter_cache.dart b/packages/flutter_tools/lib/src/flutter_cache.dart index 78bb249779..e0946861f0 100644 --- a/packages/flutter_tools/lib/src/flutter_cache.dart +++ b/packages/flutter_tools/lib/src/flutter_cache.dart @@ -801,11 +801,9 @@ class IosUsbArtifacts extends CachedArtifact { }; @override - Map get environment { - return { - 'DYLD_LIBRARY_PATH': cache.getArtifactDirectory(name).path, - }; - } + Map get environment => { + 'DYLD_LIBRARY_PATH': cache.getArtifactDirectory(name).path, + }; @override bool isUpToDateInner(FileSystem fileSystem) { diff --git a/packages/flutter_tools/lib/src/macos/swift_packages.dart b/packages/flutter_tools/lib/src/macos/swift_packages.dart index 501fc9ebf9..d323495179 100644 --- a/packages/flutter_tools/lib/src/macos/swift_packages.dart +++ b/packages/flutter_tools/lib/src/macos/swift_packages.dart @@ -91,17 +91,15 @@ class SwiftPackage { final TemplateRenderer _templateRenderer; /// Context for the [_swiftPackageTemplate] template. - Map get _templateContext { - return { - 'swiftToolsVersion': minimumSwiftToolchainVersion, - 'packageName': _name, - // Supported platforms can't be empty, so only include if not null. - 'platforms': _formatPlatforms() ?? false, - 'products': _formatProducts(), - 'dependencies': _formatDependencies(), - 'targets': _formatTargets(), - }; - } + Map get _templateContext => { + 'swiftToolsVersion': minimumSwiftToolchainVersion, + 'packageName': _name, + // Supported platforms can't be empty, so only include if not null. + 'platforms': _formatPlatforms() ?? false, + 'products': _formatProducts(), + 'dependencies': _formatDependencies(), + 'targets': _formatTargets(), + }; /// Create a Package.swift using settings from [_templateContext]. void createSwiftPackage() { 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 c0a2d2ad64..cbd758fa7d 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart @@ -1247,13 +1247,11 @@ class FakeAsyncCrashingDoctor extends Doctor { /// overriding the doctor. class FakeDoctorValidatorsProvider implements DoctorValidatorsProvider { @override - List get validators { - return [ - PassingValidator('Passing Validator'), - PassingValidator('Another Passing Validator'), - PassingValidator('Providing validators is fun'), - ]; - } + List get validators => [ + PassingValidator('Passing Validator'), + PassingValidator('Another Passing Validator'), + PassingValidator('Providing validators is fun'), + ]; @override List get workflows => [];