{"id":19066079,"url":"https://github.com/vaetas/rxdata","last_synced_at":"2025-04-28T12:24:35.524Z","repository":{"id":56838428,"uuid":"396481799","full_name":"vaetas/rxdata","owner":"vaetas","description":"RxData allows to delegate fetching and caching behavior for your data in your Flutter apps.","archived":false,"fork":false,"pushed_at":"2023-01-21T21:22:01.000Z","size":349,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-18T16:15:33.458Z","etag":null,"topics":["dart","flutter"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/rxdata","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/vaetas.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":"2021-08-15T20:16:12.000Z","updated_at":"2024-10-30T07:13:46.000Z","dependencies_parsed_at":"2023-02-12T12:45:58.957Z","dependency_job_id":null,"html_url":"https://github.com/vaetas/rxdata","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaetas%2Frxdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaetas%2Frxdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaetas%2Frxdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaetas%2Frxdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaetas","download_url":"https://codeload.github.com/vaetas/rxdata/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251312143,"owners_count":21569176,"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","flutter"],"created_at":"2024-11-09T00:54:21.609Z","updated_at":"2025-04-28T12:24:35.492Z","avatar_url":"https://github.com/vaetas.png","language":"C++","readme":"# RxData for Flutter (Riverpod)\n\nRxData allows to delegate fetching and caching behavior for your data. Uses `riverpod` on the\nbackground. Inspired by [Revolut's RxData library](https://github.com/revolut-mobile/RxData).\n\n## Install\n\n```shell\nflutter pub add rxdata\n```\n\n## Usage\n\nFirst, define `DataDelegate` object and specify `Data` type.\n\n```dart\n\nfinal delegateProvider = StateNotifierProvider\u003cDataDelegate\u003cApiResponse\u003e, Data\u003cApiResponse\u003e\u003e((ref) {\n  return DataDelegate\u003cApiResponse\u003e(\n    fromNetwork: () async* {\n      // [fromNetwork] can yield multiple values before closing. You can sequentially fetch data and \n      // and yield them step by step. You should however prevent infinite streams.\n      final response = await getRequest();\n      yield response;\n    },\n    fromStorage: () async {\n      return loadFromSqlite('my_key');\n    },\n    toStorage: (value) async {\n      await saveToSqlite(value, 'my_key');\n    },\n  );\n});\n\n```\n\nThen use standard Riverpod methods to watch/read the data.\n\n```dart\nclass ExampleWidget extends HookConsumerWidget {\n  const ExampleWidget({Key? key}) : super(key: key);\n\n  final DataDelegate\u003cApiResponse\u003e dataDelegate;\n\n  @override\n  Widget build(BuildContext context, WidgetRef ref) {\n    final state = ref.watch(delegateProvider);\n\n    return Scaffold(\n      body: Column(\n        children: [\n          if (state.isLoading) const CircularProgressIndicator(),\n          if (state.hasError) Text(state.error!.toString()),\n          if (state.hasValue) Text(state.value!.toString()),\n        ],\n      ),\n    );\n  }\n}\n```\n\n`Data` class has 3 fields:\n\n* `value`: e.g. `ApiResponse` or whatever data you need;\n* `error`: optional error, you might have `error` and `value` at the same time because `value` is\n  not deleted when error is thrown;\n* `isLoading`: if you can expect `value` or `error` to change soon.\n\nYou can then call `dataDelegate.reload()` to fetch data again. Delegate will handle caching by\nitself, provided that you specified your callbacks.\n\nSee [example project](https://github.com/vaetas/rxdata/blob/main/example/lib/main.dart) for full\nusage.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaetas%2Frxdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaetas%2Frxdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaetas%2Frxdata/lists"}