【问题标题】:Is there any way to detect if it runs on web or not?有什么方法可以检测它是否在网络上运行?
【发布时间】:2019-10-02 16:30:19
【问题描述】:

我正在玩 web 的颤振,我想知道是否有办法检测它在 web 或移动设备上运行。 就像你可以像这样检测 iOS 或 Android。

if (Theme.of(context).platform == TargetPlatform.iOS)

有人知道吗?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    还有一个问题here。

    解决办法是使用全局常量if (kIsWeb) {...}

    文档:https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html

    【讨论】:

      【解决方案2】:

      旧答案:

      Flutter Web 在主 Flutter 的另一个分支中处于预览模式。

      我认为当正式发布稳定版本时,您可以使用 Platform.isWeb 之类的东西,而更好的选择是等待或使用 Platform.isWindows 或任何其他 SO。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-28
        • 2011-11-24
        • 2011-06-19
        • 2010-11-04
        • 2013-01-18
        • 2014-08-08
        • 2010-10-28
        • 2016-12-01
        相关资源
        最近更新 更多