Reland "if chains → switch expressions" (#148634)

I did a goof a while back:

![late initialization error](https://github.com/flutter/flutter/assets/10457200/47dc423f-0dd0-4869-9a11-59cb7d1ea46e)

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:
Nate
2024-05-20 11:43:00 -06:00
committed by GitHub
parent 333c076e53
commit 73ecc8a9b2
33 changed files with 194 additions and 297 deletions

View File

@@ -163,14 +163,12 @@ class _OptionsState extends State<Options> {
double sliderValue = 0.0;
String _densityToProfile(VisualDensity density) {
if (density == VisualDensity.standard) {
return 'standard';
} else if (density == VisualDensity.compact) {
return 'compact';
} else if (density == VisualDensity.comfortable) {
return 'comfortable';
}
return 'custom';
return switch (density) {
VisualDensity.standard => 'standard',
VisualDensity.compact => 'compact',
VisualDensity.comfortable => 'comfortable',
_ => 'custom',
};
}
VisualDensity _profileToDensity(String? profile) {

View File

@@ -70,9 +70,7 @@ class PageViewAppState extends State<PageViewApp> {
void switchScrollDirection() {
setState(() {
scrollDirection = (scrollDirection == Axis.vertical)
? Axis.horizontal
: Axis.vertical;
scrollDirection = flipAxis(scrollDirection);
});
}
@@ -113,9 +111,7 @@ class PageViewAppState extends State<PageViewApp> {
AppBar _buildAppBar() {
return AppBar(
title: const Text('PageView'),
actions: <Widget>[
Text(scrollDirection == Axis.horizontal ? 'horizontal' : 'vertical'),
],
actions: <Widget>[Text(scrollDirection.name)],
);
}