fix(player): 修复评论输入聚焦时面板消失
This commit is contained in:
1 parent
226ac5920c
commit
c7b230263a
4 files changed
+399
-280
No files matched your search
@@ -0,0 +1,48 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// Provides the Android IME height even when `adjustNothing` keeps
|
||||
/// `MediaQuery.viewInsets` at zero.
|
||||
class KeyboardInsetNotifier extends ChangeNotifier {
|
||||
KeyboardInsetNotifier._();
|
||||
|
||||
static final KeyboardInsetNotifier instance = KeyboardInsetNotifier._();
|
||||
static const MethodChannel _channel = MethodChannel(
|
||||
'com.stormg.lumadrama/keyboard',
|
||||
);
|
||||
|
||||
/// Raw physical-pixel inset reported by Android.
|
||||
int _inset = 0;
|
||||
bool _started = false;
|
||||
|
||||
int get value => _inset;
|
||||
|
||||
Future<void> start() async {
|
||||
if (_started || kIsWeb || defaultTargetPlatform != TargetPlatform.android) {
|
||||
return;
|
||||
}
|
||||
_started = true;
|
||||
_channel.setMethodCallHandler((call) async {
|
||||
if (call.method != 'insetsChanged') return;
|
||||
_update(call.arguments);
|
||||
});
|
||||
try {
|
||||
_update(await _channel.invokeMethod<Object?>('get'));
|
||||
} catch (_) {
|
||||
// Tests and non-embedded Android hosts may not provide the channel.
|
||||
}
|
||||
}
|
||||
|
||||
void _update(Object? value) {
|
||||
final next = switch (value) {
|
||||
int value => value,
|
||||
num value => value.round(),
|
||||
_ => 0,
|
||||
};
|
||||
if (next == _inset) return;
|
||||
_inset = next;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user