{"id":15442358,"url":"https://github.com/reginfell/dart-sealed","last_synced_at":"2026-01-11T04:38:18.574Z","repository":{"id":56838722,"uuid":"198679002","full_name":"ReginFell/dart-sealed","owner":"ReginFell","description":"Codegen implementation for using with sealed annotation","archived":false,"fork":false,"pushed_at":"2019-09-24T19:54:44.000Z","size":84,"stargazers_count":23,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-29T11:51:42.433Z","etag":null,"topics":["codegen","dart","flutter","sealed"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ReginFell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-24T17:14:44.000Z","updated_at":"2023-10-08T17:44:07.000Z","dependencies_parsed_at":"2022-08-28T23:12:37.978Z","dependency_job_id":null,"html_url":"https://github.com/ReginFell/dart-sealed","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReginFell%2Fdart-sealed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReginFell%2Fdart-sealed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReginFell%2Fdart-sealed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReginFell%2Fdart-sealed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ReginFell","download_url":"https://codeload.github.com/ReginFell/dart-sealed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249239287,"owners_count":21235832,"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":["codegen","dart","flutter","sealed"],"created_at":"2024-10-01T19:26:59.693Z","updated_at":"2026-01-11T04:38:18.514Z","avatar_url":"https://github.com/ReginFell.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"ᶘ ᵒᴥᵒᶅ \n\n### SealedCodegen - 'when' operator generator for @sealed classes ###\n\n# Getting started #\n\n1) Add these dependencies\n```yaml\ndev_dependencies:\n  build_runner: ^1.0.0\n  sealed_generator: 1.0.1\n```\n\n2) Mark any class you want with @sealed annotation (meta: ^1.1.7) and add part '\u003cfilename\u003e.g.dart' to the header of you file\n\n```dart\nimport 'package:meta/meta.dart';\n\npart 'result.g.dart';\n\n@sealed\nclass Result\u003cT\u003e with SealedResult\u003cT\u003e {}\n\nclass Success\u003cT\u003e extends Result\u003cT\u003e {\n  T value;\n\n  Success(this.value);\n}\n```\n3) run: \n```bash\nflutter packages pub run build_runner build\n```\nGenerator will create a class OriginalClassNameSealed for you to use \n\n```dart\nclass SealedResult\u003cT\u003e {\n  R when\u003cR\u003e({\n      @required R Function(Success\u003cT\u003e) success,\n      @required R Function(Failure\u003cT\u003e) failure,\n    }) {\n    if (this is Success\u003cT\u003e) {\n      return success(this as Success\u003cT\u003e);\n    }\n    if (this is Failure\u003cT\u003e) {\n      return failure(this as Failure\u003cT\u003e);\n    }\n    throw new Exception(\n        'If you got here, probably you forgot to regenerate the classes? Try running flutter packages pub run build_runner build');\n  }\n}\n```\n\n4) Add with(or extends) to your sealed class, for e.g. class Result extends(with) ResultSealed\n\n# Using #\n\nJust create an instance of you sealed class and call when on it, for example: \n\n```dart\n    var resultWidget = result.when(\n        success: (event) =\u003e Text(event.value),\n        failure: (event) =\u003e Text(\"Failure\"),\n        idle: (event) =\u003e Text(\"idle\"),\n      );\n```\n\nAnd that's it, you are ready to use sealed classses with some sort of when \n\nIt is a very early version of the library, mostly a proof of concept, so contributions are highly welcomed\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freginfell%2Fdart-sealed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freginfell%2Fdart-sealed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freginfell%2Fdart-sealed/lists"}