搜尋分類、套件與程式碼儲存庫

套件詳情v3.0.0

http_client_helper

一個支援取消與重試功能的 Flutter http 請求外掛。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
41.6萬
喜歡數
32
Pub 分數
160

安裝套件

flutter pub add http_client_helper

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個專為簡化 HTTP 請求而設計的 Flutter 套件,內建取消和重試機制支援。它透過提供乾淨、可重複使用的介面,增強跨多個平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)的網路作業。此套件有助於有效管理請求生命週期,減少樣板程式碼,並在網路波動時提升可靠性。非常適合需要強大且即時回應 API 互動的應用程式。

適用情境

  • 處理帶有自動重試的 API 呼叫
  • 使用取消功能管理併發請求
  • 提升應用在網路延遲期間的回應能力
  • 建構可靠的資料擷取層
  • 簡化 HTTP 操作中的錯誤處理

主要特色

  • 內建請求取消
  • 自動重試邏輯
  • 跨平台相容性
  • 簡單 API 結合
  • 支援各種 HTTP 方法
  • 可設定的重試策略

適合對象

  • 頻繁網路請求的應用
  • 尋求可靠HTTP處理的開發者
  • 需要請求生命週期管理的項目
  • 優先考慮可維護網路程式碼的團隊
  • 需要應對網路不穩定的彈性應用

使用建議

  • 需要理解 async/await 模式
  • 可能需要額外設定以支援複雜的重試規則
  • 不適合非常輕量級的HTTP需求
  • 依賴於底層的 http 包
  • 僅限於 HTTP 特定用例

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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,
                timeRetry: Duration(milliseconds: 100),
                retries: 3,
                timeLimit: Duration(seconds: 5))
            .then((response) {
          setState(() {
            msg = response.body;
          });
        });
      } on TimeoutException catch (_) {
        setState(() {
          msg = "TimeoutException";
        });
      } on OperationCanceledError catch (_) {
        setState(() {
          msg = "cancel";
        });
      } catch (e) {
        setState(() {
          msg = "$e";
        });
      }

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

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案