Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何知道我的Flitter web应用程序是在手机上运行还是在桌面上运行_Flutter_Dart_Flutter Web - Fatal编程技术网

Flutter 如何知道我的Flitter web应用程序是在手机上运行还是在桌面上运行

Flutter 如何知道我的Flitter web应用程序是在手机上运行还是在桌面上运行,flutter,dart,flutter-web,Flutter,Dart,Flutter Web,我如何知道我的web颤振应用程序是在桌面上运行还是在移动设备上运行? 我不能使用kIsWeb,因为它说如果应用程序是为web构建的,而不是在web上运行的。 谢谢。也许你可以根据屏幕大小做出决定 var screenSize = MediaQuery.of(context).size; final double width = screenSize.width; final double height = screenSize.height - kToolbarHeight; 如果高度或宽度低

我如何知道我的web颤振应用程序是在桌面上运行还是在移动设备上运行? 我不能使用kIsWeb,因为它说如果应用程序是为web构建的,而不是在web上运行的。
谢谢。

也许你可以根据屏幕大小做出决定

var screenSize = MediaQuery.of(context).size;
final double width = screenSize.width;
final double height = screenSize.height - kToolbarHeight;

如果高度或宽度低于定义的值,您可以估计应用程序是在移动设备上执行的。

为了检测Flatter Web是否在移动设备上运行(仅限iOS或Android),您可以通过两个步骤检测:

  • 使用
    kIsWeb
    检测您是否在网络上
  • 使用
    defaultTargetPlatform
    获取默认平台(它将为您提供操作系统)*
下面是我刚刚在iOS上从Safari调用的
defaultTargetPlatform
的一个测试:

要使用
defaultTargetPlatform
,您需要导入
import'package:flatter/foundation.dart'

例如:

导入“包:flift/foundation.dart”;
最终的isWebMobile=kIsWeb&(defaultTargetPlatform==TargetPlatform.iOS | | defaultTargetPlatform==TargetPlatform.android)
  • defaultTargetPlatform
    已经具备网络感知功能,可以为您进行导航。您可以在此处看到实现: