为什么容器内的文字不显示颤动
why the text inside the container does not show flutter
你好,我是 flutter 的新手,所以在列中有一个容器,然后是一个大小合适的框,然后是另一个容器,最后是一个按钮。问题是尽管打印有效但琥珀色的容器没有显示,但我没有在屏幕上看到容器。如果电子邮件无效任何帮助,我想在该容器内显示文本!谢谢指教
Container(
height: MediaQuery.of(context).size.height * 0.08,
margin: const EdgeInsets.symmetric(horizontal: 5),
decoration: BoxDecoration(
color: const Color(0xFFEFEDED),
border: Border.all(color: Colors.transparent),
borderRadius: BorderRadius.circular(10),
),
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: TextFormField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
border: InputBorder.none,
),
),
),
),
const SizedBox(
height: 50,
),
InkWell(
onTap: () {
if (isValidEmail) {
emailsList.add(emailController.text);
box.write('emails', emailsList);
Navigator.of(context).pop();
}
if (!isValidEmail) {
Row(
children: [
Container(
color: Colors.amber,
),
],
);
print("test");
}
},
child: CustomButton("Ajouter", buttonColor, Colors.white)),
在Inkwell onTap
中放一个Row
? Row
不是函数,您必须在构建方法中 return 它。
return if 语句的类型必须是 'Widget' 。在容器小部件之前使用 'return'。
首先,如果你不给你的容器任何高度或宽度,而只给它一个颜色,它永远不会显示。为什么?因为它没有content意思就是默认的高和宽都是0。所以,我建议先设置一个高和宽。
其次,如果您想在字段无效时显示文本,那么您已经有了一些东西。在你的textField中,你可以给他一个Inputdecoration,在那里你可以访问参数errorText。为了让它工作,您必须将 formValidation 与小部件 Form 一起使用,并给他一个 formValidator 键。
最后,如果您不想默认使用 errorText,您应该在列中输入类似这样的内容。
Column(
children:[
TextField(),
if (isEmailInvalid)
Text("This is the error Text")
]
)
使用布尔值“isEmailInvalid”。
希望所有这些信息对您有所帮助。但是如果你真的是一个初学者,我建议坚持使用 TextField 的默认设置,看看 flutter 文档,这真的很有趣。
你好,我是 flutter 的新手,所以在列中有一个容器,然后是一个大小合适的框,然后是另一个容器,最后是一个按钮。问题是尽管打印有效但琥珀色的容器没有显示,但我没有在屏幕上看到容器。如果电子邮件无效任何帮助,我想在该容器内显示文本!谢谢指教
Container(
height: MediaQuery.of(context).size.height * 0.08,
margin: const EdgeInsets.symmetric(horizontal: 5),
decoration: BoxDecoration(
color: const Color(0xFFEFEDED),
border: Border.all(color: Colors.transparent),
borderRadius: BorderRadius.circular(10),
),
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: TextFormField(
controller: emailController,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
border: InputBorder.none,
),
),
),
),
const SizedBox(
height: 50,
),
InkWell(
onTap: () {
if (isValidEmail) {
emailsList.add(emailController.text);
box.write('emails', emailsList);
Navigator.of(context).pop();
}
if (!isValidEmail) {
Row(
children: [
Container(
color: Colors.amber,
),
],
);
print("test");
}
},
child: CustomButton("Ajouter", buttonColor, Colors.white)),
在Inkwell onTap
中放一个Row
? Row
不是函数,您必须在构建方法中 return 它。
return if 语句的类型必须是 'Widget' 。在容器小部件之前使用 'return'。
首先,如果你不给你的容器任何高度或宽度,而只给它一个颜色,它永远不会显示。为什么?因为它没有content意思就是默认的高和宽都是0。所以,我建议先设置一个高和宽。
其次,如果您想在字段无效时显示文本,那么您已经有了一些东西。在你的textField中,你可以给他一个Inputdecoration,在那里你可以访问参数errorText。为了让它工作,您必须将 formValidation 与小部件 Form 一起使用,并给他一个 formValidator 键。
最后,如果您不想默认使用 errorText,您应该在列中输入类似这样的内容。
Column(
children:[
TextField(),
if (isEmailInvalid)
Text("This is the error Text")
]
)
使用布尔值“isEmailInvalid”。
希望所有这些信息对您有所帮助。但是如果你真的是一个初学者,我建议坚持使用 TextField 的默认设置,看看 flutter 文档,这真的很有趣。