Flutter我只需要在按下按钮时隐藏我的组件,即可设置布尔值并使用if条件,但问题是它显示错误Columns子级不能包含空值。
这是我的代码
Widget build(BuildContext context) {
var first = true;
var second = false;
Size size = MediaQuery.of(context).size;
return Background(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"SIGNUP",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: size.height * 0.03),
SvgPicture.asset(
"assets/icons/signup.svg",
height: size.height * 0.35,
),
first ? RoundedInputField(
hintText: "Your Name",
icon: Icons.person,
onChanged: (value) {},
) : null ,
first ? RoundedInputField(
hintText: "Your Email",
icon: Icons.mail,
onChanged: (value) {
print(value);
},
) : null ,
first ? RoundedPasswordField(
onChanged: (value) {},
) : null ,
second ? RoundedInputField(
hintText: "Your Number",
icon: Icons.phone,
onChanged: (value) {
print(value);
},
) : null ,
first ? RoundedButton(
text: "NEXT",
press: () {
first = false;
second = true;
},
) : null ,
second ? RoundedButton(
text: "REGISTER",
press: () {
},
) : null ,
SizedBox(height: size.height * 0.03),
AlreadyHaveAnAccountCheck(
login: false,
press: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return LoginScreen();
},
),
);
},
),
],
),
),
);
}
}
我只是在单击时隐藏了输入小部件,单击后需要显示其他输入和按钮。但是获取错误的Columns子级不能包含任何空值
答案 0 :(得分:0)
使用SizedBox()
或空的Container()
代替null
Widget build(BuildContext context) {
var first = true;
var second = false;
Size size = MediaQuery.of(context).size;
return Background(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"SIGNUP",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: size.height * 0.03),
SvgPicture.asset(
"assets/icons/signup.svg",
height: size.height * 0.35,
),
first ? RoundedInputField(
hintText: "Your Name",
icon: Icons.person,
onChanged: (value) {},
) : SizedBox() ,
first ? RoundedInputField(
hintText: "Your Email",
icon: Icons.mail,
onChanged: (value) {
print(value);
},
) : SizedBox() ,
first ? RoundedPasswordField(
onChanged: (value) {},
) : SizedBox() ,
second ? RoundedInputField(
hintText: "Your Number",
icon: Icons.phone,
onChanged: (value) {
print(value);
},
) : SizedBox() ,
first ? RoundedButton(
text: "NEXT",
press: () {
first = false;
second = true;
},
) : SizedBox() ,
second ? RoundedButton(
text: "REGISTER",
press: () {
},
) : SizedBox() ,
SizedBox(height: size.height * 0.03),
AlreadyHaveAnAccountCheck(
login: false,
press: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return LoginScreen();
},
),
);
},
),
],
),
),
);
}
}
答案 1 :(得分:0)
如果第一个和第二个变量为null,则需要返回Container() 列小部件不知道如何呈现null 您必须告诉Column小部件如果为空,则呈现空白内容。
例如:
#include <stdlib.h>
#include <stdio.h>
int main() {
char hey[5]="hello";
if(hey[5] == NULL){
puts("Yes the last charcter is a NULL ");
}
return 0;
}
答案 2 :(得分:0)
Flutter不接受[('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'c'), ('c', 'a'), ('c', 'b'), ('a', 'a'), ('b', 'b'), ('c', 'c')]
值作为窗口小部件。如果不想在其他窗口小部件中什么也不显示,则必须至少提供一个空窗口小部件。通常,您可以使用itertools.permutations(iterable, r=None)
甚至null
。
答案 3 :(得分:0)
所有答案都是有效的,但是您可以使用Visibility显示或隐藏小部件,看起来像这样
// Get the modal
var modal = document.getElementById("myModal");
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById("myImg");
var modalImg = document.getElementById("img01");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}