Implement switch expressions in dev/ (#139048)
I previously made a PR (#136140) that used `switch` expressions to make some parts of the Flutter codebase easier to understand. It was assigned to the framework team, and @christopherfujino let me know that it was too large to effectively review and recommended breaking it up into smaller pull requests. Here's a PR that only targets files in the `dev/` directory. Hopefully this will be easier to work with! (solves issue https://github.com/flutter/flutter/issues/136139)
This commit is contained in:
@@ -174,17 +174,12 @@ class _OptionsState extends State<Options> {
|
||||
}
|
||||
|
||||
VisualDensity _profileToDensity(String? profile) {
|
||||
switch (profile) {
|
||||
case 'standard':
|
||||
return VisualDensity.standard;
|
||||
case 'comfortable':
|
||||
return VisualDensity.comfortable;
|
||||
case 'compact':
|
||||
return VisualDensity.compact;
|
||||
case 'custom':
|
||||
default:
|
||||
return widget.model.density;
|
||||
}
|
||||
return switch (profile) {
|
||||
'standard' => VisualDensity.standard,
|
||||
'comfortable' => VisualDensity.comfortable,
|
||||
'compact' => VisualDensity.compact,
|
||||
'custom' || _ => widget.model.density,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -478,14 +478,11 @@ class _TestMenusState extends State<_TestMenus> {
|
||||
void _setCheck(TestMenu item) {
|
||||
debugPrint('App: Set Checkbox item ${item.label}');
|
||||
setState(() {
|
||||
switch (checkboxState) {
|
||||
case false:
|
||||
checkboxState = true;
|
||||
case true:
|
||||
checkboxState = null;
|
||||
case null:
|
||||
checkboxState = false;
|
||||
}
|
||||
checkboxState = switch (checkboxState) {
|
||||
false => true,
|
||||
true => null,
|
||||
null => false,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user