パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.6

fluri

Fluri は、URI の変更を簡単にできるように設計されたフレンドリーな URI ライブラリです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
3万
いいね数
6
Pub ポイント
140

パッケージをインストール

flutter pub add fluri

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Fluri は、Dart および Flutter アプリケーションにおける URI 操作を簡素化することを目的としたスムーズな URI ライブラリです。直感的でチェーン可能な API を提供し、URI の構築、変更、解析を簡単に実行できます。開発者は、クリーンで読みやすいコードを保ちながら、パス、クエリパラメータ、フラグメントをすばやく追加できます。Workiva によって開発された Fluri は、Android、iOS、Web、macOS、Windows、Linux などすべての主要プラットフォームをサポートしており、堅牢な URL 処理を必要とするクロスプラットフォームプロジェクトに最適です。

用途

  • 動的APIエンドポイントの構築
  • 実行時におけるURLの解析と変更
  • 複雑なクエリ文字列の構築
  • 相対URIと絶対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']}

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト