我正在尝试建立一个应用程序,其中所有者可以从数据库中删除“保留”,我正在显示我的数据库的列表视图,我已经在每张卡的底部添加了一个删除按钮,但我不确定如何真正删除特定的数据,而不是删除数据库中的所有内容……有什么建议吗?
class ReservasOwner extends StatefulWidget {
Firestore _fireStore = Firestore.instance;
@override
_ReservasOwnerState createState() => _ReservasOwnerState();
}
class _ReservasOwnerState extends State<ReservasOwner> {
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: widget._fireStore.collection('Reservas').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text("No tiene reservas disponibles");
} else {
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
String idParqueo = snapshot.data.documents[index]['IDParqueo'];
String horaInicio =
snapshot.data.documents[index]['HoraInicio'];
String horaFinal = snapshot.data.documents[index]['HoraFinal'];
String tamAuto = snapshot.data.documents[index]['TamañoAuto'];
return ReservaCard(
idParqueo: idParqueo,
horaInicio: horaInicio,
horaFinal: horaFinal,
tamAuto: tamAuto,
);
},
);
}
});
}
}
class ReservaCard extends StatefulWidget {
String idParqueo;
String horaInicio;
String horaFinal;
String tamAuto;
ReservaCard({this.idParqueo, this.horaInicio, this.horaFinal, this.tamAuto});
@override
_ReservaCardState createState() => _ReservaCardState();
}
class _ReservaCardState extends State<ReservaCard> {
bool isChecked = false;
@override
Widget build(BuildContext context) {
return Container(
child: Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 30.0),
child: ListTile(
title: Text(
"ID Parqueo: " + widget.idParqueo,
style: TextStyle(fontSize: 30.0),
),
),
),
//Text("Id Reserva: " + reserva.idReserva),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
children: <Widget>[
Text("Tamaño auto: " + widget.tamAuto),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 4.0),
child: Row(
children: <Widget>[
Text("Hora final: " + widget.horaInicio),
Spacer(),
Text("Hora inicio: " + widget.horaFinal),
],
),
),
Botones(
textoBoton: 'Cancelar reserva',
tipoBoton: TipoBoton.BotonLogin,
//onPressed delete function
onPressed: () {
},
)
],
),
),
),
);
}
}发布于 2020-12-20 04:28:37
我建议您使用app.quicktype.io为您的JSON创建一个模型。完成此操作后,从数据库中获取数据并将其作为列表映射到模型。这意味着,一旦获得数据,就可以轻松地显示ListView,而一旦想要移除项目,只需调用{list variable name}.removeAt({index of item})即可
https://stackoverflow.com/questions/65374099
复制相似问题