Url.fromComponents constructor

Url.fromComponents({
  1. required String protocol,
  2. required String host,
  3. int port = -1,
  4. String path = '',
  5. String query = '',
  6. String fragment = '',
})

Creates a new Url instance from its individual components.

All parts are assembled into a valid URI using Dart's Uri class.

  • host: Hostname or IP address
  • port: Port number or -1 for default
  • path: Path portion of the URL
  • query: Optional query (no ? prefix)
  • fragment: Optional fragment (no # prefix)

Throws a MalformedUrlException if the components do not form a valid URL.

Implementation

Url.fromComponents({
  required String protocol,
  required String host,
  int port = -1,
  String path = '',
  String query = '',
  String fragment = '',
}) : _uri = _buildUri(protocol, host, port, path, query, fragment);