Flutter - клавиатура не отображается при выборе TextFormField - PullRequest
1 голос
/ 10 июля 2020

В настоящее время у меня возникает проблема, когда клавиатура не появляется, когда я выбираю какие-либо виджеты TextFormField внутри виджета Form. Это код формы, который находится внутри моего CreateAccountForm виджета с отслеживанием состояния.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sign_up_page/constants.dart';

class CreateAccountForm extends StatefulWidget {
  @override
  _CreateAccountFormState createState() => _CreateAccountFormState();
}

class _CreateAccountFormState extends State<CreateAccountForm> {
  final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Form(
      key: _formKey,
      child: Column(
        children: <Widget>[
          CustomTextFormField(
            labelText: "Email",
            keyboardType: TextInputType.emailAddress,
          ),
          Spacer(),
          CustomTextFormField(labelText: "Full name"),
          Spacer(),
          CustomTextFormField(
            labelText: "Password",
            isPassword: true,
          ),
          Spacer(),
          RaisedButton(
            onPressed: () {
              print("Get started button pressed");
            },
            padding: EdgeInsets.all(20.0),
            color: blueMaterialColor.shade100,
            shape: defaultRectangularButtonShape,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  "Get started",
                  style: TextStyle(
                    fontSize: 20.0,
                    color: Colors.white,
                  ),
                ),
                Icon(
                  Icons.arrow_forward,
                  color: Colors.white,
                ),
              ],
            ),
          ),
          Spacer(),
        ],
      ),
    );
  }
}

class CustomTextFormField extends StatefulWidget {
  CustomTextFormField({
    @required this.labelText,
    this.isPassword = false,
    this.keyboardType = TextInputType.text,
  });

  final String labelText;
  final bool isPassword;
  final TextInputType keyboardType;

  @override
  _CustomTextFormFieldState createState() => _CustomTextFormFieldState();
}

class _CustomTextFormFieldState extends State<CustomTextFormField> {
  @override
  Widget build(BuildContext context) {
    return TextFormField(
      decoration: InputDecoration(
          labelText: widget.labelText, labelStyle: inputLabelStyleUnselected),
      style: inputTextStyle,
      obscureText: widget.isPassword,
      keyboardType: widget.keyboardType,
    );
  }
}

Это снимок экрана, который показывает курсор внутри электронного письма TextFormWidget, но без отображения клавиатуры вверх:

A screenshot of the app running on an iPhone 11. The keyboard does not show even when a TextFormWidget is selected.

Вы можете просмотреть весь код проекта в моей ветке Github здесь: https://github.com/Jordan-Gillard/sign_up_page/tree/bug/fixing_keyboard_not_showing

1 Ответ

1 голос
/ 11 июля 2020

Если вы работаете на Simulator, ваш Simulator определенно имеет Connect Hardware Keyboard включенным. Вы можете решить эту проблему, отключив эту функцию.

Я предоставил изображения, чтобы показать, как это сделать, ниже:

  1. Выберите симулятор и щелкните вкладку Hardware.
  2. На вкладке Hardware выберите опцию Keyboard.
  3. Снимите отметку с опции Connect Keyboard Hardware, чтобы включить переключение реальной клавиатуры на Simulator

Проверьте изображения, представленные ниже, для более подробного описания:)

enter image description here

введите описание изображения здесь

...