if chains → switch expressions (#147793)

Previous "if-chains" pull requests:
- https://github.com/flutter/flutter/pull/144905
- https://github.com/flutter/flutter/pull/144977
- https://github.com/flutter/flutter/pull/145194
- https://github.com/flutter/flutter/pull/146293
- https://github.com/flutter/flutter/pull/147472

<br>

I think this one should be enough to wrap things up!

fixes https://github.com/flutter/flutter/issues/144903

---------

Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
This commit is contained in:
Nate
2024-05-10 00:55:48 -06:00
committed by GitHub
parent c90e18c6f5
commit 4734d80f22
33 changed files with 194 additions and 297 deletions

View File

@@ -307,13 +307,11 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
}
final double flingVelocity = details.velocity.pixelsPerSecond.dy / _backdropHeight;
if (flingVelocity < 0.0) {
_controller.fling(velocity: math.max(2.0, -flingVelocity));
} else if (flingVelocity > 0.0) {
_controller.fling(velocity: math.min(-2.0, -flingVelocity));
} else {
_controller.fling(velocity: _controller.value < 0.5 ? -2.0 : 2.0);
}
_controller.fling(velocity: switch (flingVelocity) {
< 0.0 => math.max(2.0, -flingVelocity),
> 0.0 => math.min(-2.0, -flingVelocity),
_ => _controller.value < 0.5 ? -2.0 : 2.0,
});
}
// Stacks a BackdropPanel, which displays the selected category, on top

View File

@@ -184,21 +184,18 @@ class _ListDemoState extends State<ListDemo> {
}
Widget buildListTile(BuildContext context, String item) {
Widget? secondary;
if (_itemType == _MaterialListType.twoLine) {
secondary = const Text('Additional item information.');
} else if (_itemType == _MaterialListType.threeLine) {
secondary = const Text(
'Even more additional list item information appears on line three.',
);
}
final String? subtitle = switch (_itemType) {
_MaterialListType.oneLine || _MaterialListType.oneLineWithAvatar || null => null,
_MaterialListType.twoLine => 'Additional item information.',
_MaterialListType.threeLine => 'Even more additional list item information appears on line three.',
};
return MergeSemantics(
child: ListTile(
isThreeLine: _itemType == _MaterialListType.threeLine,
dense: _dense,
leading: _showAvatars != null ? ExcludeSemantics(child: CircleAvatar(child: Text(item))) : null,
title: Text('This item represents $item.'),
subtitle: secondary,
subtitle: subtitle != null ? Text(subtitle) : null,
trailing: _showIcons != null ? Icon(Icons.info, color: Theme.of(context).disabledColor) : null,
),
);

View File

@@ -246,13 +246,11 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
}
final double flingVelocity = details.velocity.pixelsPerSecond.dy / _backdropHeight;
if (flingVelocity < 0.0) {
_controller!.fling(velocity: math.max(2.0, -flingVelocity));
} else if (flingVelocity > 0.0) {
_controller!.fling(velocity: math.min(-2.0, -flingVelocity));
} else {
_controller!.fling(velocity: _controller!.value < 0.5 ? -2.0 : 2.0);
}
_controller!.fling(velocity: switch (flingVelocity) {
< 0.0 => math.max(2.0, -flingVelocity),
> 0.0 => math.min(-2.0, -flingVelocity),
_ => _controller!.value < 0.5 ? -2.0 : 2.0,
});
}
void _toggleFrontLayer() {

View File

@@ -337,22 +337,14 @@ class _HighlightSpan {
}
TextStyle? textStyle(SyntaxHighlighterStyle? style) {
if (type == _HighlightType.number) {
return style!.numberStyle;
} else if (type == _HighlightType.comment) {
return style!.commentStyle;
} else if (type == _HighlightType.keyword) {
return style!.keywordStyle;
} else if (type == _HighlightType.string) {
return style!.stringStyle;
} else if (type == _HighlightType.punctuation) {
return style!.punctuationStyle;
} else if (type == _HighlightType.klass) {
return style!.classStyle;
} else if (type == _HighlightType.constant) {
return style!.constantStyle;
} else {
return style!.baseStyle;
}
return switch (type) {
_HighlightType.number => style!.numberStyle,
_HighlightType.comment => style!.commentStyle,
_HighlightType.keyword => style!.keywordStyle,
_HighlightType.string => style!.stringStyle,
_HighlightType.punctuation => style!.punctuationStyle,
_HighlightType.klass => style!.classStyle,
_HighlightType.constant => style!.constantStyle,
};
}
}