![](/img/trans.png)
[英]Keyboard is not showing on clicking on TextFormField in flutter android
[英]Flutter - Keyboard not showing when TextFormField is selected
我目前遇到的问题是,当我 select Form
小部件内的任何TextFormField
小部件时,键盘没有出现。 这是表单的代码,它位于我的CreateAccountForm
Stateful 小部件中。
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,
);
}
}
这是一个屏幕截图,它显示了 email TextFormWidget
内部的 cursor ,但没有显示键盘:
您可以在我的 Github 分支上查看该项目的所有代码: https://github.com/Jordan-Gillard/sign_up_page/tree/bug/fixing_keyboard_not_showing
如果您使用 ios 模拟器,菜单选项卡是 I/O。 在此处输入图像描述
就我而言,我在 main.dart 中调用了enableFlutterDriverExtension()
。 删除这个解决了这个问题。
解决方案很简单
例如。
Form(
key: _formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 21),
child: TextFormField(
validator: (value) {
if (value == null || value.isEmpty) {
return '';
}
return null;
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.