Generally speaking, there are two ways to deal with the soft keyboard pop-up blocking keyboard in flutter:
The first case:
This is the state where the keyboard does not pop up. In this case, the effect we want to achieve must be that the soft keyboard pops up and the login button is put on top, and the interface cannot slide to achieve the best interaction effect:
So how do you implement such a code?
/// only the key parts of the code are attached here... Scaffold (resizeToAvoidBottomInset: false, / / / here must be forbidden to redraw the body: SingleChildScrollView (child: reverse: true, Height: mediaQuery.of (context).size. Height * 0.8, child: Column(crossAxisAlignment: CrossAxisAlignment. Start, children: [... / / / mainly idea is to set a fixed height SingleChildScrollView then use expended containers are free to hold up the space Expanded (child: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ GestureDetector( child: Container( margin: EdgeInsets.only(left: 20), width: 335, height: 48, decoration: BoxDecoration( color: Theme.of(context).primaryColor, borderRadius: BorderRadius.all(Radius.circular(90)) ), child: Center( child: Text('Login', style: TextStyle(color: Colors.white)), ), ), onTap: () { Navigator.of(context).push(MaterialPageRoute(builder: (_) => CreatePassWord()));},),), /// The main thing is that there is a padding that will hold up a keyboard height from the bottom of the screen to put the button on top of the padding (padding: MediaQuery.of(context).viewInsets), ], ) ), ], ), ) ) ) ...Copy the code
So having said the first case, what about the second case?
The second case
In another case, the white space of our page is not enough to support a keyboard without blocking the input box. For example, the red area is the elastic area, but it is not high enough for the keyboard, so in order to interact properly, we need to make scrollable operations on this page.The code is as follows:
. / / resizeToAvoidBottomInset: false, / / / comment out redraw it open, the entire page will be able to slide up and down...Copy the code