Reland "if chains → switch expressions" (#148634)
I did a goof a while back:

Now that [the bug is fixed](e9d403541f), I think we're good to re-implement the if-chains cleanup!
Related:
- https://github.com/flutter/flutter/pull/147793
- https://github.com/flutter/flutter/pull/148556
- https://github.com/flutter/flutter/issues/148548
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user