Julius Baer
Julius Baer

Reputation: 61

how do I create a const URL in Dart?

A (constructor) method (FirebaseOptions) in Dart expects a constant String. Simply passing a string results in a URISyntaxException (even though it's a perfectly fine URL), so apparently I have to encode the String. But the String has to be const and the Uri encoder doesn't return a const String.

mucking about

Upvotes: 2

Views: 953

Answers (1)

Maksym Anurin
Maksym Anurin

Reputation: 3957

It is not possible with Uri implementation due constructor of the Uri class is not constant.

By the way you are able to create own, constant implementation of Uri interface:

class MyConstUri implements Uri {
  const MyConstUri();

  //... implement or generate all necessary methods
}

const Uri reallyConstUri = MyConstUri();

Upvotes: 1

Related Questions