Flutter TextField hidden by Keyboard, try many solution but not working

后端 未结 4 486
轮回少年
轮回少年 2020-12-12 04:12

When focussing on the TextField, the keyboard hides over the TextField. Below I attached a screenshot with code. Please guide me in fixing this issue.

signup

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 04:46

    This one worked for me
    signup.dart

    import 'package:flutter/material.dart';
    import 'package:yfobs/utilities/desc.dart';    
    
    ScrollController _scrollController;                                 //<==  
    
    class SignUpPage extends StatefulWidget {
      static String tag = 'SignUpPage';
      @override
      _SignUpPageState createState() => _SignUpPageState();
    }
    
    class _SignUpPageState extends State {
    
    //Implementing scrollController by detecting keyboard               //<==
      bool scrolled = false;
      _scrollListener() {
        if (!scrolled && MediaQuery.of(context).viewInsets.bottom != 0) {
          _scrollController.animateTo(
            _scrollController.position.maxScrollExtent,
            duration: Duration(milliseconds: 100),
            curve: Curves.easeOut,
          );
          scrolled = true;
        }
        if (MediaQuery.of(context).viewInsets.bottom == 0) {
          scrolled = false;
        }
      }
    
      @override
      void initState() {
        _scrollController = ScrollController();
        _scrollController.addListener(_scrollListener);
        super.initState();
      }
    
    
    
    
      Widget build(BuildContext context) {
        .
        .
        //rest is same
        .
        .
    }
    

提交回复
热议问题