Flutter:如何在 运行 浏览器中的 Web 版本时停止显示移动应用程序

Flutter: How to stop showing mobile App when running the Web version in browser

我正在移动和 Web 平台上使用 Flutter 构建应用程序。我有一些不同的 UI 可以从 Web 显示到移动设备。在网页版运行上chrome当我改变浏览器的大小时,它显示移动应用页面。

如何停止这种情况,以便当浏览器布局发生变化时,Web 版本不应该显示移动版本。

我假设您检查布局的大小,例如:

if (layoutSize <= someValue) {
  switchToSmallerLayout();
}

如果你想防止打开移动设备,你可以尝试这样做

bool get _isMobile => Platform.isIOS || Platform.isAndroid;

if (layoutSize <= someValue && !_isMobile) {
  switchToSmallerLayout();
}

这应该可以解决您的问题。