搜索插件、代码仓与 APP 分类

插件详情v1.2.1

fetch_client

基于 Fetch API 的 http 包客户端,可在 Web 上启用流式和可取消的请求,功能更强大。

Web
近 30 天下载
10.1万
喜欢数
44
Pub 分数
140

安装插件

flutter pub add fetch_client

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Fetch_client 是一个 Flutter 包,提供类似 Fetch API 的接口来发起 HTTP 请求,专为 Web 平台设计。它支持流式响应和可取消的请求,从而提升 Web 应用的性能和用户体验。基于 http 包构建,它提供了现代化且直观的语法,同时保持与 Dart 异步编程模型的兼容性。非常适合希望在面向 Web 的 Flutter 应用中以熟悉且高效的方式处理 HTTP 交互的开发者。

适合场景

  • 在基于Web的Flutter应用中发起HTTP请求
  • 处理来自 API 的流式响应
  • 在导航期间取消正在进行的请求
  • 实现实时数据获取
  • 使用异步操作构建响应式 Web 界面

主要特点

  • Fetch API 类似语法
  • 对流式响应的支持
  • 可取消的请求
  • 以网页为先的设计
  • http 包的轻量级封装

适合对象

  • 专注于网络的Flutter开发者
  • 需要实时数据的应用程序
  • 偏好现代 HTTP 模式的开发人员
  • 需要请求取消的项目
  • 使用流式数据流的团队

使用建议

  • 有限的功能,仅限于网页平台
  • 依赖 http 包进行核心操作
  • 移动平台无原生支持
  • 不适用于超出网页的复杂HTTP场景
  • 在Web上下文中需要仔细处理流

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Fetch Client

pub package package publisher

This package provides package:http client based on Fetch API with WASM support.

It's a drop-in solution for extensions with Manifest V3.

Features

  • WASM-ready internals.
  • Cancel requests.
  • Support data streaming:
    • Get response as Stream.
    • Optionally, send Stream as request body (supported only in Chromium 105+ based browsers).
  • Get access to redirect URL and status.
  • Support non-200 responses (fetch will only fail on network errors).
  • Simulate redirects responses via probe request and artificial location header.

Notes

Large payload

This module maps keepalive to BaseRequest.persistentConnection which is true by default.

Fetch spec says that maximum request size with keepalive flag is 64KiB:

4.5. HTTP-network-or-cache fetch

8.10.5: If the sum of contentLength and inflightKeepaliveBytes is greater than 64 kibibytes, then return a network error.

Source: Fetch. Living Standard — Last Updated 19 June 2023

Therefore if your request is larger than 64KiB (this includes some other data, such as headers) BaseRequest.persistentConnection will be ignored and treated as false.

Request streaming

Request streaming is supported only in Chromium 105+ based browsers and requires the server to use HTTP/2 or HTTP/3.

See MDN compatibility chart and Chrome Developers' blog for more info.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目