mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
28 lines
789 B
Dart
28 lines
789 B
Dart
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
import 'package:spotube/utils/platform.dart';
|
|
|
|
bool useHasTouch() {
|
|
final hasTouch = useState(kIsMobile);
|
|
|
|
useEffect(() {
|
|
void globalRoute(PointerEvent event) {
|
|
if (hasTouch.value) return;
|
|
hasTouch.value = event.kind == PointerDeviceKind.touch ||
|
|
event.kind == PointerDeviceKind.stylus ||
|
|
event.kind == PointerDeviceKind.invertedStylus;
|
|
}
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
GestureBinding.instance.pointerRouter.addGlobalRoute(globalRoute);
|
|
});
|
|
|
|
return () {
|
|
GestureBinding.instance.pointerRouter.removeGlobalRoute(globalRoute);
|
|
};
|
|
}, []);
|
|
|
|
return hasTouch.value;
|
|
}
|