首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >删除按钮颤动字段恢复

删除按钮颤动字段恢复
EN

Stack Overflow用户
提问于 2020-12-20 04:23:10
回答 1查看 96关注 0票数 0

我正在尝试建立一个应用程序,其中所有者可以从数据库中删除“保留”,我正在显示我的数据库的列表视图,我已经在每张卡的底部添加了一个删除按钮,但我不确定如何真正删除特定的数据,而不是删除数据库中的所有内容……有什么建议吗?

代码语言:javascript
复制
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: () {
                  
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
EN

回答 1

Stack Overflow用户

发布于 2020-12-20 04:28:37

我建议您使用app.quicktype.io为您的JSON创建一个模型。完成此操作后,从数据库中获取数据并将其作为列表映射到模型。这意味着,一旦获得数据,就可以轻松地显示ListView,而一旦想要移除项目,只需调用{list variable name}.removeAt({index of item})即可

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65374099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档