【发布时间】:2020-05-28 05:42:05
【问题描述】:
我正在尝试在从 firestore 文档派生的某些布尔条件下启用颤振应用程序中的按钮。在下面的代码中,应该调用共享函数checkTrueFalse(),并且应该派生checkFinalValue1和checkFinalValue2的bool值,如果checkFinalValue1是true,那么Button1应该在被按下时给出结果,并且如果checkFinalValue2 是true,则应启用Button2,否则应显示为禁用。
我们如何在 Flutter 应用程序中做到这一点?我无法找到 enable button 的 Flatbutton 属性,因为我们在 Android Studio 或 Xcode 中有它
Widget build(BuildContext context) {
String listid1 = widget.listid1;
bool checkFinalValue1, checkFinalValue2;
checkTrueFalse() { final DocumentReference docRef = Firestore.instance.collection("list").document(listid1);
docRef.get().then((DocumentSnapshot ds) {
checkFinalValue1 = ds.data["value1"];
checkFinalValue2 = ds.data["value2"];
});}
final button1 = FlatButton();
return Card(child: ListTile(title:Text(widget.itemTitle),subtitle: Column(
children: <Widget>[
Text(widget.commentId),
Container(
child: Row(
children: <Widget>[
FlatButton(
child: Text("Button1"),
onPressed: () {
print("Check 1");
},
),
FlatButton(
child: Text("Button2"),
onPressed: () {
print("Button Enabled");
},
),
],
))
],
), ),);
}
【问题讨论】:
-
所以你想隐藏按钮还是禁用它?
-
@jitsm555 我最初想禁用
Button2,但是如果checkFinalValue2的值是true,那么应该启用该按钮,但是对于Button1,调用的操作应该仅在checkFinalValue1是真的,但Button1应该始终启用 -
禁用按钮,可以设置onPressed函数为null
标签: firebase flutter button google-cloud-firestore