Flutter 如何检测我的颤振应用程序是否在网络上运行?

Flutter 如何检测我的颤振应用程序是否在网络上运行?,flutter,dart,Flutter,Dart,我知道我可以用Platform.isAndroid,Platform.isIOS等来检测操作系统。但是没有像Platform.isWeb这样的东西,那么我怎么能检测到呢?有一个全局布尔值kIsWeb,它可以告诉你应用程序是否被编译为在网络上运行 文件: 下面编写了一段代码,用于获取运行颤振的OS/web if(kIsWeb) return Text("It's web"); else if(Platform.isAndroid){ return Text("it's Andro

我知道我可以用
Platform.isAndroid
Platform.isIOS
等来检测操作系统。但是没有像
Platform.isWeb
这样的东西,那么我怎么能检测到呢?

有一个全局布尔值
kIsWeb
,它可以告诉你应用程序是否被编译为在网络上运行

文件:


下面编写了一段代码,用于获取运行颤振的OS/web

if(kIsWeb)
   return Text("It's web");

else if(Platform.isAndroid){
     return Text("it's Android"); }

如果你想知道你的操作系统在网络上是什么,你可以使用

    String platform = "";
    if (kIsWeb) {
      platform = getOSInsideWeb();
    }

    String getOSInsideWeb() {
      final userAgent = window.navigator.userAgent.toString().toLowerCase();
      if( userAgent.contains("iphone"))  return "ios";
      if( userAgent.contains("ipad")) return "ios";
      if( userAgent.contains("android"))  return "Android";
    return "Web";
   }

如果一个应用程序被编译为在网络上运行,而现在我正在android/ios上运行一个应用程序,那么这个代码是否可以执行?它是否会给我在网络上运行而不是在android/ios/software/windows上运行的应用程序的能力?别忘了导入它。。。进口“包装:颤振/基础.dart”;有可能检测台式机还是移动设备吗?非常讽刺的是,我们已经有了
isFuchsia
isLinux
,但我仍然必须来这里检查如何检测web。我如何在单元测试期间测试
kIsweb
常量?
    String platform = "";
    if (kIsWeb) {
      platform = getOSInsideWeb();
    }

    String getOSInsideWeb() {
      final userAgent = window.navigator.userAgent.toString().toLowerCase();
      if( userAgent.contains("iphone"))  return "ios";
      if( userAgent.contains("ipad")) return "ios";
      if( userAgent.contains("android"))  return "Android";
    return "Web";
   }