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

<br>

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.
This commit is contained in:
Nate Wilson
2024-10-17 13:25:14 -06:00
committed by GitHub
parent fdbd855fdc
commit 6b1bc456f4
36 changed files with 239 additions and 345 deletions

View File

@@ -85,21 +85,10 @@ class _DraggableScrollableSheetExampleState extends State<DraggableScrollableShe
);
}
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,
};
}
/// A draggable widget that accepts vertical drag gestures

View File

@@ -102,21 +102,10 @@ class _PageViewExampleState extends State<PageViewExample> 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.

View File

@@ -97,12 +97,10 @@ class RenderDiagonal extends RenderBox
// Returns children in hit test order.
@override
Iterable<RenderBox> get children {
return <RenderBox>[
if (_topLeft != null) _topLeft!,
if (_bottomRight != null) _bottomRight!,
];
}
Iterable<RenderBox> get children => <RenderBox>[
if (_topLeft != null) _topLeft!,
if (_bottomRight != null) _bottomRight!,
];
// LAYOUT

View File

@@ -47,16 +47,14 @@ class _MyHomePageState extends State<MyHomePage> {
});
}
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<void> _launchPlatformCount() async {
final int? platformCounter =