如何检测Flutter应用程序是否正在网络上运行? [英] How can I detect if my Flutter app is running in the web?

查看:190
本文介绍了如何检测Flutter应用程序是否正在网络上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用 Platform.isAndroid Platform.isIOS 等检测操作系统,但是没有类似 Platform.isWeb 的东西,那么我该如何检测呢?

I know that I can detect the operating system with Platform.isAndroid, Platform.isIOS, etc. but there isn't something like Platform.isWeb so how can I detect this?

推荐答案

有一个全局布尔 kIsWeb ,它可以告诉您该应用是否已编译为可以在网络上运行。

There is a global boolean kIsWeb which can tell you whether or not the app was compiled to run on the web.

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

import 'package:flutter/foundation.dart' show kIsWeb;

if (kIsWeb) {
  // running on the web!
} else {
  // NOT running on the web! You can check for additional platforms here.
}

这篇关于如何检测Flutter应用程序是否正在网络上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆