[英]How detect keyboard finish animation in flutter
In my page I have textfield
and when tap in textfield
open keyboard, Now I want know when finished keyboard open animation.在我的页面中,我有
textfield
,当点击textfield
打开键盘,现在我想知道何时完成键盘打开动画。 When I use any packages about keyboard, keyboard visible property becomes true when starting animation.当我使用任何关于键盘的包时,启动动画时键盘可见属性变为真。
You can add listener to the class you want to observe.您可以将侦听器添加到要观察的类。 For example
例如
class KeyboardTogglePage extends StatefulWidget {
@override
_KeyboardTogglePageState createState() => _KeyboardTogglePageState();
}
class _KeyboardTogglePageState extends State<KeyboardTogglePage>
with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
var isKeyboardOpen = false;
///
/// This routine is invoked when the window metrics have changed.
///
@override
void didChangeMetrics() {
final value = MediaQuery.of(context).viewInsets.bottom;
if (value > 0) {
if (isKeyboardOpen) {
_onKeyboardChanged(false);
}
isKeyboardOpen = false;
} else {
isKeyboardOpen = true;
_onKeyboardChanged(true);
}
}
_onKeyboardChanged(bool isVisible) {
if (isVisible) {
print("KEYBOARD VISIBLE");
} else {
print("KEYBOARD HIDDEN");
}
}
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: TextField(),
),
);
}
}
Credit from here.信用从这里。 https://stackoverflow.com/a/52140861/11612628
https://stackoverflow.com/a/52140861/11612628
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.