有没有办法检测移动浏览器中使用的 flutter web?
Is there a way to detect flutter web is used in mobile browser?
我知道 Platform
个常量可用于识别将 flutter 构建编译为 运行。
但是有什么方法可以识别用户正在移动端使用 flutter 网站吗?
感谢任何帮助,提前致谢。
您可以查看device_info_plus package, specifically WebBrowserInfo class了解一些相关信息。
您可以使用 package:flutter/foundation.dart
中的 TargetPlatform
class,例如:
defaultTargetPlatform == TargetPlatform.iOS
或者
defaultTargetPlatform == TargetPlatform.android
我相信您可以通过检查平台和屏幕尺寸来做到这一点。
如果平台是web,屏幕尺寸小,肯定是手机浏览器。
GetX 包也有一个名为 isPhone 的方法,你也可以使用它。
bool isTablet = context.isTablet;
bool isPhone = context.isPhone;
bool isAndroid = GetPlatform.isAndroid;
bool isIos = GetPlatform.isIOS;
bool isMacOs = GetPlatform.isMacOS;
bool isWindows = GetPlatform.isWindows;
bool isLinux = GetPlatform.isLinux;
bool isFuchsia = GetPlatform.isFuchsia;
bool isMobile = GetPlatform.isMobile;
bool isWeb = GetPlatform.isWeb;
bool isDesktop = GetPlatform.isDesktop;
bool isLandScape = context.isLandscape;
bool isPortrait = context.isPortrait;
double screenHeight = Get.height;
double screenWidth = Get.width;
我知道 Platform
个常量可用于识别将 flutter 构建编译为 运行。
但是有什么方法可以识别用户正在移动端使用 flutter 网站吗?
感谢任何帮助,提前致谢。
您可以查看device_info_plus package, specifically WebBrowserInfo class了解一些相关信息。
您可以使用 package:flutter/foundation.dart
中的 TargetPlatform
class,例如:
defaultTargetPlatform == TargetPlatform.iOS
或者
defaultTargetPlatform == TargetPlatform.android
我相信您可以通过检查平台和屏幕尺寸来做到这一点。 如果平台是web,屏幕尺寸小,肯定是手机浏览器。
GetX 包也有一个名为 isPhone 的方法,你也可以使用它。
bool isTablet = context.isTablet;
bool isPhone = context.isPhone;
bool isAndroid = GetPlatform.isAndroid;
bool isIos = GetPlatform.isIOS;
bool isMacOs = GetPlatform.isMacOS;
bool isWindows = GetPlatform.isWindows;
bool isLinux = GetPlatform.isLinux;
bool isFuchsia = GetPlatform.isFuchsia;
bool isMobile = GetPlatform.isMobile;
bool isWeb = GetPlatform.isWeb;
bool isDesktop = GetPlatform.isDesktop;
bool isLandScape = context.isLandscape;
bool isPortrait = context.isPortrait;
double screenHeight = Get.height;
double screenWidth = Get.width;