switch statement cleanup (#148382)
This PR is step 12 in the journey to solve issue #136139 and make the entire Flutter repo more readable. Most of it involves implementing switch expressions, and there's also a few other random things that I wanted to clean up a bit.
This commit is contained in:
@@ -204,18 +204,12 @@ class _ListDemoState extends State<ListDemo> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String layoutText = _dense != null ? ' \u2013 Dense' : '';
|
||||
String? itemTypeText;
|
||||
switch (_itemType) {
|
||||
case _MaterialListType.oneLine:
|
||||
case _MaterialListType.oneLineWithAvatar:
|
||||
itemTypeText = 'Single-line';
|
||||
case _MaterialListType.twoLine:
|
||||
itemTypeText = 'Two-line';
|
||||
case _MaterialListType.threeLine:
|
||||
itemTypeText = 'Three-line';
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
final String? itemTypeText = switch (_itemType) {
|
||||
_MaterialListType.oneLine || _MaterialListType.oneLineWithAvatar => 'Single-line',
|
||||
_MaterialListType.twoLine => 'Two-line',
|
||||
_MaterialListType.threeLine => 'Three-line',
|
||||
null => null,
|
||||
};
|
||||
|
||||
Iterable<Widget> listTiles = items.map<Widget>((String item) => buildListTile(context, item));
|
||||
if (_showDividers != null) {
|
||||
|
||||
@@ -80,29 +80,12 @@ class _CustomRangeThumbShape extends RangeSliderThumbShape {
|
||||
);
|
||||
|
||||
final double size = _thumbSize * sizeTween.evaluate(enableAnimation);
|
||||
late Path thumbPath;
|
||||
switch (textDirection) {
|
||||
case TextDirection.rtl:
|
||||
switch (thumb) {
|
||||
case Thumb.start:
|
||||
thumbPath = _rightTriangle(size, center);
|
||||
case Thumb.end:
|
||||
thumbPath = _leftTriangle(size, center);
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
case TextDirection.ltr:
|
||||
switch (thumb) {
|
||||
case Thumb.start:
|
||||
thumbPath = _leftTriangle(size, center);
|
||||
case Thumb.end:
|
||||
thumbPath = _rightTriangle(size, center);
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
case null:
|
||||
break;
|
||||
}
|
||||
final Path thumbPath = switch ((textDirection!, thumb!)) {
|
||||
(TextDirection.rtl, Thumb.start) => _rightTriangle(size, center),
|
||||
(TextDirection.rtl, Thumb.end) => _leftTriangle(size, center),
|
||||
(TextDirection.ltr, Thumb.start) => _leftTriangle(size, center),
|
||||
(TextDirection.ltr, Thumb.end) => _rightTriangle(size, center),
|
||||
};
|
||||
canvas.drawPath(thumbPath, Paint()..color = colorTween.evaluate(enableAnimation)!);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user