Created
June 30, 2023 11:05
-
-
Save VB10/2a5be90356c1886a18bfb9a90859a4ac to your computer and use it in GitHub Desktop.
flutter status code extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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