artflutter / reactive_forms_widgets

MIT License
121 stars 72 forks source link

ReactiveImagePicker: how to make deleteDialogBuilder? #156

Open Dionnie123 opened 2 weeks ago

Dionnie123 commented 2 weeks ago

I tried many approach, the image still stays when I confirm delete on dialog.

  deleteDialogBuilder: (context, onConfirm) {
        return showDialog<void>(
          context: context,
          barrierDismissible: false, // User must tap button to dismiss dialog
          builder: (BuildContext dialogContext) {
            return AlertDialog(
              title: const Text('Delete File'),
              content:
                  const Text('Are you sure you want to delete this file?!!'),
              actions: <Widget>[
                TextButton(
                  child: const Text('Cancel'),
                  onPressed: () {
                    Navigator.of(dialogContext).pop(); // Dismiss the dialog
                  },
                ),
                TextButton(
                  child: const Text('Delete'),
                  onPressed: () {
// Call the onDelete callback
                       onConfirm(SelectedFile.image());

                    Navigator.of(dialogContext).pop(); // Dismiss the dialog
                  },
                ),
              ],
            );
          },
        );
      },

image

Dionnie123 commented 2 weeks ago

Looks like I got it now, I just need to access form control value and give to onConfirm, it works but still not 100% sure.

  TextButton(
                  child: const Text('Delete'),
                  onPressed: () {
                    onConfirm(formControl!.value![0]);
                    Navigator.of(dialogContext).pop(); // Dismiss the dialog
                  },
                ),