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: