一、点击空白,收起键盘
body: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); // 收起键盘
},
child: Container( ... ),
),
二、文字不居中
问题: 文本靠上
方案: 文本已经居中(与上图有细微的差别,睁大眼睛看哈!)
设置TextField里面的decoration对应的InputDecoration中的boder参数。线框border会自动校正文字的位置。
TextField(
InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 0, color: Colors.transparent)),
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 0, color: Colors.transparent)),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 0, color: Colors.transparent)),
border: OutlineInputBorder(
borderSide: BorderSide(width: 0, color: Colors.transparent)),
contentPadding: EdgeInsets.symmetric(vertical: 0),
),
),
三、键盘弹出,底部溢出报错
方案:
外面套一层SingleChildScrollView
body: SingleChildScrollView(
child: Column(
children: [ ... ],
),
),
以上内容的转载链接: