当前位置:网站首页>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
边栏推荐
猜你喜欢

Understand Chisel language. 31. Chisel advanced communication state machine (3) - Ready-Valid interface: definition, timing and implementation in Chisel

Xilinx Constraint Study Notes - Timing Constraints

spark架构

mysql操作入门(四)-----数据排序(升序、降序、多字段排序)

MySQL-锁机制

概率论与数理统计

DeadLock的可视化分析

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

初探形式化方法基本原理

MPLS和BGP的综合实验
随机推荐
Inverter Phase Locking Principle and DSP Implementation
Control 'ContentPlaceHolder1_ddlDepartment' of type 'DropDownList' must be placed inside a form tag with runat=server.
How to export multiple query results at once in SQL server 2014?
HCIP 第十天
Splunk Filed Alias field name
MySQL-数据库事务详解
OC-NSArray
apt & apt-get commands
MySQL - Detailed Explanation of Database Transactions
如何保护智能家居不受黑客攻击
Data reveal that the average cost is as high as $4.35 million in 2022, a record!
MySQL database design specification
Enterprise training and reproduction guidebook - training and reasoning of the OpenPose model based on Huawei ModelArts platform, realizing the recognition of two behaviors of climbing and climbing ov
postgres groupby 合并字符串
Find the largest n files
ROS file system and related commands
关于DDoS的几个误区
View zombie processes
HCIP 第六天
HCIP 第十二天