【发布时间】:2021-08-09 19:15:21
【问题描述】:
当我触摸按钮时,我试图在终端中查看密码和用户电子邮件,但它给了我一些错误。
- 我尝试使用两个键,但它给了我错误
- 我试图在我的小部件上方放置一个 body: form,但我没有脚手架,因此它不起作用,而且我尝试更改为脚手架,但情况更糟,而且我没有更多背景。
所以有一种方法可以显示密码和电子邮件,它允许使用多种密钥的 _formKey1 和 _formKey2 系统? 我认为问题出在我的 globalkey 上
这是我的一些代码
class _BodyState extends State<Body> {
final _formKey =new GlobalKey<FormState>();
late String _email;
late String _password;
和
@override
Widget build (BuildContext context) {
return Background(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("SIGNUP", style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
Container(child: Image.asset('assets/ctlogo.png', height: 200),
),
RoundedInputField(
key: _formKey,
hintText: "Your Email",
onChanged:(value) => setState(() => _email = value),
),
RoundedPasswordField(
key: _formKey,
onChanged: (value) => setState(() => _password = value),
),
Container(margin: EdgeInsets.symmetric(vertical: 20),
width: 300,
child: ClipRRect(
borderRadius: BorderRadius.circular(29),
// ignore: deprecated_member_use
child: FlatButton(
padding: EdgeInsets.symmetric(vertical: 14, horizontal: 40),
color: DarkTurquoise,
onPressed: (){print(_email); print(_password);
Navigator.push(
context,
出现错误“相同键的小部件太多”和“LateInitializationError: Field '_password@30293343' has not been initialized”
还有我的 rounded_password_field 代码
class RoundedPasswordField extends StatefulWidget {
final ValueChanged<String> onChanged;
const RoundedPasswordField({
required this.onChanged,
Key? key,
}) : super(key: key);
@override
_RoundedPasswordFieldState createState() => _RoundedPasswordFieldState();
}
class _RoundedPasswordFieldState extends State<RoundedPasswordField> {
bool _isSecret = true;
@override
Widget build(BuildContext context) {
return TextFieldContainer(
child: TextField(
obscureText: _isSecret,
decoration: InputDecoration(
hintText: "Password",
border: InputBorder.none,
icon: Icon(
Icons.lock,
color: DarkTurquoise,
),
suffixIcon: InkWell(
onTap: () =>
setState(() => _isSecret = !_isSecret),
child: Icon(!_isSecret
? Icons.visibility
: Icons.visibility_off, color: DarkTurquoise),
),
),
),
);
}
}
【问题讨论】:
标签: flutter email dart passwords key