From 71dbf0fab28c2b1cd4ac6e3b4dbf15b21c1be15a Mon Sep 17 00:00:00 2001 From: Sahil Yeole Date: Tue, 5 Sep 2023 17:58:22 +0530 Subject: [PATCH] fix avoid chat window keyboard overlap ios Signed-off-by: Sahil Yeole --- flutter/lib/common/widgets/overlay.dart | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/flutter/lib/common/widgets/overlay.dart b/flutter/lib/common/widgets/overlay.dart index 89a4184db..bae1f7fc0 100644 --- a/flutter/lib/common/widgets/overlay.dart +++ b/flutter/lib/common/widgets/overlay.dart @@ -389,28 +389,27 @@ class _IOSDraggableState extends State with WidgetsBindingObserver _chatModel = widget.chatModel; _width = widget.width; _height = widget.height; - - WidgetsBinding.instance?.addObserver(this); } - @override - void dispose() { - WidgetsBinding.instance?.removeObserver(this); - super.dispose(); - } - - @override - void didChangeMetrics() { - final currentVisible = MediaQuery.of(context).viewInsets.bottom != 0; + checkKeyboard() { + final bottomHeight = MediaQuery.of(context).viewInsets.bottom; + final currentVisible = bottomHeight != 0; + // save if (!_keyboardVisible && currentVisible) { _saveHeight = _position.dy; - } else if (_lastBottomHeight > 0 && !currentVisible) { + } + + // reset + if (_lastBottomHeight > 0 && bottomHeight == 0) { setState(() { _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; if (sumHeight + _position.dy > contextHeight) { final y = contextHeight - sumHeight; @@ -421,11 +420,12 @@ class _IOSDraggableState extends State with WidgetsBindingObserver } _keyboardVisible = currentVisible; - _lastBottomHeight = MediaQuery.of(context).viewInsets.bottom; + _lastBottomHeight = bottomHeight; } @override Widget build(BuildContext context) { + checkKeyboard(); return Stack( children: [ Positioned(