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

@@ -67,18 +67,16 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
final Set<TestScenario> values = Set<TestScenario>.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<String, dynamic>? result;

View File

@@ -59,14 +59,12 @@ class _FilteredChildAnimationPageState extends State<FilteredChildAnimationPage>
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(

View File

@@ -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;

View File

@@ -207,12 +207,10 @@ class ABTest {
return buffer.toString();
}
Set<String> get _allScoreKeys {
return <String>{
..._aResults.keys,
..._bResults.keys,
};
}
Set<String> get _allScoreKeys => <String>{
..._aResults.keys,
..._bResults.keys,
};
/// Returns the summary as a tab-separated spreadsheet.
///

View File

@@ -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")};