tryDelete method

Future<bool> tryDelete(
  1. BuildContext context, {
  2. List<String>? whatsDeleted,
})

Implementation

Future<bool> tryDelete(BuildContext context,
    {List<String>? whatsDeleted}) async {
  var loading = LoadingWidgetService.instance.show();

  if (lockService != null) {
    try {
      var isLocked = await lockService!.isLocked(
        databaseCollection.collectionName,
        updateItemFrame.editableItem.id,
        catchExceptions: false,
      );
      if (isLocked) {
        loading.deactivate();
        await SplitRouterDelegate.instance.pushDialog(DefaultDialog(
          title: Text(
              "Der Eintrag kann zurzeit nicht gelöscht werden, da er von einem anderen Benutzer bearbeitet wird."),
          buttons: [
            DefaultDialogButton(
              titel: Text("Verstanden"),
            )
          ],
        ));
        return false;
      }
    } catch (e) {
      loading.deactivate();
      SnackBarController.showText("Verbindung fehlgeschlagen");
      return false;
    }
  }

  loading.deactivate();
  var result = await onBeforeDelete?.call(context) ?? true;
  if (result == false) {
    return false;
  }

  bool confirmation = false;
  // await SplitRouterDelegate.instance.pushDialog(DefaultDialog(
  //   title: Text("Soll der Eintrag wirklich entgültig gelöscht werden?"),
  //   buttons: [
  //     DefaultDialogButton(titel: Text("Abbrechen"), onTap: () {}),
  //     DefaultDialogButton(
  //       titel: Text("Löschen"),
  //       onTap: () => confirmation = true,
  //     ),
  //   ],
  // ));

  await SplitRouterDelegate.instance.pushDialog(DeleteQuestionDialog(
    whatsDeleted: whatsDeleted,
    onSuccess: () => confirmation = true,
  ));
  if (!confirmation) return false;

  Navigator.of(context).pop();

  loading = LoadingWidgetService.instance.show();
  result = await databaseCollection.delete(updateItemFrame.editableItem);
  loading.deactivate();

  if (result == false) {
    SnackBarController.showText("Verbindung fehlgeschlagen");
  } else {
    SnackBarController.showIconAndText(
        Icons.delete_outline, "Erfolgreich gelöscht");
  }
  return true;
}