{"id":32285498,"url":"https://github.com/ownii/flutter_bloc_network","last_synced_at":"2026-05-17T09:38:30.440Z","repository":{"id":56829137,"uuid":"203935476","full_name":"Ownii/flutter_bloc_network","owner":"Ownii","description":"Manage flutter bloc objects that gets loaded via network","archived":false,"fork":false,"pushed_at":"2019-12-28T18:32:38.000Z","size":59,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T01:49:26.208Z","etag":null,"topics":["async","bloc","flutter","network"],"latest_commit_sha":null,"homepage":"","language":"Dart","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/Ownii.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-08-23T06:13:36.000Z","updated_at":"2019-12-28T18:32:41.000Z","dependencies_parsed_at":"2022-08-26T14:11:43.429Z","dependency_job_id":null,"html_url":"https://github.com/Ownii/flutter_bloc_network","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Ownii/flutter_bloc_network","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ownii%2Fflutter_bloc_network","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ownii%2Fflutter_bloc_network/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ownii%2Fflutter_bloc_network/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ownii%2Fflutter_bloc_network/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ownii","download_url":"https://codeload.github.com/Ownii/flutter_bloc_network/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ownii%2Fflutter_bloc_network/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280546408,"owners_count":26348722,"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","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["async","bloc","flutter","network"],"created_at":"2025-10-23T01:49:25.309Z","updated_at":"2025-10-23T01:49:26.335Z","avatar_url":"https://github.com/Ownii.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flutter_bloc_network\n\nThis package helps to manage network states used with [flutter_bloc](https://pub.dev/packages/flutter_bloc) by wrapping the loaded content into a NetworkState\n\n## Sample\n\nCheck out the [sample project](./sample) that shows how to load users async and show the different NetworkStates\n\n## Getting Started\n\n## Basic Usage\n\nTo use this plugin, add `flutter_bloc_network` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).\n\n### Bloc\n\nIn your initial state\n```dart\n  NetworkState\u003cMyObject\u003e myObject = NetworkStateUninitialized();\n```\n\nIn Bloc -\u003e mapEventToState\n```dart\n  yield currentState.copyWith({\n    myObject: NetworkStateLoading();\n  });\n  try {\n    MyObject result = await doNetworkStuff();\n    yield currentState.copyWith({\n      myObject: NetworkStateSucceeded(result);\n    });\n  } catch(e) {\n    yield currentState.copyWith({\n      myObject: NetworkStateFailed(e);\n    });\n  }\n```\n\n### Widget      \n\n```dart\nBlocNetworBuilder\u003cMyBloc, MyState, MyEvent, MyObject\u003e(\n  getValue: (state) =\u003e state.myObject,\n  loading: MyLoadingWidget(),\n  initializeEvent: LoadMyObjectEvent(),\n  error: MyErrorWidget(),\n  builder: (BuildContext context, MyObject value) =\u003e MyWidget(value);\n)\n```\n\nproperties\n```dart\nWidget loading;                           // This widget gets shown if the state is NetworkStateLoading\nWidget uninitialized;                     // this widget gets shown if state is NetworkStateUninitialized, if its not set the loading widget gets shown\nbool animateSwitch;                       // Use AnimatedSwitcher on top\nStateWidgetBuilder\u003cT\u003e builder;            // Builder gets called if state is NetworkStateSucceded\nE initializeEvent;                          // this event gets dispatched if state is NetworkStateUninitialized\nStateValueGetter\u003cS, T\u003e getValue;          // get the actual value from the BlocState\nWidget error;                             // This widget gets shown if the state is NetworkStateFailed\nFunction(BuildContext, T) onSucceeded;    // This function gets called if the state changed to NetworkStateSucceeded\nFunction(BuildContext, dynamic) onFailed; // This function gets called if the state changed to NetworkStateFailed\n```\n\n## Usage with custom bloc or without bloc\n\nYou can use the **NetworkStateWidget** to use **NetworkState** without BlocBuilder. So you can use your own BlocBuilder or use it in different situations where you dont want a BlocBuilder.\n\n### NetworkStateWidget\n\n```dart\nNetworkStateWidget\u003cMyObject\u003e(\n  state: myNetworkStateObject,\n  loading: MyLoadingWidget(),\n  error: MyErrorWidget(),\n  builder: (BuildContext context, MyObject value) =\u003e MyWidget(value),\n  initialize: () {\n    myService.startLoadingMyObject();\n  }\n)\n```\n\n```dart\nNetworkState\u003cT\u003e state;          // the NetworkState object\nWidget loading;                 // This widget gets shown if the state is\nWidget error;                   // This widget gets shown if the state is NetworkStateFailed\nbool animateSwitch;             // Use AnimatedSwitcher on top\nWidget uninitialized;           // this widget gets shown if state is NetworkStateUninitialized, if its not set the loading widget gets shownStateWidgetBuilder\u003cT\u003e builder;  // Builder gets called if state is NetworkStateSucceded\nFunction initialize;            // this function gets called if state is NetworkStateUninitialized\n```\n\n## NetworkState without data\n\nIf you wanna represent a NetworkCall that has no response/data you can simply pass void as generic type and pass null for your NetworkStateSucceeded\n\nKeep in mind to not use the passed value in your builder or onSucceeded Listener.\n\nCheck the [sample project](./sample) to see the usage.\n\nIn your initial state\n```dart\nNetworkState\u003cvoid\u003e callWithoutResponse = NetworkStateUninitialized();\n```\n\nIn Bloc -\u003e mapEventToState\n```dart\nyield currentState.copyWith(\n  callWithoutResponse: NetworkStateLoading(),\n);\ntry {\n  await _userService.createUser(event.username, event.age);\n  yield currentState.copyWith(\n    callWithoutResponse: NetworkStateSucceeded(null),\n  );\n} catch(e) {\n  yield currentState.copyWith(\n    callWithoutResponse: NetworkStateFailed(e),\n  );\n}\n```\n\nin your widget\n```dart\nBlocNetworkBuilder\u003cMyBloc, MyState, MyEvent, void\u003e(\n  getValue: (state) =\u003e state.callWithoutResponse,\n  builder: (context, value) =\u003e MySucceededWidget(), // dont use value (its null)\n  loading: MyLoadingWidget(),\n  error: MyErrorWidget(),\n  initializeEvent: DoMyNetworkCallEvent(),\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fownii%2Fflutter_bloc_network","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fownii%2Fflutter_bloc_network","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fownii%2Fflutter_bloc_network/lists"}