当前位置:网站首页>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
边栏推荐
- Link with Game Glitch
- MySQL database design specification
- 查找最大的n个文件
- hdu1752 copy
- Please tell me, how to write Flink SQL and JDBC sink into mysql library and want to create an auto-incrementing primary key
- Hack The Box - File Transfers Module详细讲解中文教程
- 替换ptmalloc,使用tcmalloc和jemalloc
- Neural network
- 【Network】IP, subnet mask
- MySQL-Multiversion Concurrency Control
猜你喜欢

OC-error prompt

LeetCode 2312. Sell Wood Blocks

(2022 Nioke Duo School 5) C-Bit Transmission (Thinking)

ROS file system and related commands

Azure Synapse Analytics上创建用户并赋予权限

Hack The Box - File Transfers Module详细讲解中文教程

PanGu-Coder: A function-level code generation model

神经元网络
![The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]](/img/14/cd6ed7452230571db2e027f61dbdba.png)
The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]

Buried development process
随机推荐
spark read local file
From cloud computing to function computing
MySQL-执行流程+缓存+存储引擎
OC-NSDictionary
敏捷、DevOps和嵌入式系统测试
OSPF 综合实验
2022-08-01 第四小组 修身课 学习笔记(every day)
DeadLock的可视化分析
About the SQL concat () function problem, how to splice
Go implements distributed locks
WebForm DropDownList分别绑定年月
从云计算到函数计算
机器学习笔记--数学库
redis-advanced
LeetCode 2360. 图中的最长环
OC-Category
MySQL - Index Optimization and Query Optimization
Splunk Field Caculated Calculated Field
概率论与数理统计
2022年防止网络攻击的15个网络安全实践,你学会了吗?