Чтобы указать следующее поле ввода текста, вы должны использовать «FocusNode();
», например:
В «TextFormField (» мы можем использовать этот метод для фокусировки:
onFieldSubmitted: (v){
FocusScope.of(context).requestFocus(focus);
},
Также, чтобы установить различные параметры для поля ввода текста, такие как следующие и готовые параметры на клавиатуре, вы можете использовать метод ниже:
1) Для следующей опции: "textInputAction: TextInputAction.next,"
2) Для параметра «выполнено»: «textInputAction: TextInputAction.done»
Ниже приведен полный пример автоматической фокусировки на следующем поле ввода текста:
class MyApp extends State<MyLoginForm> {
final _formKey = GlobalKey<FormState>();
final focus = FocusNode();
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: Center(
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 30, top: 65.0, right: 30, bottom: 0),
child:
TextFormField(
textInputAction: TextInputAction.next,
decoration: new InputDecoration(hintText: 'Enter username', contentPadding: EdgeInsets.all(8.0)),
style: new TextStyle(fontSize: 18),
onFieldSubmitted: (v){
FocusScope.of(context).requestFocus(focus);
},
),
),
Padding(
padding: const EdgeInsets.only(left: 30, top: 30.0, right: 30, bottom: 0),
child:
TextFormField(
focusNode: focus,
textInputAction: TextInputAction.done,
decoration: new InputDecoration(hintText: 'Enter password', contentPadding: EdgeInsets.all(8.0)),
style: new TextStyle(fontSize: 18),
onFieldSubmitted: (v){
FocusScope.of(context).requestFocus(focus);
},
),
),
],
),
),
),
);
}
}
Проблема в том, что вы устанавливаете текст в TextFormField при открытии клавиатуры с помощью TextEditingController. Это означает, что
Вы присваиваете значение каждый раз в TextEditingController, поэтому при открытии клавиатуры «TextEditingController» будет
огонь, и он попытается проверить ваше состояние и установить значение по умолчанию в вашем TextFormField, а затем клавиатура получает
закрыто как нормальное поведение.
Чтобы решить эту проблему, сделайте следующее:
Прежде всего инициализируйте ваш «TextEditingController» с «новой» клавиатурой, как показано ниже:
var _AdContr = new TextEditingController();
var _SoyadContr = new TextEditingController();
final _NicknameContr = new TextEditingController();
final _getContr = new TextEditingController();
final _myUpdateContr = new TextEditingController();
Затем попробуйте установить текст по умолчанию для "TextFormField" после этих двух строк:
var contentadi = userDocument["adi"].toString();
var contentsoyadi = userDocument["Soyadi"].toString();
_AdContr.text = (contentadi == null ? "" : contentadi);
_SoyadContr.text = (contentsoyadi == null ? "" : contentsoyadi);
Затем измените ваш «TextFormField», как показано ниже, и попытайтесь сохранить это значение в ваших переменных в методе «onSubmitted»:
return Column(
children: <Widget>[
TextFormField(
controller: _AdContr,
onSubmitted: (String str){
setState(() {
contentadi = str;
_AdContr.text = contentadi;
});
},
decoration: new InputDecoration(
labelText: 'Adınız',
fillColor: Colors.white,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
),
SizedBox(height: 20),
TextFormField(
controller: _SoyadContr,
onSubmitted: (String str){
setState(() {
contentsoyadi = str;
_SoyadContr.text = contentsoyadi;
});
},
decoration: new InputDecoration(
labelText: 'Soyadınız',
fillColor: Colors.white,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
//fillColor: Colors.green
),
),
RaisedButton(
color: Colors.orange,
textColor: Colors.white,
splashColor: Colors.orangeAccent,
child: const Text('Update'),
onPressed: () {
clickUpdate(_AdContr.text, _SoyadContr.text);
},
),
],
);
Если вышеуказанное решение не работает, попробуйте использовать StreamBuilder () вместо FutureBuilder (). это будет работать и фокусироваться без проблем.