keyboard_height_plugin/lib/keyboard_height_plugin.dart
Noah Schairer c2ecf63462 init
2023-04-28 15:21:41 -04:00

29 lines
836 B
Dart

import 'dart:async';
import 'package:flutter/services.dart';
typedef KeyboardHeightCallback = void Function(double height);
class KeyboardHeightPlugin {
static const EventChannel _keyboardHeightEventChannel = const EventChannel('keyboardHeightEventChannel');
StreamSubscription? _keyboardHeightSubscription;
void onKeyboardHeightChanged(KeyboardHeightCallback callback) {
if (_keyboardHeightSubscription != null) {
_keyboardHeightSubscription!.cancel();
}
_keyboardHeightSubscription = _keyboardHeightEventChannel
.receiveBroadcastStream()
.listen((dynamic height) {
callback(height as double);
});
}
void dispose() {
if (_keyboardHeightSubscription != null) {
_keyboardHeightSubscription!.cancel();
}
}
}