replace method
Creates a new Uri
based on this one, but with some parts replaced.
This method takes the same parameters as the Uri constructor, and they have the same meaning.
At most one of path
and pathSegments
must be provided. Likewise, at most one of query
and queryParameters
must be provided.
Each part that is not provided will default to the corresponding value from this Uri
instead.
This method is different from Uri.resolve which overrides in a hierarchical manner, and can instead replace each part of a Uri
individually.
Example:
Uri uri1 = Uri.parse("a://b@c:4/d/e?f#g"); Uri uri2 = uri1.replace(scheme: "A", path: "D/E/E", fragment: "G"); print(uri2); // prints "a://b@c:4/D/E/E?f#G"
This method acts similarly to using the Uri
constructor with some of the arguments taken from this Uri
. Example:
Uri uri3 = Uri( scheme: "A", userInfo: uri1.userInfo, host: uri1.host, port: uri1.port, path: "D/E/E", query: uri1.query, fragment: "G"); print(uri3); // prints "a://b@c:4/D/E/E?f#G" print(uri2 == uri3); // prints true.
Using this method can be seen as a shorthand for the Uri
constructor call above, but may also be slightly faster because the parts taken from this Uri
need not be checked for validity again.
Implementation
Uri replace( {String? scheme, String? userInfo, String? host, int? port, String? path, Iterable<String>? pathSegments, String? query, Map<String, dynamic /*String|Iterable<String>*/ >? queryParameters, String? fragment});
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-core/Uri/replace.html