Unverified Commit 140f5eef authored by Nate's avatar Nate Committed by GitHub

Implement `switch` expressions in `examples/` and `animation/` (#139882)

Thanks so much for approving the previous PR (#139048) a couple weeks ago!

This one is the same, except it's covering files in `examples/` and `packages/flutter/lib/src/animation/`.

(solving issue #136139)
parent 6a61e878
...@@ -366,12 +366,10 @@ class ColorChip extends StatelessWidget { ...@@ -366,12 +366,10 @@ class ColorChip extends StatelessWidget {
static Color contrastColor(Color color) { static Color contrastColor(Color color) {
final Brightness brightness = ThemeData.estimateBrightnessForColor(color); final Brightness brightness = ThemeData.estimateBrightnessForColor(color);
switch (brightness) { return switch (brightness) {
case Brightness.dark: Brightness.dark => Colors.white,
return Colors.white; Brightness.light => Colors.black,
case Brightness.light: };
return Colors.black;
}
} }
@override @override
......
...@@ -33,12 +33,10 @@ class Diagonal extends SlottedMultiChildRenderObjectWidget<DiagonalSlot, RenderB ...@@ -33,12 +33,10 @@ class Diagonal extends SlottedMultiChildRenderObjectWidget<DiagonalSlot, RenderB
@override @override
Widget? childForSlot(DiagonalSlot slot) { Widget? childForSlot(DiagonalSlot slot) {
switch (slot) { return switch (slot) {
case DiagonalSlot.topLeft: DiagonalSlot.topLeft => topLeft,
return topLeft; DiagonalSlot.bottomRight => bottomRight,
case DiagonalSlot.bottomRight: };
return bottomRight;
}
} }
// The [createRenderObject] and [updateRenderObject] methods configure the // The [createRenderObject] and [updateRenderObject] methods configure the
......
...@@ -272,14 +272,11 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide ...@@ -272,14 +272,11 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
} }
String _getStatus(CalculationState state) { String _getStatus(CalculationState state) {
switch (state) { return switch (state) {
case CalculationState.loading: CalculationState.loading => 'Loading...',
return 'Loading...'; CalculationState.calculating => 'In Progress',
case CalculationState.calculating: CalculationState.idle => 'Idle',
return 'In Progress'; };
case CalculationState.idle:
return 'Idle';
}
} }
void _updateState(String result, double progress) { void _updateState(String result, double progress) {
......
...@@ -48,20 +48,14 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -48,20 +48,14 @@ class _MyHomePageState extends State<MyHomePage> {
} }
static Widget get _buttonText { static Widget get _buttonText {
switch (defaultTargetPlatform) { return switch (defaultTargetPlatform) {
case TargetPlatform.android: TargetPlatform.android => const Text('Continue in Android view'),
return const Text('Continue in Android view'); TargetPlatform.iOS => const Text('Continue in iOS view'),
case TargetPlatform.iOS: TargetPlatform.windows => const Text('Continue in Windows view'),
return const Text('Continue in iOS view'); TargetPlatform.macOS => const Text('Continue in macOS view'),
case TargetPlatform.windows: TargetPlatform.linux => const Text('Continue in Linux view'),
return const Text('Continue in Windows view'); TargetPlatform.fuchsia => throw UnimplementedError('Platform not yet implemented'),
case TargetPlatform.macOS: };
return const Text('Continue in macOS view');
case TargetPlatform.linux:
return const Text('Continue in Linux view');
case TargetPlatform.fuchsia:
throw UnimplementedError('Platform not yet implemented');
}
} }
Future<void> _launchPlatformCount() async { Future<void> _launchPlatformCount() async {
......
...@@ -269,16 +269,12 @@ abstract class Animation<T> extends Listenable implements ValueListenable<T> { ...@@ -269,16 +269,12 @@ abstract class Animation<T> extends Listenable implements ValueListenable<T> {
/// * "&#x23ED;": [AnimationStatus.completed] ([value] == 1.0) /// * "&#x23ED;": [AnimationStatus.completed] ([value] == 1.0)
/// * "&#x23EE;": [AnimationStatus.dismissed] ([value] == 0.0) /// * "&#x23EE;": [AnimationStatus.dismissed] ([value] == 0.0)
String toStringDetails() { String toStringDetails() {
switch (status) { return switch (status) {
case AnimationStatus.forward: AnimationStatus.forward => '\u25B6', // >
return '\u25B6'; // > AnimationStatus.reverse => '\u25C0', // <
case AnimationStatus.reverse: AnimationStatus.completed => '\u23ED', // >>|
return '\u25C0'; // < AnimationStatus.dismissed => '\u23EE', // |<<
case AnimationStatus.completed: };
return '\u23ED'; // >>|
case AnimationStatus.dismissed:
return '\u23EE'; // |<<
}
} }
} }
......
...@@ -307,12 +307,12 @@ class ReverseAnimation extends Animation<double> ...@@ -307,12 +307,12 @@ class ReverseAnimation extends Animation<double>
double get value => 1.0 - parent.value; double get value => 1.0 - parent.value;
AnimationStatus _reverseStatus(AnimationStatus status) { AnimationStatus _reverseStatus(AnimationStatus status) {
switch (status) { return switch (status) {
case AnimationStatus.forward: return AnimationStatus.reverse; AnimationStatus.forward => AnimationStatus.reverse,
case AnimationStatus.reverse: return AnimationStatus.forward; AnimationStatus.reverse => AnimationStatus.forward,
case AnimationStatus.completed: return AnimationStatus.dismissed; AnimationStatus.completed => AnimationStatus.dismissed,
case AnimationStatus.dismissed: return AnimationStatus.completed; AnimationStatus.dismissed => AnimationStatus.completed,
} };
} }
@override @override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment