fix avoid chat window keyboard overlap ios

Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
This commit is contained in:
Sahil Yeole 2023-09-05 17:58:22 +05:30
parent 048e97e1ee
commit 71dbf0fab2

View File

@ -389,28 +389,27 @@ class _IOSDraggableState extends State<IOSDraggable> with WidgetsBindingObserver
_chatModel = widget.chatModel; _chatModel = widget.chatModel;
_width = widget.width; _width = widget.width;
_height = widget.height; _height = widget.height;
WidgetsBinding.instance?.addObserver(this);
} }
@override checkKeyboard() {
void dispose() { final bottomHeight = MediaQuery.of(context).viewInsets.bottom;
WidgetsBinding.instance?.removeObserver(this); final currentVisible = bottomHeight != 0;
super.dispose();
}
@override
void didChangeMetrics() {
final currentVisible = MediaQuery.of(context).viewInsets.bottom != 0;
// save
if (!_keyboardVisible && currentVisible) { if (!_keyboardVisible && currentVisible) {
_saveHeight = _position.dy; _saveHeight = _position.dy;
} else if (_lastBottomHeight > 0 && !currentVisible) { }
// reset
if (_lastBottomHeight > 0 && bottomHeight == 0) {
setState(() { setState(() {
_position = Offset(_position.dx, _saveHeight); _position = Offset(_position.dx, _saveHeight);
}); });
} else if (_keyboardVisible && currentVisible) { }
final sumHeight = MediaQuery.of(context).viewInsets.bottom + _height;
// onKeyboardVisible
if (_keyboardVisible && currentVisible) {
final sumHeight = bottomHeight + _height;
final contextHeight = MediaQuery.of(context).size.height; final contextHeight = MediaQuery.of(context).size.height;
if (sumHeight + _position.dy > contextHeight) { if (sumHeight + _position.dy > contextHeight) {
final y = contextHeight - sumHeight; final y = contextHeight - sumHeight;
@ -421,11 +420,12 @@ class _IOSDraggableState extends State<IOSDraggable> with WidgetsBindingObserver
} }
_keyboardVisible = currentVisible; _keyboardVisible = currentVisible;
_lastBottomHeight = MediaQuery.of(context).viewInsets.bottom; _lastBottomHeight = bottomHeight;
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
checkKeyboard();
return Stack( return Stack(
children: [ children: [
Positioned( Positioned(