replace abstract method Null safety
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:
final uri1 = Uri.parse(
'http://dart.cn/guides/libraries/library-tour#utility-classes');
final uri2 = uri1.replace(
scheme: 'https',
path: 'guides/libraries/library-tour',
fragment: 'uris');
print(uri2); // https://dart.cn/guides/libraries/library-tour#uris
This method acts similarly to using the Uri
constructor with
some of the arguments taken from this Uri
. Example:
final Uri uri3 = Uri(
scheme: 'https',
userInfo: uri1.userInfo,
host: uri1.host,
port: uri2.port,
path: '/guides/language/language-tour',
query: uri1.query,
fragment: null);
print(uri3); // https://dart.cn/guides/language/language-tour
Using this method can be seen as 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});