当前位置:网站首页>flutter解决键盘和输入框不适配问题
flutter解决键盘和输入框不适配问题
2022-08-02 07:18:00 【氤氲息】
//是否显示键盘
bool isShowKeyboard = false;
double keyboardSize = Global.screenHeight * 0.4;
@override
void initState() {
super.initState();
//输入框焦点监测
_focusNode.addListener(() {
if (_focusNode.hasFocus) {
//下面这句是当UI被遮挡的时候,遮挡高度大于0时就意味着键盘弹起来了
if (MediaQuery.of(context).viewInsets.bottom > 0) {
//设置为true
isShowKeyboard = true;
}
} else {
isShowKeyboard = false;
}
if (mounted) {
setState(() {
});
}
});
} //软键盘高度
@override
void didChangeMetrics() {
super.didChangeMetrics();
WidgetsBinding.instance!.addPostFrameCallback((_) {
// 以后是安卓零碎并且在焦点聚焦的状况下
if (Platform.isAndroid && _focusNode.hasFocus) {
if (MediaQuery.of(context).viewInsets.bottom > 0) {
isShowKeyboard = true;
} else {
isShowKeyboard = false;
}
if (mounted) {
setState(() {
});
}
}
});
}
//如果isShowKeyboard是true就用下边距为keyboardSize(Global.screenHeight * 0.4),如果是false就是30了
布局中就可以设置bottom: isShowKeyboard ? keyboardSize : 30
边栏推荐
- (2022 Niu Ke Duo School 5) D-Birds in the tree (tree DP)
- MySQL - slow query log
- Metasploit (MSF) Basic Super Detailed Edition
- OC - NSSet (set)
- Control 'ContentPlaceHolder1_ddlDepartment' of type 'DropDownList' must be placed inside a form tag with runat=server.
- 企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人
- View port number occupancy
- 敏捷、DevOps和嵌入式系统测试
- redis-高级篇
- Introduction to mysql operation (4) ----- data sorting (ascending, descending, multi-field sorting)
猜你喜欢
随机推荐
Find the largest n files
(2022 Niu Ke Duo School 5) D-Birds in the tree (tree DP)
Metasploit(MSF)基础超级详细版
PanGu-Coder: A function-level code generation model
有点奇怪!访问目的网址,主机能容器却不行
MGRE环境下的OSPF
[Unity3D] Beginner Encryption Skills (Anti-Cracking)
About the SQL concat () function problem, how to splice
Mysql报错2003 解决办法 Can‘t connect to MySQL server on ‘localhost‘ (10061)
View zombie processes
Splunk Filed extraction 字段截取
Splunk Field Caculated Calculated Field
FormData upload binary file, object, object array
HCIP 第六天
MySQL batch update
Install Metasploitable2 on VMware
2022-2023 十大应用开发趋势
LeetCode 2312. 卖木头块
Debian 10 dhcp relay (dhcp 中继) dhcp 固定分配
Probability Theory and Mathematical Statistics









