Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:core
  3. Uri class
Uri
description

Uri classabstractinterface

A parsed URI, such as a URL.

To create a URI with specific components, useUri.new:

var httpsUri = Uri(    scheme: 'https',    host: 'dart.dev',    path: '/guides/libraries/library-tour',    fragment: 'numbers');print(httpsUri); // https://dart.dev/guides/libraries/library-tour#numbershttpsUri = Uri(    scheme: 'https',    host: 'example.com',    path: '/page/',    queryParameters: {'search': 'blue', 'limit': '10'});print(httpsUri); // https://example.com/page/?search=blue&limit=10final mailtoUri = Uri(    scheme: 'mailto',    path: 'John.Doe@example.com',    queryParameters: {'subject': 'Example'});print(mailtoUri); // mailto:John.Doe@example.com?subject=Example

HTTP and HTTPS URI

To create a URI with https scheme, useUri.https orUri.http:

final httpsUri = Uri.https('example.com', 'api/fetch', {'limit': '10'});print(httpsUri); // https://example.com/api/fetch?limit=10

File URI

To create a URI from file path, useUri.file:

final fileUriUnix =    Uri.file(r'/home/myself/images/image.png', windows: false);print(fileUriUnix); // file:///home/myself/images/image.pngfinal fileUriWindows =    Uri.file(r'C:\Users\myself\Documents\image.png', windows: true);print(fileUriWindows); // file:///C:/Users/myself/Documents/image.png

If the URI is not a file URI, calling this throwsUnsupportedError.

Directory URI

LikeUri.file except that a non-empty URI path ends in a slash.

final fileDirectory =    Uri.directory('/home/myself/data/image', windows: false);print(fileDirectory); // file:///home/myself/data/image/final fileDirectoryWindows = Uri.directory('/data/images', windows: true);print(fileDirectoryWindows); //  file:///data/images/

URI from string

To create a URI from string, useUri.parse orUri.tryParse:

final uri = Uri.parse(    'https://dart.dev/guides/libraries/library-tour#utility-classes');print(uri); // https://dart.devprint(uri.isScheme('https')); // trueprint(uri.origin); // https://dart.devprint(uri.host); // dart.devprint(uri.authority); // dart.devprint(uri.port); // 443print(uri.path); // guides/libraries/library-tourprint(uri.pathSegments); // [guides, libraries, library-tour]print(uri.fragment); // utility-classesprint(uri.hasQuery); // falseprint(uri.data); // null

See also:

Constructors

Uri({String?scheme,String?userInfo,String?host,int?port,String?path,Iterable<String>?pathSegments,String?query,Map<String,dynamic>?queryParameters,String?fragment})
Creates a new URI from its components.
factory
Uri.dataFromBytes(List<int>bytes, {StringmimeType ="application/octet-stream",Map<String,String>?parameters,boolpercentEncoded =false})
Creates adata: URI containing an encoding ofbytes.
factory
Uri.dataFromString(Stringcontent, {String?mimeType,Encoding?encoding,Map<String,String>?parameters,boolbase64 =false})
Creates adata: URI containing thecontent string.
factory
Uri.directory(Stringpath, {bool?windows})
LikeUri.file except that a non-empty URI path ends in a slash.
factory
Uri.file(Stringpath, {bool?windows})
Creates a new file URI from an absolute or relative file path.
factory
Uri.http(Stringauthority, [StringunencodedPath,Map<String,dynamic>?queryParameters])
Creates a newhttp URI from authority, path and query.
factory
Uri.https(Stringauthority, [StringunencodedPath,Map<String,dynamic>?queryParameters])
Creates a newhttps URI from authority, path and query.
factory

Properties

authorityString
The authority component.
no setter
dataUriData?
Access the structure of adata: URI.
no setter
fragmentString
The fragment identifier component.
no setter
hasAbsolutePathbool
Whether the URI has an absolute path (starting with '/').
no setter
hasAuthoritybool
Whether the URI has anauthority component.
no setter
hasEmptyPathbool
Whether the URI has an empty path.
no setter
hasFragmentbool
Whether the URI has a fragment part.
no setter
hashCodeint
Returns a hash code computed astoString().hashCode.
no setteroverride
hasPortbool
Whether the URI has an explicit port.
no setter
hasQuerybool
Whether the URI has a query part.
no setter
hasSchemebool
Whether the URI has ascheme component.
no setter
hostString
The host part of the authority component.
no setter
isAbsolutebool
Whether the URI is absolute.
no setter
originString
Returns the origin of the URI in the form scheme://host:port for theschemes http and https.
no setter
pathString
The path component.
no setter
pathSegmentsList<String>
The URI path split into its segments.
no setter
portint
The port part of the authority component.
no setter
queryString
The query component.
no setter
queryParametersMap<String,String>
The URI query split into a map according to the rulesspecified for FORM post in theHTML 4.01 specification section17.13.4.
no setter
queryParametersAllMap<String,List<String>>
Returns the URI query split into a map according to the rulesspecified for FORM post in theHTML 4.01 specification section17.13.4.
no setter
runtimeTypeType
A representation of the runtime type of the object.
no setterinherited
schemeString
The scheme component of the URI.
no setter
userInfoString
The user info part of the authority component.
no setter

Methods

isScheme(Stringscheme)bool
Whether the scheme of thisUri isscheme.
normalizePath()Uri
Returns a URI where the path has been normalized.
noSuchMethod(Invocationinvocation)→ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeFragment()Uri
Creates aUri that differs from this only in not having a fragment.
replace({String?scheme,String?userInfo,String?host,int?port,String?path,Iterable<String>?pathSegments,String?query,Map<String,dynamic>?queryParameters,String?fragment})Uri
Creates a newUri based on this one, but with some parts replaced.
resolve(Stringreference)Uri
Resolvereference as an URI relative tothis.
resolveUri(Urireference)Uri
Resolvereference as a URI relative tothis.
toFilePath({bool?windows})String
Creates a file path from a file URI.
toString()String
The normalized string representation of the URI.
override

Operators

operator ==(Objectother)bool
A URI is equal to another URI with the same normalized representation.
override

Static Properties

baseUri
The natural base URI for the current platform.
no setter

Static Methods

decodeComponent(StringencodedComponent)String
Decodes the percent-encoding inencodedComponent.
decodeFull(Stringuri)String
Decodes the percent-encoding inuri.
decodeQueryComponent(StringencodedComponent, {Encodingencoding =utf8})String
Decodes the percent-encoding inencodedComponent, convertingpluses to spaces.
encodeComponent(Stringcomponent)String
Encode the stringcomponent using percent-encoding to make itsafe for literal use as a URI component.
encodeFull(Stringuri)String
Encodes the stringuri using percent-encoding to make itsafe for literal use as a full URI.
encodeQueryComponent(Stringcomponent, {Encodingencoding =utf8})String
Encodes the stringcomponent according to the HTML 4.01 rulesfor encoding the posting of a HTML form as a query stringcomponent.
parse(Stringuri, [intstart =0,int?end])Uri
Creates a newUri object by parsing a URI string.
parseIPv4Address(Stringhost, [intstart =0,int?end])List<int>
Parses thehost as an IP version 4 (IPv4) address, returning the addressas a list of 4 bytes in network byte order (big endian).
parseIPv6Address(Stringhost, [intstart =0,int?end])List<int>
Parses thehost as an IP version 6 (IPv6) address.
splitQueryString(Stringquery, {Encodingencoding =utf8})Map<String,String>
Splits thequery into a map according to the rulesspecified for FORM post in theHTML 4.01 specification section17.13.4.
tryParse(Stringuri, [intstart =0,int?end])Uri?
Creates a newUri object by parsing a URI string.
  1. Dart
  2. dart:core
  3. Uri class
dart:core library

[8]ページ先頭

©2009-2025 Movatter.jp