我从雇主那里得到了一个让人头疼的任务。 我被要求开发简单的软件,严格只能在Google Chrome上运行, 不能尝试连接到网络(出于安全原因)。
我了解flutter开发,对sdk感到很舒适。 如何开发一个可以使用usb存储器部署的web应用程序呢? 似乎PWA可以是一个选择,但文档缺乏详细说明。
- 系统没有运行本地Web服务器的能力。
- Flutter应用程序必须能够使用JS库,我打算使用jsQR。
我从雇主那里得到了一个让人头疼的任务。 我被要求开发简单的软件,严格只能在Google Chrome上运行, 不能尝试连接到网络(出于安全原因)。
我了解flutter开发,对sdk感到很舒适。 如何开发一个可以使用usb存储器部署的web应用程序呢? 似乎PWA可以是一个选择,但文档缺乏详细说明。
get_server
:您可以在此处找到它。它旨在允许开发人员仅使用flutter而无需依赖外部工具或其他编程/脚本语言来托管自己的HTTP服务器。它还允许(这是相关部分)包装您的flutter Web应用程序并使其在本地网络上运行。create a new flutter project: since I needed the webserver to run on Windows, I had to get flutter ready for that (see here for help)
add get_server
to the new pubspec.yaml
run flutter build web
on your flutter web project, and copy the build/web
output
folder in the root folder of the new project (I renamed the folder while copying since flutter might change the content of the web
folder)
delete all the content of lib/main.dart
paste this (this the actual content of main.dart
)
import 'package:get_server/get_server.dart' as gs;
void main() {
gs.runApp(
gs.GetServerApp(home: gs.FolderWidget('folderName')),
);
}
folderName
是包含Flutter Web应用程序构建的重命名文件夹的名称。localhost:8080
上访问(现在我只使用了get_server
的默认选项)。我还得到了Web服务器(空)GUI作为白色窗口:我想这对于一些有关服务器本身的信息可能会有用,但是如果该窗口关闭,则localhost:8080
将不可用。但是,一旦发布,您应该能够仅使用USB驱动器上的可执行文件,然后使用Chrome连接到它。shelf
让它工作了:我可能会发布一个新问题或答案,这样我就可以把所有的代码放进去。完成后我会通知你的。 - il_boga