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: