搜尋套件、儲存庫與 APP 分類

套件詳情v5.4.4

w_transport

用於發送 HTTP 請求和開啟 WebSocket 的傳輸庫。與平台無關,內建支援瀏覽器和 Dart VM(甚至支援 SockJS)。包含用於測試的模擬工具。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3.2萬
喜歡數
3
Pub 分數
125

安裝套件

flutter pub add w_transport

套件介紹

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

w_transport 是一個跨平台的 Dart HTTP 與 WebSocket 客戶端程式庫,專為在 Android、iOS、Web、macOS、Windows 和 Linux 上順暢運作而設計。它支援標準 HTTP 請求與 WebSocket 連線,並在原生 WebSocket 無法使用之環境中內建對 SockJS 的相容性。該程式庫包含模擬工具,可協助開發者在無需實際網路呼叫的情況下模擬網路行為,從而簡化測試。非常適合需要與後端服務實現可靠、跨平台通訊的應用程式。

適用情境

  • 從Flutter應用發送HTTP請求
  • 在網頁和移動應用中建立 WebSocket 連接
  • 使用模擬回應測試網路邏輯
  • 使用 WebSockets 建立即時功能
  • 跨平台創建可移植的網路層

主要特色

  • 跨平台 HTTP 和 WebSocket 支持
  • 瀏覽器內建的 SockJS 回退
  • 用於單元測試的模擬工具
  • 跨所有平台的一致性 API
  • 輕量且專注於傳輸層

適合對象

  • 開發多平台 Flutter 應用的開發者
  • 需要在設備間保持一致網路行為的團隊
  • 需要可測試網路代碼的專案
  • 即時資料流應用程式
  • 後端無關的通訊層

使用建議

  • 需要理解 HTTP 和 WebSocket 協議
  • 僅限傳輸層功能(無序列化)
  • 模擬工具僅用於測試,不適用於生產環境
  • 不適用於需要開箱即用快取或驗證的複雜REST客戶端
  • 依賴外部套件進行JSON解析或請求攔截

原始 README

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

w_transport

Pub


Transport library for sending HTTP requests and opening WebSockets.

HTTP support includes plain-text, JSON, form-data, and multipart data, as well as custom encoding. Also supports automatic retrying and request & response interception.

WebSocket support includes native WebSockets in the browser and the VM with the option to use SockJS in the browser.

All transport classes are platform-independent and can be configured to work in the browser or on the Dart VM. Additionally, all transport classes can be mocked out and controlled through an API included with this library.


Docs & Help
Older Versions
Installing

As of version 3.0.0, w_transport will be following a versioning and stability commitment that guarantees a compatibility lifespan of two major versions.

If you're installing w_transport for the first time, simply depend on the latest major version and you'll get all patches and minor versions as they are released:

dependencies:
  w_transport: ^3.0.0

If you're upgrading from version 2.x, you can use the above version range without breaking any existing code. Check out the 3.0.0 upgrade guide.

Importing

The main entry point contains all of the transport classes necessary for sending HTTP requests and establishing WebSocket connections. It is also platform-independent (depends on neither dart:html nor dart:io), which means you can use it to build components, libraries, or APIs that will be reusable in the browser and on the Dart VM.

import 'package:w_transport/w_transport.dart' as transport;

We strongly recommend importing with the prefix transport because there are some classes whose names conflict with classes from the Dart SDK.

The end consumer will make the decision between browser and VM, most likely in a main() block.

Dart SDK

As of version 3.0.0 of the w_transport package, the minimum required Dart SDK version is 1.14.0 (released Jan 28, 2016).

Versioning and Stability

This library follows semver to the best of our interpretation of it. We want this library to be a stable dependency that’s easy to keep current. A good explanation of the versioning scheme that we intend to follow can be seen here from React.js:

https://facebook.github.io/react/blog/2016/02/19/new-versioning-scheme.html

In short: our goal is for every major release to be backwards compatible with the previous major version, giving consumers a lifespan of two major versions to deal with deprecations.

Credits

This library was influenced in many ways by the http package, especially with regard to multipart requests, and served as a useful source for references to pertinent IETF RFCs.

Development

This project leverages the dart_dev package for most of its tooling needs, including static analysis, code formatting, running tests, collecting coverage, and serving examples. Check out the dart_dev readme for more information.

To run integration tests, you'll need two JS dependencies for a SockJS server. Run npm install to download them.

所屬分類

依賴

依賴清單 7 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。