颤振构建只显示空白页



奇怪的是,几天来我无法通过flutter web部署flutter应用程序。我通过Android studio在chrome浏览器中运行和调试Flutter应用程序没有问题,但是一旦我尝试

flutter build web

在/build/web/目录下生成的index.html文件将显示一个空白页面,并出现以下错误:Chrome浏览器错误信息图片

我开始了一个全新的项目,所以错误不会是由于我的糟糕的代码编写:p

有人能帮忙吗?

尝试在project folder中删除.dart-tool文件夹并重新构建项目。

我有同样的错误,改变index.html不工作。我通过删除项目文件夹中的。dart-tool文件夹解决了这个问题。删除它后,IDE显示一些错误,但flutter构建web工作良好。这是原始链接。https://github.com/flutter/flutter/issues/61464 issuecomment - 924577391

index.html中更改为<base href="./">

just在隐私和安全方面清除浏览数据如果在控制台中没有看到任何错误

这是一个老问题,但它似乎永远存在(我也撞到了)。下面是帮助我解决这个问题的方法:

医生说:

Update the <base href="/"> tag in web/index.html to the path where your app is hosted.

在我的情况下,它是htdocs/app,所以base href变成<base href="/app">,这为我解决了这个问题。

当使用flutter build web时,如果它显示一个空白页面,那么这是因为在index.html中缺少基础url。你可以使用

flutter build web --release --web-renderer html --base-href ./

尝试使用此代码重新构建web文件夹。

上下文

我的Flutter网页在移动浏览器上(不是在计算机或模拟器的浏览器上)启动启动屏幕,随后重定向到一个新的路由(包括usePathUrlStrategy,直到这里工作良好。

但是无论路由和屏幕小部件如何,它都只显示一个空白页面。

<标题>

调试在我的Android Chrome上运行的web应用程序通过我的电脑的Chrome开发者控制台通过USBchrome://inspect/#devices说:

MissingPluginException(No implementation found for method getSupportedModes on channel flutter_display_mode)
<标题>

解决方案删除与该库相关的代码flutter_displaymode(手机屏幕的刷新率),否则使用条件导入方法不导入与web不兼容的库。

这是一个与flutter_displaymode无关的例子,尽管如此,它可以帮助你

// The file of your widget where you use the functionality runned only for web.
import 'logic/common/platform_specific.dart' if (dart.library.html) 'logic/common/platform_specific_web.dart';
...
PlatformSpecificImpl.setPageTitle(title);
// File `platform_specific_web.dart`. On web, it setups up the web page.

import 'dart:html' as html;
import 'platform_specific_abstract.dart';
class PlatformSpecificImpl implements PlatformSpecific {
static void setPageTitle(String title) {
html.document.title = title;
}
}
// File `platform_specific.dart`. On desktop and mobile, it does nothing.
import 'platform_specific_abstract.dart';
class PlatformSpecificImpl implements PlatformSpecific {
static void setPageTitle(String title) {}
}
// File `platform_specific_abstract.dart`
abstract class PlatformSpecific {
static void setPageTitle(String title) {}
}

最新更新