Async and Practical
URI Parse Lite
Uri.parse(...) breaks a URL string into a structured value with host, pathSegments, and queryParameters. The example reads each piece and prints a compact summary.
Program
Play the program to pull host, page, and step from a fixed URL.
uri_parse_lite.dart
void main() {
var uri = Uri.parse('https://egtry.dev/dart/hello?step=5');
var host = uri.host;
var page = uri.pathSegments.last;
var step = uri.queryParameters['step'] ?? '0';
print('$host $page step=$step');
}
Uri.parse
`Uri.parse(...)` splits a URL string into host, path segments, and query parameters.
pathSegments
`uri.pathSegments` is the path split on `/`, so `.last` gives the leaf name.
queryParameters
`uri.queryParameters['step'] ?? '0'` reads a query value with a safe default.