Home > front end >  I would like to change a boolean value in Firebase, but it says that the document doesn't exist
I would like to change a boolean value in Firebase, but it says that the document doesn't exist

Time:06-03

When I click in the TextButton, I want the value of requestDelivered on Firestore change to true. The code is the following:

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class Delivered extends StatefulWidget {
  final String pedidoId;
  final bool delivered;
  Delivered(this.pedidoId, this.delivered, {Key key}) : super(key: key);

  @override
  State<Delivered> createState() => _DeliveredState(delivered: this.delivered);
}

class _DeliveredState extends State<Delivered> {
  bool delivered = false;
  _DeliveredState({this.delivered});

  Future<void> _updateDelivered(pedidoId) async {
    await FirebaseFirestore.instance
        .collection("pedidos")
        .doc(pedidoId)
        .update({
      'requestDelivered': true,
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        margin: const EdgeInsets.all(5),
        child: Padding(
            padding: const EdgeInsets.all(
              10,
            ),
            child: Card(
                child: TextButton(
              style: TextButton.styleFrom(
                primary: Colors.green[900],
              ),
              child: const Text(
                'Confirmar entrega!',
                style: TextStyle(fontSize: 18),
              ),
              onPressed: () {
                setState(() {
                  delivered = !delivered;
                });
                _updateDelivered(widget.pedidoId);
              },
            ))));
  }
}

an image: [1]: https://i.stack.imgur.com/HXWT6.pn

The error is:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [cloud_firestore/not-found] Some requested document was not found

CodePudding user response:

The code looks correct, I think there is a parameter problem. check if at the moment of the upgrade the value of "pedidoId" is correct in the firebase database. can you take a screenshot of the firebase screen?

  • Related