Flutter , TextField遇到的问题

一、点击空白,收起键盘

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),
  ),                     
),

三、键盘弹出,底部溢出报错

Flutter , TextField遇到的问题_第1张图片
方案:
外面套一层SingleChildScrollView

body: SingleChildScrollView(
              child: Column(
                children: [   ...  ],       
              ),
 ),

以上内容的转载链接:

  1. https://blog.csdn.net/weixin_42869574/article/details/103301302?ops_request_misc=%25257B%252522request%25255Fid%252522%25253A%252522160845652916780288221037%252522%25252C%252522scm%252522%25253A%25252220140713.130102334.pc%25255Fall.%252522%25257D&request_id=160845652916780288221037&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_v2~rank_v29-1-103301302.nonecase&utm_term=flutter,TextField%20%E7%82%B9%E5%87%BB%E7%A9%BA%E7%99%BD%20%20%E6%94%B6%E8%B5%B7%E9%94%AE%E7%9B%98

  2. https://blog.csdn.net/qq_35547137/article/details/109367095?ops_request_misc=&request_id=&biz_id=102&utm_term=flutter%25EF%25BC%258CTextField%25E7%259A%2584%25E6%2596%2587%25E5%25AD%2597%25E5%2592%258CsuffixIco&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-1-109367095.nonecase

  3. https://blog.csdn.net/wo541075754/article/details/86145870?ops_request_misc=&request_id=&biz_id=102&utm_term=flutter,TextField%2520%25E9%2594%25AE%25E7%259B%2598%25E5%25BC%25B9%25E8%25B5%25B7%25EF%25BC%258C%25E9%25A1%25B5%25E9%259D%25A2%25E6%25BA%25A2%25E5%2587%25BA&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-2-86145870.nonecase

你可能感兴趣的:(Flutter,flutter)