showCustomDialog<T, R> method

Future<DialogResponse<T>?> showCustomDialog<T, R>({
  1. dynamic variant,
  2. String? title,
  3. String? description,
  4. bool hasImage = false,
  5. String? imageUrl,
  6. bool showIconInMainButton = false,
  7. String? mainButtonTitle,
  8. bool showIconInSecondaryButton = false,
  9. String? secondaryButtonTitle,
  10. bool showIconInAdditionalButton = false,
  11. String? additionalButtonTitle,
  12. bool takesInput = false,
  13. Color barrierColor = Colors.black54,
  14. bool barrierDismissible = false,
  15. String barrierLabel = '',
  16. @Deprecated('Prefer to use `data` and pass in a generic type. customData doesn\'t work anymore') dynamic customData,
  17. R? data,
})

Creates a popup with the given widget, a scale animation, and faded background.

The first generic type argument will be the DialogResponse while the second generic type argument is the DialogRequest

e.g.

await _dialogService.showCustomDialog<GenericDialogResponse, GenericDialogRequest>();

Where GenericDialogResponse is a defined model response, and GenericDialogRequest is the request model.

Implementation

Future<DialogResponse<T>?> showCustomDialog<T, R>({
  dynamic variant,
  String? title,
  String? description,
  bool hasImage = false,
  String? imageUrl,
  bool showIconInMainButton = false,
  String? mainButtonTitle,
  bool showIconInSecondaryButton = false,
  String? secondaryButtonTitle,
  bool showIconInAdditionalButton = false,
  String? additionalButtonTitle,
  bool takesInput = false,
  Color barrierColor = Colors.black54,
  bool barrierDismissible = false,
  String barrierLabel = '',
  @Deprecated('Prefer to use `data` and pass in a generic type. customData doesn\'t work anymore')
      dynamic customData,
  R? data,
}) {
  assert(
    _dialogBuilders != null,
    'You have to call registerCustomDialogBuilder to use this function. Look at the custom dialog UI section in the stacked_services readme.',
  );

  final customDialogUI = _dialogBuilders![variant];

  assert(
    customDialogUI != null,
    'You have to call registerCustomDialogBuilder to use this function. Look at the custom dialog UI section in the stacked_services readme.',
  );

  return Get.generalDialog<DialogResponse<T>>(
    barrierColor: barrierColor,
    transitionDuration: const Duration(milliseconds: 200),
    barrierDismissible: barrierDismissible,
    barrierLabel: barrierLabel,
    pageBuilder: (BuildContext buildContext, _, __) => SafeArea(
      key: Key('dialog_view'),
      child: Builder(
        builder: (BuildContext context) => customDialogUI!(
          context,
          DialogRequest<R>(
            title: title,
            description: description,
            hasImage: hasImage,
            imageUrl: imageUrl,
            showIconInMainButton: showIconInMainButton,
            mainButtonTitle: mainButtonTitle,
            showIconInSecondaryButton: showIconInSecondaryButton,
            secondaryButtonTitle: secondaryButtonTitle,
            showIconInAdditionalButton: showIconInAdditionalButton,
            additionalButtonTitle: additionalButtonTitle,
            takesInput: takesInput,
            data: data,
            variant: variant,
          ),
          completeDialog,
        ),
      ),
    ),
  );
}