Implement switch expressions in dev/ (#139048)
I previously made a PR (#136140) that used `switch` expressions to make some parts of the Flutter codebase easier to understand. It was assigned to the framework team, and @christopherfujino let me know that it was too large to effectively review and recommended breaking it up into smaller pull requests. Here's a PR that only targets files in the `dev/` directory. Hopefully this will be easier to work with! (solves issue https://github.com/flutter/flutter/issues/136139)
This commit is contained in:
@@ -32,13 +32,11 @@ class ExtendedStandardMessageCodec extends StandardMessageCodec {
|
||||
|
||||
@override
|
||||
dynamic readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
case _dateTime:
|
||||
return DateTime.fromMillisecondsSinceEpoch(buffer.getInt64());
|
||||
case _pair:
|
||||
return Pair(readValue(buffer), readValue(buffer));
|
||||
default: return super.readValueOfType(type, buffer);
|
||||
}
|
||||
return switch (type) {
|
||||
_dateTime => DateTime.fromMillisecondsSinceEpoch(buffer.getInt64()),
|
||||
_pair => Pair(readValue(buffer), readValue(buffer)),
|
||||
_ => super.readValueOfType(type, buffer),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,16 +75,12 @@ class OperationToken extends ExpressionToken {
|
||||
Operation operation;
|
||||
|
||||
static String? opString(Operation operation) {
|
||||
switch (operation) {
|
||||
case Operation.Addition:
|
||||
return ' + ';
|
||||
case Operation.Subtraction:
|
||||
return ' - ';
|
||||
case Operation.Multiplication:
|
||||
return ' \u00D7 ';
|
||||
case Operation.Division:
|
||||
return ' \u00F7 ';
|
||||
}
|
||||
return switch (operation) {
|
||||
Operation.Addition => ' + ',
|
||||
Operation.Subtraction => ' - ',
|
||||
Operation.Multiplication => ' \u00D7 ',
|
||||
Operation.Division => ' \u00F7 ',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -163,14 +163,11 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
|
||||
isScrollable: true,
|
||||
indicator: getIndicator(),
|
||||
tabs: _allPages.map<Tab>((_Page page) {
|
||||
switch (_demoStyle) {
|
||||
case TabsDemoStyle.iconsAndText:
|
||||
return Tab(text: page.text, icon: Icon(page.icon));
|
||||
case TabsDemoStyle.iconsOnly:
|
||||
return Tab(icon: Icon(page.icon));
|
||||
case TabsDemoStyle.textOnly:
|
||||
return Tab(text: page.text);
|
||||
}
|
||||
return switch (_demoStyle) {
|
||||
TabsDemoStyle.iconsAndText => Tab(text: page.text, icon: Icon(page.icon)),
|
||||
TabsDemoStyle.iconsOnly => Tab(icon: Icon(page.icon)),
|
||||
TabsDemoStyle.textOnly => Tab(text: page.text),
|
||||
};
|
||||
}).toList()
|
||||
),
|
||||
),
|
||||
|
||||
@@ -221,18 +221,13 @@ class ExpandingBottomSheetState extends State<ExpandingBottomSheet> with TickerP
|
||||
// Returns the correct width of the ExpandingBottomSheet based on the number of
|
||||
// products in the cart.
|
||||
double _widthFor(int numProducts) {
|
||||
switch (numProducts) {
|
||||
case 0:
|
||||
return _kWidthForCartIcon;
|
||||
case 1:
|
||||
return 136.0;
|
||||
case 2:
|
||||
return 192.0;
|
||||
case 3:
|
||||
return 248.0;
|
||||
default:
|
||||
return 278.0;
|
||||
}
|
||||
return switch (numProducts) {
|
||||
0 => _kWidthForCartIcon,
|
||||
1 => 136.0,
|
||||
2 => 192.0,
|
||||
3 => 248.0,
|
||||
_ => 278.0,
|
||||
};
|
||||
}
|
||||
|
||||
// Returns true if the cart is open or opening and false otherwise.
|
||||
|
||||
@@ -411,20 +411,14 @@ class _PlatformItem extends StatelessWidget {
|
||||
final ValueChanged<GalleryOptions>? onOptionsChanged;
|
||||
|
||||
String _platformLabel(TargetPlatform platform) {
|
||||
switch (platform) {
|
||||
case TargetPlatform.android:
|
||||
return 'Mountain View';
|
||||
case TargetPlatform.fuchsia:
|
||||
return 'Fuchsia';
|
||||
case TargetPlatform.iOS:
|
||||
return 'Cupertino';
|
||||
case TargetPlatform.linux:
|
||||
return 'Material Desktop (linux)';
|
||||
case TargetPlatform.macOS:
|
||||
return 'Material Desktop (macOS)';
|
||||
case TargetPlatform.windows:
|
||||
return 'Material Desktop (Windows)';
|
||||
}
|
||||
return switch (platform) {
|
||||
TargetPlatform.android => 'Mountain View',
|
||||
TargetPlatform.fuchsia => 'Fuchsia',
|
||||
TargetPlatform.iOS => 'Cupertino',
|
||||
TargetPlatform.linux => 'Material Desktop (linux)',
|
||||
TargetPlatform.macOS => 'Material Desktop (macOS)',
|
||||
TargetPlatform.windows => 'Material Desktop (Windows)',
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user