mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
chore: fix detection isn't working as drag device enables drag
This commit is contained in:
parent
af60cfc067
commit
aa5d0e535b
27
lib/hooks/configurators/use_has_touch.dart
Normal file
27
lib/hooks/configurators/use_has_touch.dart
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
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;
|
||||||
|
}
|
@ -1,29 +0,0 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/gestures.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
||||||
import 'package:spotube/utils/platform.dart';
|
|
||||||
|
|
||||||
Set<PointerDeviceKind> usePointerDevices() {
|
|
||||||
final devices = useState<Set<PointerDeviceKind>>({
|
|
||||||
if (kIsMobile) PointerDeviceKind.touch,
|
|
||||||
if (kIsDesktop || kIsWeb) PointerDeviceKind.mouse,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
GestureBinding.instance.pointerRouter
|
|
||||||
.addGlobalRoute((PointerEvent event) {
|
|
||||||
if (devices.value.contains(event.kind)) return;
|
|
||||||
devices.value = {
|
|
||||||
...devices.value,
|
|
||||||
event.kind,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return devices.value;
|
|
||||||
}
|
|
@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@ -22,7 +23,7 @@ import 'package:spotube/hooks/configurators/use_deep_linking.dart';
|
|||||||
import 'package:spotube/hooks/configurators/use_disable_battery_optimizations.dart';
|
import 'package:spotube/hooks/configurators/use_disable_battery_optimizations.dart';
|
||||||
import 'package:spotube/hooks/configurators/use_fix_window_stretching.dart';
|
import 'package:spotube/hooks/configurators/use_fix_window_stretching.dart';
|
||||||
import 'package:spotube/hooks/configurators/use_get_storage_perms.dart';
|
import 'package:spotube/hooks/configurators/use_get_storage_perms.dart';
|
||||||
import 'package:spotube/hooks/configurators/use_pointer_devices.dart';
|
import 'package:spotube/hooks/configurators/use_has_touch.dart';
|
||||||
import 'package:spotube/models/database/database.dart';
|
import 'package:spotube/models/database/database.dart';
|
||||||
import 'package:spotube/provider/audio_player/audio_player_streams.dart';
|
import 'package:spotube/provider/audio_player/audio_player_streams.dart';
|
||||||
import 'package:spotube/provider/database/database.dart';
|
import 'package:spotube/provider/database/database.dart';
|
||||||
@ -143,7 +144,7 @@ class Spotube extends HookConsumerWidget {
|
|||||||
final paletteColor =
|
final paletteColor =
|
||||||
ref.watch(paletteProvider.select((s) => s?.dominantColor?.color));
|
ref.watch(paletteProvider.select((s) => s?.dominantColor?.color));
|
||||||
final router = ref.watch(routerProvider);
|
final router = ref.watch(routerProvider);
|
||||||
final pointerDevices = usePointerDevices();
|
final hasTouchSupport = useHasTouch();
|
||||||
|
|
||||||
ref.listen(audioPlayerStreamListenersProvider, (_, __) {});
|
ref.listen(audioPlayerStreamListenersProvider, (_, __) {});
|
||||||
ref.listen(bonsoirProvider, (_, __) {});
|
ref.listen(bonsoirProvider, (_, __) {});
|
||||||
@ -181,10 +182,6 @@ class Spotube extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return MaterialApp.router(
|
return MaterialApp.router(
|
||||||
scrollBehavior: const MaterialScrollBehavior()
|
|
||||||
..copyWith(
|
|
||||||
dragDevices: pointerDevices,
|
|
||||||
),
|
|
||||||
supportedLocales: L10n.all,
|
supportedLocales: L10n.all,
|
||||||
locale: locale.languageCode == "system" ? null : locale,
|
locale: locale.languageCode == "system" ? null : locale,
|
||||||
localizationsDelegates: const [
|
localizationsDelegates: const [
|
||||||
@ -197,8 +194,22 @@ class Spotube extends HookConsumerWidget {
|
|||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
title: 'Spotube',
|
title: 'Spotube',
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
if (kIsDesktop && !kIsMacOS) return DragToResizeArea(child: child!);
|
child = ScrollConfiguration(
|
||||||
return child!;
|
behavior: ScrollConfiguration.of(context).copyWith(
|
||||||
|
dragDevices: hasTouchSupport
|
||||||
|
? {
|
||||||
|
PointerDeviceKind.touch,
|
||||||
|
PointerDeviceKind.stylus,
|
||||||
|
PointerDeviceKind.invertedStylus,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
child: child!,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (kIsDesktop && !kIsMacOS) child = DragToResizeArea(child: child);
|
||||||
|
|
||||||
|
return child;
|
||||||
},
|
},
|
||||||
themeMode: themeMode,
|
themeMode: themeMode,
|
||||||
theme: lightTheme,
|
theme: lightTheme,
|
||||||
|
Loading…
Reference in New Issue
Block a user