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

套件詳情v2.0.6

fluri

Fluri 是一個流暢的 URI 庫,旨在讓 URI 變更變得輕鬆。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3萬
喜歡數
6
Pub 分數
140

安裝套件

flutter pub add fluri

套件介紹

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

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

Pub Build Status documentation

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.

With fluri, the above interactions are easy:

import 'package:fluri/fluri.dart';

var fluri = Fluri()
  ..scheme = 'https'
  ..host = 'example.com'
  ..path = 'path/to/resource';

fluri
  ..path = 'new/path'
  ..query = 'foo=true';

fluri.updateQuery({'bar': '10'});

Additional methods like appendToPath and setQueryParam make it easy to build on top of a base URL:

import 'package:fluri/fluri.dart';

var base = Fluri('https://example.com/base/');

var fluri = Fluri.from(base)
  ..appendToPath('path/to/resource')
  ..setQueryParam('count', '10');

Fluri also supports multi-value parameters. To access the query parameters as Map<String, List<String>>, use queryParametersAll (just like the Uri class):

var fluri = Fluri('/resource?format=json&format=text');
print(fluri.queryParameters); // {'format': 'text'}
print(fluri.queryParametersAll); // {'format': ['json', 'text']}

To set a single query parameter to multiple values:

var fluri = Fluri('/resource');
fluri.setQueryParam('format', ['json', 'text']);
print(fluri.queryParametersAll); // {'format': ['json', 'text']}

Using setQueryParam will always replace existing values:

var fluri = Fluri('/resource');
fluri.setQueryParam('format', ['json', 'text']);
fluri.setQueryParam('format', ['binary', 'text']);
print(fluri.queryParametersAll); // {'format': ['binary', 'text']}

You can use the queryParametersAll setter to set the entire query with multi-value param support:

var fluri = Fluri('/resource');
fluri.queryParametersAll = {'format': ['json', 'text'], 'count': ['5']}
print(fluri.queryParametersAll); // {'format': ['json', 'text'], 'count': ['5']}

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:

var fluri = Fluri('/resource?format=json');
fluri.updateQuery({'format': ['binary', 'text'], 'count': '5'}, mergeValues: true);
print(fluri.queryParametersAll); // {'format': ['binary', 'json', 'text'], 'count': ['5']}

所屬分類

原始碼儲存庫

使用此套件的專案