http_client_helper 0.1.4 copy "http_client_helper: ^0.1.4" to clipboard
http_client_helper: ^0.1.4 copied to clipboard

outdated

A Flutter plugin for http request with cancel and retry fuctions.

http_client_helper #

pub package

A Flutter plugin for http request with cancel and retry fuctions.

Usage #

To use this plugin, add http_client_helper as a dependency in your pubspec.yaml file.

Example #

  cancellationToken = new CancellationToken();
    try {
      await HttpClientHelper.get(url,
              cancelToken: cancellationToken,
              millisecondsDelay: 1000,
              retries: 10)
          .then((response) {
        setState(() {
          msg = response.body;
        });
      });
    } on OperationCanceledError catch (e) {
      setState(() {
        msg = "cancel";
      });
    } catch (e) {

    }

If you need other method of http, you can do it with RetryHelper and CancellationToken as you wish. as follow

static Future<Response> get(url,
      {Map<String, String> headers,
      CancellationToken cancelToken,
      int millisecondsDelay = 100,
      int retries = 3}) async {
    cancelToken?.throwIfCancellationRequested();
    return await RetryHelper.tryRun<Response>(() {
      return CancellationTokenSource.register(
          cancelToken, _httpClient.get(url, headers: headers));
    },
        cancelToken: cancelToken,
        millisecondsDelay: millisecondsDelay,
        retries: retries);
  }

Please see the example app of this plugin for a full example.

26
likes
0
pub points
94%
popularity

Publisher

verified publisherfluttercandies.com

A Flutter plugin for http request with cancel and retry fuctions.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, http

More

Packages that depend on http_client_helper