show method

Future<UniqueKey> show({
  1. String title = 'Error',
  2. String? desc,
  3. DialogType type = DialogType.error,
})

Displays a custom dialog.

The dialog is shown as a SnackBar at the bottom of the screen.

Optionally takes a title, desc (description), and type of dialog. The type influences the appearance of the dialog.

Returns a Future that resolves with a UniqueKey identifying the displayed dialog. This key can be used to hide the specific dialog later.

If an error occurs during the process (e.g., ScaffoldMessengerState is null), a CustomException is thrown.

Implementation

Future<UniqueKey> show({
  String title = 'Error',
  String? desc,
  DialogType type = DialogType.error,
}) async {
  try {
    FocusScope.of(_context).unfocus();
    UniqueKey key = UniqueKey();
    ScaffoldFeatureController<SnackBar, SnackBarClosedReason>? controller =
        _smKey.currentState?.showSnackBar(
          GlueSnackBarWidget(
            key: key,
            dismissOnBack: true,
            dismissOnTapOutside: true,
            margin: EdgeInsets.zero,
            hideCallback: () => hide(key),
            backgroundColor: Colors.black,
            elevation: 5,
            content: SizedBox(
              height: _context.screenSize.height,
              width: _context.screenSize.width,
              child: AnimatedDialogWidget(
                dialog: SMDialog(
                  context: _context,
                  dialogType: type,
                  alignment: Alignment.center,
                  animType: AnimType.bottomSlide,
                  width: double.infinity,
                  transitionAnimationDuration: Duration(milliseconds: 200),
                  buttonsBorderRadius: BorderRadius.circular(10),
                  dismissOnTouchOutside: false,
                  dismissOnBackKeyPress: false,
                  headerAnimationLoop: false,
                  title: title,
                  desc: desc,
                  showCloseIcon: true,
                  onClose: () => hide(key),
                ),
              ),
            ),
          ),
        );
    _dialogsStack.add(_DialogEntry(controller, key));
    SnackBarClosedReason? reason = await controller?.closed;
    if (kDebugMode) print(reason);
    return key;
  } catch (e, s) {
    throw CustomException(
      message: 'حصل خطأ في احدى الميزات, رمز الخطأ [SMK maybe null]',
      hiddenMessage: '{\ne: $e\ns:$s\n}',
    );
  }
}