Dart Uri removeFragment()
Syntax & Examples


Uri.removeFragment() method

The `removeFragment` method in Dart's Uri class returns a Uri that is identical to this Uri but without the fragment component.


Syntax of Uri.removeFragment()

The syntax of Uri.removeFragment() method is:

 Uri removeFragment() 

This removeFragment() method of Uri returns a Uri that differs from this only in not having a fragment.

Return Type

Uri.removeFragment() returns value of type Uri.



✐ Example

1 Removing the fragment from a URI

In this example,

  1. We parse a URI with a fragment component.
  2. We call the `removeFragment` method on the URI.
  3. We print the string representation of the modified URI, which excludes the fragment part.

Dart Program

void main() {
  Uri uri = Uri.parse('https://example.com/page#section1');
  Uri uriWithoutFragment = uri.removeFragment();
  print(uriWithoutFragment.toString()); // https://example.com/page
}

Output

https://example.com/page

Summary

In this Dart tutorial, we learned about removeFragment() method of Uri: the syntax and few working examples with output and detailed explanation for each example.