xCMD_DeleteFromList method

Future<bool> xCMD_DeleteFromList(
  1. XFDataItem itemToRemove,
  2. String title, {
  3. required List listFromClone_RemoveItem,
  4. required List listFromOriginal_RemoveItem,
  5. required dynamic cmd_Delete(
    1. String
    ),
})

Comando per la cancellazione di un Item dai Dettagli

Implementation

Future<bool> xCMD_DeleteFromList(XFDataItem itemToRemove, String title, {required List<dynamic> listFromClone_RemoveItem, required List<dynamic> listFromOriginal_RemoveItem, required Function(String) cmd_Delete}) async {
  setState(() {
    enteredInEditOnCell = true;
  });
  bool? x = await showDialog(
      barrierDismissible: false,
      context: context,
      builder: (builder) {
        return XAlertDialog(
          btnNO_label: "NO",
          btnYES_label: "SI",
          btnYES_OnPressed: () => Navigator.pop(context, true),
          btnNO_OnPressed: () => Navigator.pop(context, false),
          title_Text: title,
          title_Style: XStyles.xStyTextForSubLabel(textColor: Colors.yellow),
        );
      });

  if (x != null && x) {
    editedPage.value = true;

    if (listFromClone_RemoveItem.isEmpty) {
      xBottomBarAction_Fill();
    }
    var res = listFromOriginal_RemoveItem.firstWhereOrNull((element) => element.id == itemToRemove.id);

    if (res != null) {
      if (itemToRemove.id == "") {
        return false;
      } else {
        listFromClone_RemoveItem.remove(itemToRemove);
        setState(() {
          widget.key_BottomBar = UniqueKey();
          widget.key_AppBar = UniqueKey();
          widget.key_Rows = UniqueKey();
          enteredInEditOnCell = false;
        });
        await cmd_Delete(itemToRemove.id);

        return true;
      }
    } else {
      setState(() {
        widget.key_BottomBar = UniqueKey();
        widget.key_AppBar = UniqueKey();
        widget.key_Rows = UniqueKey();
        enteredInEditOnCell = false;
      });
      return false;
    }
  } else {
    setState(() {
      widget.key_BottomBar = UniqueKey();
      widget.key_AppBar = UniqueKey();
      widget.key_Rows = UniqueKey();
      enteredInEditOnCell = false;
    });
    return false;
  }
}