{"id":15008388,"url":"https://github.com/dariomatias-dev/flutter_error_handling","last_synced_at":"2025-12-26T11:43:29.860Z","repository":{"id":246591195,"uuid":"821572554","full_name":"dariomatias-dev/flutter_error_handling","owner":"dariomatias-dev","description":"Flutter Error Handling","archived":false,"fork":false,"pushed_at":"2024-12-08T17:57:31.000Z","size":71,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T22:47:00.068Z","etag":null,"topics":["dart","dartlang","flutter","mit","mit-license","solution"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dariomatias-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-28T21:19:54.000Z","updated_at":"2024-12-08T17:57:35.000Z","dependencies_parsed_at":"2024-06-28T22:32:14.983Z","dependency_job_id":"a2020c76-4984-4ab2-b827-60ce59fc6913","html_url":"https://github.com/dariomatias-dev/flutter_error_handling","commit_stats":null,"previous_names":["dariomatias-dev/flutter_error_handling"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dariomatias-dev%2Fflutter_error_handling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dariomatias-dev%2Fflutter_error_handling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dariomatias-dev%2Fflutter_error_handling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dariomatias-dev%2Fflutter_error_handling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dariomatias-dev","download_url":"https://codeload.github.com/dariomatias-dev/flutter_error_handling/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243190866,"owners_count":20250969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dartlang","flutter","mit","mit-license","solution"],"created_at":"2024-09-24T19:18:16.587Z","updated_at":"2025-12-26T11:43:29.824Z","avatar_url":"https://github.com/dariomatias-dev.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Request Management in Flutter\n\nA custom solution offering efficient and flexible management of requests in Flutter applications. Based on the `Either` abstraction, it simplifies handling success and failure scenarios, enabling detailed and tailored management for each situation.\n\nThe solution supports both local management, where specific cases can be handled individually, and global management, which applies consistent rules across all cases. Additionally, a robust global error management system ensures a smooth and uninterrupted user experience, even in unexpected situations.\n\n## Requests\n\n### Defining URLs\n\nIn `ApiService`, define the base URLs that will be used, using `http` in the same scheme as `http`:\n\n__Class with URLs:__\n```dart\nclass Urls {\n  static const httpUrl = 'https://dummyjson.com/http';\n}\n```\n\n__Service Class:__\n```dart\nclass ApiService {\n  static ApiMethods get http =\u003e ApiMethods(\n        baseUrl: Urls.httpUrl,\n      );\n}\n```\n\n### Creating an Instance for Requests\n\nCreate an instance of `ApiService` calling the `get` method on the base URL of the requests:\n\n```dart\nfinal _api = ApiService.http;\n```\n\n### HTTP Requests\n\nTo make requests, call the corresponding HTTP method as shown below:\n\n```dart\nfinal result = await _api.get('[path]');\n```\n\nIf there is a header:\n\n```dart\nfinal result = await _api.get(\n  '[path]',\n  headers: \u003cString, dynamic\u003e{},\n);\n```\n\nWhen there is a body:\n\n```dart\nfinal result = await _api.post(\n  '[path]',\n  headers: \u003cString, dynamic\u003e{},\n  data: \u003cString, dynamic\u003e{},\n);\n```\n\n\u003c/br\u003e\n\n## Handling Results\n\nThe result of the requests will be an instance of Either, which can be either a success or a failure. To handle the result, access the `handle` method, passing a function to obtain the current context, what to do when a success occurs, and what to do when a failure occurs:\n\n```dart\nawait result.handle(\n  getContext: _getContext,\n  success: (value) {},\n  failure: (type, message, handleError) async {},\n);\n```\n\nWhen a failure occurs and you want the default handling to be performed, call the `handleError` function:\n\n```dart\nawait result.handle(\n  getContext: _getContext,\n  success: (value) {},\n  failure: (type, message, handleError) async {\n    await handleError();\n  },\n);\n```\n\nThe default handling will only be applied when `handleError` is called, allowing for local handling as follows:\n\n```dart\nawait result.handle(\n  getContext: _getContext,\n  success: (value) {},\n  failure: (type, message, handleError) async {\n    switch (type) {\n      case FailureType.badGateway:\n        // Local Error Handling\n      default:\n        await handleError();\n    }\n  },\n);\n```\n\n\u003cbr/\u003e\n\n## Autor\n\n\u003cimg style=\"border-radius: 50%\" src=\"https://raw.githubusercontent.com/dariomatias-dev/images/main/my_photo/my_photo.png\" width=\"100px\" alt=\"My photo\"/\u003e\n\n\u003csub\u003e\n  \u003cb\u003eDário Matias\u003c/b\u003e\n\u003c/sub\u003e\n\n\u003cp\u003e\n  Solution developed for study and learning purposes, available under the MIT license.\n\u003c/p\u003e\n\n\u003ca href=\"https://www.linkedin.com/in/dariomatias-dev/\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white\" /\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://www.instagram.com/dariomatias_dev/?theme=dark\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/-Instagram-%23E4405F?style=for-the-badge\u0026logo=instagram\u0026logoColor=white\" /\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdariomatias-dev%2Fflutter_error_handling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdariomatias-dev%2Fflutter_error_handling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdariomatias-dev%2Fflutter_error_handling/lists"}