When i click on the text this exception appears: FlutterError (This widget has been unmounted, so the State no longer has a context (and should be considered defunct). Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.)
Future addToList({
required String name,
required int price,
required String imgUrl,
required String quantity,
}) async {
final docShopList = FirebaseFirestore.instance.collection('shoplist').doc();
final shopList = ShopList(
id: docShopList.id,
name: name,
price: price,
imageUrl: imgUrl,
quantity: quantity);
final json = shopList.toJson();
await docShopList.set(json).then(
(value) => showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) => AlertDialog(
title: const Text(
'El producto se ha añadido al carrito',
textAlign: TextAlign.center,
),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('OK'))
],
),
),
);
}
The TextButton:
TextButton(
onPressed: () {
addToList(
name: widget.products.name,
price: widget.products.price,
imgUrl: widget.products.imageUrl,
quantity: quantity ?? '1');
widget.callback(2);
widget.controller!.resumeCamera();
Navigator.pop(context);
Navigator.pop(context);
},