当前位置:网站首页>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
边栏推荐
- MySQL batch update
- Appium swipe problem
- Data reveal that the average cost is as high as $4.35 million in 2022, a record!
- MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
- MySQL - index explanation
- Fatal error compiling: 无效的目标发行版: 11
- LeetCode 2360. 图中的最长环
- Inverter Phase Locking Principle and DSP Implementation
- 【Unity3D】初学加密技巧(反破解)
- 查找最大的n个文件
猜你喜欢
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;)
Thesis understanding: "Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution, Denoising, and "
MySQL-索引优化和查询优化
Hack The Box - File Transfers Module详细讲解中文教程
Splunk Field Caculated Calculated Field
DeadLock的可视化分析
MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
2022年防止网络攻击的15个网络安全实践,你学会了吗?
2022-08-01 第四小组 修身课 学习笔记(every day)
Inverter insulation detection detection function and software implementation
随机推荐
Appium swipe problem
MySQL-基础
LeetCode刷题(7)
查看僵尸进程
MySQL-多版本并发控制
Conditional constructor ~wapper
OC-NSString
Comprehensive experiment of MPLS and BGP
MPLS和BGP的综合实验
MySQL-数据库设计规范
Splunk Field Caculated Calculated Field
DeadLock的可视化分析
MySQL-锁机制
Link with Game Glitch
PanGu-Coder: A function-level code generation model
Azure Synapse Analytics上创建用户并赋予权限
Chain Of Responsibility
Splunk Filed Alias field name
MySQL - Index Optimization and Query Optimization
Hack The Box - File Transfers Module详细讲解中文教程