Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
Dart 我们怎么知道屏幕在飞镖中是可触摸的?_Dart_Dart Html - Fatal编程技术网

Dart 我们怎么知道屏幕在飞镖中是可触摸的?

Dart 我们怎么知道屏幕在飞镖中是可触摸的?,dart,dart-html,Dart,Dart Html,为了开发响应性应用程序,我们需要知道用户是否在使用手指或鼠标来适应应用程序的行为。例如,如果屏幕是可触摸的,按钮将更大 我们可以收听Window.onTouch事件和Window.onMouse事件来猜测屏幕是否可触摸 但我想知道应用程序何时加载:在用户进行任何交互之前 我该怎么做呢?您可以使用dart:js并使用此答案中所示的方法 将此添加到index.html 函数hasTouchSupport(){ 在document.documentElement中返回“ontouchstart”;

为了开发响应性应用程序,我们需要知道用户是否在使用手指或鼠标来适应应用程序的行为。例如,如果屏幕是可触摸的,按钮将更大

我们可以收听
Window.onTouch
事件和
Window.onMouse
事件来猜测屏幕是否可触摸

但我想知道应用程序何时加载:在用户进行任何交互之前


我该怎么做呢?

您可以使用
dart:js
并使用此答案中所示的方法

将此添加到index.html


函数hasTouchSupport(){
在document.documentElement中返回“ontouchstart”;
}
像飞镖一样叫它

导入'dart:html';
将“dart:js”导入为js;
bool_hasstouchsupport;
bool get hasTouchSupport{
如果(_hasTouchSupport==null){
_hasTouchSupport=js.context.callMethod('hasTouchSupport');
}
返回\u hasTouchSupport;
}
void main(){
打印(hasTouchSupport);
}
Linux中Dartium/Chrome的
false
true
在我的安卓手机上

据我所知,要拥有一款适用于所有浏览器的产品并不容易

如果您愿意,您可以使用:

将'dart:js'导入为js;
bool-get-isTouchDevice=>js.context['modernizer']['touch'];

似乎不是个好主意。答案有点过时,所以可能有新的发现……我记得有人在Dartisans论坛上提出了一个小lib来实现这一点,但我再也找不到了。对我来说,这已经足够好了,我并不真的想添加现代化功能,只是因为屏幕是可触摸的,并不意味着用户可以用触摸来控制它。带有触摸屏的笔记本电脑越来越普遍。这是一个困难的问题。这就是为什么我在问题下面添加了另一个答案的链接。它很好地解释了这个问题。