Fluri 是一个流畅的 URI 库,旨在简化 Dart 和 Flutter 应用程序中的 URI 操作。它提供了一个直观、可链式调用的 API,轻松构建、修改和解析 URI。开发者可以无缝地添加路径、查询参数和片段,同时保持代码简洁易读。由 Workiva 开发,Fluri 支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,非常适合需要强大 URL 处理功能的跨平台项目。
适合场景
构建动态 API 端点
在运行时解析和修改URL
构造复杂的查询字符串
处理相对和绝对 URI
使用各种 URL 测试 HTTP 客户端
使用参数管理导航路线
主要特点
流畅的、可链式调用的 API
支持查询参数变异
轻松路径和片段操作
跨平台兼容性
不可变的 URI 构造
强大的解析和序列化
适合对象
需要灵活的 URI 处理的 Flutter 开发人员
需要动态端点生成的API客户端
具有复杂路由或深度链接的应用程序
优先考虑干净、可维护的 URL 逻辑的团队
针对多个平台的项目
使用建议
不适用于低级别URL解析
需要理解 URI 结构
可能会为简单的静态URL增加开销
仅限 URI 特定操作
最好与 dio 或 http 等 HTTP 客户端配合使用
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
fluri
Examples/Usage
Fluri is a fluent URI library for Dart built to make URI mutation easy.
The dart:core.Uri class provides an immutable representation of URIs, which
makes it difficult to incrementally build them or update them at a later time.
If you wanted to build a long URI from the individual pieces, you would do
something like this:
var uri = Uri(
scheme: 'https',
host: 'example.com',
path: 'path/to/resource'
);
If you later wanted to update the path and add a query parameter, you'd have to
do this:
uri = uri.replace(
path: 'new/path',
query: 'foo=true'
);
Now let's say you want update the query without losing what you already have:
var query = Map.from(uri.queryParameters);
query['bar'] = '10';
uri = uri.replace(queryParameters: query);
As you can see, incremental or fluent-style URI mutations become a hassle with
the core Uri class.
Fluri also supports multi-value parameters. To access the query parameters as
Map<String, List<String>>, use queryParametersAll (just like the Uri
class):
Again, if you need to preserve existing query parameters, you can use the
updateQuery method to do so. Set mergeValues: true and any values that you
provide will be merged with existing values: