[英]How to hide a widget with if an if condition in Flutter/dart?
This is what I have so far: This code returns the correct isShow
values.这就是我到目前为止所拥有的:此代码返回正确的isShow
值。 If the value from Firebase
is yes
it returns isShow
with true and if the value from Firebase
is something other than yes
it returns isShow
with false.如果Firebase
的值为yes
,则返回isShow
为 true;如果Firebase
的值不是yes
,则返回isShow
为 false。 So it seems to work when I try it, but after a while the Button
hide/show at random, but the values are still correct.所以当我尝试它时它似乎工作,但过了一会儿Button
隐藏/显示随机,但值仍然是正确的。
So I think I am on the right track, just missing something.所以我认为我在正确的轨道上,只是错过了一些东西。
Code:代码:
bool isShow = true;
updateToolDialog(BuildContext context, id) async {
return showDialog(context: context, builder: (context) {
FirebaseFirestore.instance.collection('users').doc(id).get().then((querySnapshot) {
statusservice = querySnapshot.get('status').toString();
setState((){
if(statusservice.contains('yes')) {
isShow = true;
print("should be true $isShow");
}else{
isShow = false;
print("should be false $isShow");
}});
});
return Dialog(
child: Container(
child: SizedBox(
width: 600,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Endre verktøy', style: TextStyle(
fontWeight: FontWeight.bold
),),
SizedBox(
height: 10,
),
Visibility(
visible: isShow,
child: ElevatedButton(
onPressed: () async{
FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance;
await firebaseFirestore.collection('users').doc(id).update({
'Status' : 'No',
});
Navigator.pop(context, true);
_initializeData();
},
child: const Text('Change status'),
),
),
]
),
),
));
});
}
You Can Do Like This你可以这样做
if(isSize.width ==100) {
SizedBox(width: 20, height: 100),
}else if(isSize.width ==50) {
SizedBox(width: 20, height: 50),
}
else {
SizedBox(width: 20, height: 20),
}
Replace Your Widgets where SizeBox Declare.替换 SizeBox 声明的小部件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.