【发布时间】:2021-07-12 18:25:58
【问题描述】:
嗯, 我的实时数据库如下:Database
我的应用看起来像:Slidable button
可滑动按钮包含在 Visibility() 小部件中,因此,当子“inService”设置为“true”时,我试图将其设置为不可见,反之亦然。如果有人能告诉我如何使用 FutureBuilder 实现,我真的非常感谢,因为我只是在 Widget 构建后尝试过一次,如下所示:
bool inService = false;
Widget build(BuildContext context) {
userRef.child(FirebaseAuth.instance.currentUser.uid).onValue.listen((event) {
var snap = event.snapshot;
inService = snap.value["inService"];
//inService = (snap.value["inService"] == true) ? false: true;
print(" info: $inService");
});
.....// design
Visibility(
visible: (inService) ? false : true,
child: Positioned(
bottom: 36,
left: 20,
right: 20,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(35.0),
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 6.0,
spreadRadius: 0.5,
offset: Offset(0.7,0.7),
)
],
),//BoxDecoration
child:SliderButton(
action: () {
///Do something here OnSlide
},
///Put label over here
label: Text(
"Desliza para entrar en servicio",
style: TextStyle(
color: Color(0xffcbc7c7),
fontWeight: FontWeight.w500,
fontSize: 17),
),
icon: Center(
child: Icon(
Icons.directions_car_sharp,
color: Colors.black54,
size: 35.0,
)
),//Center
///Change All the color and size from here.
buttonColor: Colors.grey[200],
highlightedColor: Colors.white,
baseColor: Colors.grey,
dismissible: false,
width: 335,
),// SliderButton
),
),
),
我确信使用 FutureBuilder 它将按我的意愿工作,我的意思是,当 inService 发生变化时,SlidableButton 也会发生变化。
【问题讨论】:
标签: firebase flutter firebase-realtime-database visibility flutter-futurebuilder