mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
31 lines
522 B
Dart
31 lines
522 B
Dart
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();
|
|
}
|
|
} |