flutter_request_bloc 1.0.0 copy "flutter_request_bloc: ^1.0.0" to clipboard
flutter_request_bloc: ^1.0.0 copied to clipboard

discontinued

Package that facilitates REST API calls using flutter_bloc and hydrated_bloc.

Flutter Request BLoC #

Package Patreon License

Package that facilitates REST API and other network calls using flutter_bloc and hydrated_bloc.

Before taking a look a this package, please visit the BLoC library page, in order to get familiarized with various concept related to this package.

Usage #

Here's a list of all the components have been built inside this package, and how they interact with one another. If you need more information about how everything works, please take a look at the example folder provided with the project, or create a new issue.

RequestState #

The status of a request made by a Request object inside this library can be represented using the RequestState enum. This are the possible values for the status:

  • RequestState.init
  • RequestState.loading
  • RequestState.loaded
  • RequestState.error

RequestRepository #

The RequestRepository object is the base of this package, and allows you to easily create a repository object that handles all data related to any data request.

It makes use of a BaseService object. This way, the 'request' class logic is completly separated from the downloading and managing aspect of the information it controlls.

The loadData is the method inside the 'request' object that handles all the event-emiting logic related to a repository object. Inside it, you can call the fetchData method you're using at that time.

You can use the autoLoad constructor parameter to automatically call the loadData method upon its initialization.

class TodosRepository extends RequestRepository<TodosService, String> {
  TodosRepository(TodosService service)
      : super(
          service,
          autoLoad: false,
        );

  @override
  Future<String> fetchData() async => (await service.getTodos()).toString();

  void loadError() {
    emit(RequestState.error('ERROR GENERATED!'));
  }

RequestPersistantRepository #

This object is pretty similiar to the one above, with the difference that it has te ability to make its data 'persistant', using the hydrated_bloc library.

It also has the same front-end API as RequestRepository.

class TodosRepository extends RequestPersistantRepository<TodosService, String> {
  TodosRepository(TodosService service) : super(service);

  @override
  Future<String> fetchData() async => (await service.getTodos()).toString();

  void loadError() {
    emit(RequestState.error('ERROR GENERATED!'));
  }

RequestBuilder #

This widget makes contruction UI using Request object pretty easily. It has a RequestWidgetBuilder parameter for each RequestState value, so that the interface can adapt to the current status of the request.

RequestBuilder<TodosCubit, String>(
    onInit: (context, state) => Text('Hello world!'),
    onLoading: (context, state, value) => CircularProgressIndicator(),
    onLoaded: (context, state, value) => Text(value!),
    onError: (context, state, error) => Text(error!),
)

Example #

If you want to take a deeper look at the example, take a look at the example folder provided with the project.

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Built with #

Authors #

License #

This project is licensed under the GNU GPL v3 License - see the LICENSE file for details.

3
likes
120
pub points
66%
popularity

Publisher

verified publisherjesusrp98.page

Package that facilitates REST API calls using flutter_bloc and hydrated_bloc.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (LICENSE)

Dependencies

equatable, flutter, flutter_bloc, hydrated_bloc

More

Packages that depend on flutter_request_bloc