duckma_client 0.0.4 copy "duckma_client: ^0.0.4" to clipboard
duckma_client: ^0.0.4 copied to clipboard

An interface with an adapter layer which tries to consume Dio with efficiency and smartly.

duckma_client #

An interface with an adapter layer which tries to consume Dio with efficiency and smartly.

Github stars Pub Version

Installation #

  1. Add this to your packages pubspec.yaml file:
dependencies:
  duckma_client: <^last>
  1. Install it You can install it from the command line:
$ flutter pub get
  1. Import it Now in Dart code, you can use:
import 'package:duckma_client/duckma_client.dart';

Usage #

  1. create a HttpClient instance
  2. create a Dio instance and pass it to HttpClient
  3. Enjoy!

See the example for demonstration usage.

Get request #

Nothing change.

Future<void> getAllUsers() async {
  final Response<List<dynamic>> response = await _client.get(
    Uri(path: '/users'),
  );

  final List<UserModel>? model =
  response.data?.map((e) => UserModel.fromJson(e)).toList();
  if (model != null) {
    _users.addAll(model);
  }
}

See nothing changes, but we have add something cool like the following one:

Future<void> getAllUsers() async {
  final Response<List<dynamic>> response = await _client.get(
    Uri(path: '/users'),
  );

  final List<UserModel> model =
  response.body.map((e) => UserModel.fromJson(e)).toList();
  _users.addAll(model);
}

Here we go, by using body, which came from an extension on Response, We are no more forced to check nullability in every single method, we do this once for all.

response.data = []; // no error, but its a huge problem resetting this property.
response.body = []; // compile error, There isn’t a setter named 'body' in class Response.

And this is only the beginning.

0
likes
100
pub points
17%
popularity

Publisher

verified publisherduckma.com

An interface with an adapter layer which tries to consume Dio with efficiency and smartly.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

connectivity_plus, dio, meta

More

Packages that depend on duckma_client