mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
[Android] Turn page by volume keys
This commit is contained in:
31
lib/utils/volume.dart
Normal file
31
lib/utils/volume.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class VolumeListener {
|
||||
static const channel = EventChannel('venera/volume');
|
||||
|
||||
void Function()? onUp;
|
||||
|
||||
void Function()? onDown;
|
||||
|
||||
VolumeListener({this.onUp, this.onDown});
|
||||
|
||||
StreamSubscription? stream;
|
||||
|
||||
void listen() {
|
||||
stream = channel.receiveBroadcastStream().listen(onEvent);
|
||||
}
|
||||
|
||||
void onEvent(event) {
|
||||
if (event == 1) {
|
||||
onUp!();
|
||||
} else if (event == 2) {
|
||||
onDown!();
|
||||
}
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
stream?.cancel();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user