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

An interface with adapter layer which try to consume Dio in efficient and smart way.

duckma_client #

An interface with adapter layer which try to consume Dio in efficient and smart way.

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
0
pub points
23%
popularity

Publisher

verified publisherduckma.com

An interface with adapter layer which try to consume Dio in efficient and smart way.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dio, meta

More

Packages that depend on duckma_client