Implementing switch expressions in flutter_tools/ (#145632)

This pull request is step 12 in the journey to make this entire repository more readable.

(previous PRs: #139048, #139882, #141591, #142279, #142634, #142793, #143293, #143496, #143634, #143812, #144580)

We're getting close to the end! 😄
This commit is contained in:
Nate
2024-03-29 16:31:19 -06:00
committed by GitHub
parent 7f6685658c
commit a17d4b34f0
20 changed files with 222 additions and 409 deletions

View File

@@ -20,23 +20,15 @@ enum HttpMethod {
}
HttpMethod _fromMethodString(String value) {
final String name = value.toLowerCase();
switch (name) {
case 'get':
return HttpMethod.get;
case 'put':
return HttpMethod.put;
case 'delete':
return HttpMethod.delete;
case 'post':
return HttpMethod.post;
case 'patch':
return HttpMethod.patch;
case 'head':
return HttpMethod.head;
default:
throw StateError('Unrecognized HTTP method $value');
}
return switch (value.toLowerCase()) {
'get' => HttpMethod.get,
'put' => HttpMethod.put,
'delete' => HttpMethod.delete,
'post' => HttpMethod.post,
'patch' => HttpMethod.patch,
'head' => HttpMethod.head,
_ => throw StateError('Unrecognized HTTP method $value'),
};
}
String _toMethodString(HttpMethod method) {