Sat*_*ani 4 dart flutter flutter-web
使用 Dart 和 Flutter Web 构建 Web 应用程序时,我们能否以某种方式获取用于在 Dart 代码中启动 Web 应用程序的 URL?我需要为一个工具构建一个 Web 应用程序,用户将在他的一台机器上本地部署该工具,然后从浏览器启动。我需要能够在 Web 应用程序中获取服务器的 IP 地址/主机名,然后进行进一步的 gRPC/REST 调用。
正如评论中提到的,您可以使用类似以下未经测试的示例:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
865 次 |
| 最近记录: |