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