搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目

暂无相关数据。