当前位置:网站首页>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
边栏推荐
- Inverter Phase Locking Principle and DSP Implementation
- MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
- gdalinfo: error while loading shared libraries: libgdal.so.30: cannot open shared object file: No su
- 2022-2023 十大应用开发趋势
- MySQL-基础
- redis-advanced
- HCIP 第十一天
- From cloud computing to function computing
- Conditional constructor ~wapper
- Azure Synapse Analytics上创建用户并赋予权限
猜你喜欢

HCIP 第十一天

FormData upload binary file, object, object array

【CV】OpenVINO installation tutorial

spark架构

59: Chapter 5: Develop admin management services: 12: MongoDB usage scenarios; (non-core data, non-core data with a relatively large amount of data, small private files such as face photos;)

2022-2023 十大应用开发趋势

HCIP 第十二天
![MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains](/img/aa/ab58ec47bb96df803dbc6a8ff6dde3.png)
MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains

2022年防止网络攻击的15个网络安全实践,你学会了吗?

OC-error prompt
随机推荐
Probability Theory and Mathematical Statistics
停止精神内耗 每日分享
Splunk Field Caculated Calculated Field
Debian 10 dhcp relay (dhcp 中继) dhcp 固定分配
UG NX二次开发(C#)-外部模式-导出dwg格式的文件
Understand the Chisel language. 30. Chisel advanced communication state machine (2) - FSMD: Take Popcount as an example
【CV】OpenVINO installation tutorial
常用的云安全防护措施盘点
Control 'ContentPlaceHolder1_ddlDepartment' of type 'DropDownList' must be placed inside a form tag with runat=server.
Hack The Box - File Transfers Module详细讲解中文教程
postgres groupby merge strings
MySQL - Index Optimization and Query Optimization
Modify apt-get source to domestic mirror source
OC-NSArray
OC-NSString
ROS文件系统以及相关命令
HCIP 第十一天
59: Chapter 5: Develop admin management services: 12: MongoDB usage scenarios; (non-core data, non-core data with a relatively large amount of data, small private files such as face photos;)
OC-错误提示
LeetCode 283. Shifting Zeros (Simple, Array)