How can I get the current URL in a Flutter Web App on which the user of the web app currently is?
For example:
app1.website.com app2.website.com
According to the result of the current URL on which the user of the web app currently is, I want to show different content.
This will get you the current url.
Uri.base
From the docs:
When running in a browser this is the current URL of the current page (from window.location.href). https://api.flutter.dev/flutter/dart-core/Uri/base.html
You can find it like this:
import 'dart:html';
var url = window.location.href;
You can use the javascript code, like this:
import 'dart:js' as js;
FlatButton(
child: Text("Button"),
onPressed: () {
print(js.context['location']['href']);
js.context.callMethod("alert", [js.context['location']['href']]);
},
)
Uri.base.path
- 导航器上的当前路径
I simply wanted the first part to know if I was on a main domain or subdomain to create links with.
Uri.base.origin
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.