从真实的移动浏览器访问flutter localhost [英] Access flutter localhost from real mobile browser

查看:54
本文介绍了从真实的移动浏览器访问flutter localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个颤抖的Web应用程序,可以轻松地将其部署到PC上的chrome浏览器中.成功部署后:

I have flutter web app which can be easily deploy to chrome browser on my PC. Upon successful deployment:

  1. 控制台

  1. Web浏览器(Chrome)

我正在寻找从我的iPhone浏览器访问以chrome运行的localhost的方法.我的iPhone和PC都连接到同一网络.我获取了网络的IP地址,并尝试通过以下链接从我的iPhone Safari浏览器进行访问:

I'm looking for the way to access localhost running in chrome from my iPhone browser. My iPhone and PC both connected to the same network. I grabbed IP address of the network and tried accessing from my iPhone safari browser with the link as:

http://192.168.43.36:61867

但是它不起作用,并且收到无法访问该站点"消息.我可以执行一些额外的步骤来使flutter本地主机从我的移动浏览器访问吗,或者根本无法通过flutter实现?

But it's NOT working and I'm getting 'The site can't be reached' message. Is there any extra step I can perform to make flutter localhost accessible from my mobile browser or simply its impossible with flutter ?

推荐答案

在开发应用程序时,Flutter不会真正输出JS. flutter run 命令在Chrome浏览器中使用开发编译器启动应用程序,这意味着Dart代码可以直接在Chrome中运行.而且您实际上无法从网络中的另一台计算机访问Chrome,因为它不能充当服务器.

While you're developing your app, Flutter doesn't really output the JS. The flutter run command launches the application using the development compiler in a Chrome browser, which means that Dart code runs directly in Chrome. And you cannot really access Chrome from another machine in the network, as it doesn't act as a server.

您可能应该在JS中编译您的应用(又称为"flutter构建网络" )进行常规部署,以便从其他主机进行访问.您可以使用Python的简单HTTP服务器来服务该应用程序.无需安装任何框架,进行任何配置和编写Python代码.只要确保已安装Python 3并从应用程序的构建输出中运行 python -m http.server 8000 即可.它将在8000端口上为该应用提供服务.

You should probably compile your app in JS (AKA flutter build web) for a regular deployment, to access it from other hosts. You could use Python's simple HTTP server to serve the app. There is no need to install any frameworks, configure anything, and writte Python code. Just make sure you have Python 3 installed and run python -m http.server 8000 from your apps build output. It will serve the app on port 8000.

这篇关于从真实的移动浏览器访问flutter localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆