Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 415
Sathish Ramani Avatar asked Jul 21 '20 03:07

Sathish Ramani


People also ask

How do you add a URL on flutter web?

Update the <base href="/"> tag in web/index. html to the path where your app is hosted. For example, to host your Flutter app at my_app. dev/flutter_app , change this tag to <base href="/flutter_app/"> .

How do I open URL in WebView flutter?

Android-only settings: forceWebView – If set to null or false , the URL is opened in the device's default browser; otherwise, the URL is launched in a WebView. enableJavaScript – If set to true , JavaScript is enabled in WebView. enableDomStorage – When the value is set to true , WebView enables DOM storage.

How do you write a URL in flutter?

linkify Flutter plugin can turn text URL and email to a clickable inline text. First, add flutter_linkify plugin to your project. Next import to the file which you are going to implement the code. print("Linkify link = ${link.


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

like image 159
Gregory Conrad Avatar answered Oct 20 '22 02:10

Gregory Conrad