Skip to content

Instantly share code, notes, and snippets.

@VB10
Created June 30, 2023 11:05
Show Gist options
  • Save VB10/2a5be90356c1886a18bfb9a90859a4ac to your computer and use it in GitHub Desktop.
Save VB10/2a5be90356c1886a18bfb9a90859a4ac to your computer and use it in GitHub Desktop.
flutter status code extension
extension IntExtension on int? {
StatusCode get httpStatusCode {
if (this == null) return StatusCode.unknown;
switch (this!) {
case < 200:
return StatusCode.continue_;
case >= 200 && <= 300:
return StatusCode.ok;
case 401:
return StatusCode.unAuthorized;
case >= 400 && <= 500:
return StatusCode.notFound;
default:
return StatusCode.serverError;
}
}
}
enum StatusCode {
ok,
continue_,
unAuthorized,
notFound,
serverError,
unknown,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment