[Flutter/dart]Open a URL that requires encoding
- M.R

- Dec 31, 2022
- 1 min read
Problem
Previously, I wrote an article that it is necessary to encode to open a URL containing Japanese.
However, re-encoding an already encoded URL will result in a different URL.
In other words, before processing to open the URL,
Does the URL require encoding?
Is it already encoded?
will have to be judged. This is a rather complicated process.
Situation
As a situation where the above problem occurs, there is a case opening the URL registered by the user in WebView.
There are often cases where Japanese websites include Japanese in the URL,
When you get the URL with shareExtent, you can receive the encoded one
When the user directly copies and pastes the browser URL, whether the copied URL is encoded or not depends on the browser specifications. In chrome and firefox it is encoded but in safari it is not
In such a case, it becomes a situation that you do not know whether the registered URL is encoded or not.
Solution
All you have to do is conv.
Uri _uri = await Uri.parse(url);
await launchUrl(_uri);





Comments