Is there a way to get URL used to launch the app in the code for "Flutter web" app?

Viewed 2194

When building a web app using Dart & Flutter web, can we somehow get the URL used to launch the web app in Dart code? I need to build a web app for a tool that the user will locally deploy on one of his machines and then launch from browser. I need to be able to get the IP address/host name of the server in the web app and then do further gRPC/REST calls.

1 Answers

As mentioned in the comments, you can use something like the following untested example:

import 'dart:html' as html;

...
// Use whichever of the following you need:
final url = html.window.location.href;
final hostname = html.window.location.hostname; // you probably need this one

Related