showModal method

void showModal()

Function to show the choice modal

Implementation

void showModal() async {
  // call on modal will open callback
  // and prevent open modal if return value is not `true`
  final bool willOpen = await onModalWillOpen() ?? true;
  if (willOpen != true) return;

  // initialize the selection choice(s)
  resolveSelection();

  // initialize filter
  initializeFilter();

  // initial load the choice items
  choices.initialize();

  // show modal by type and return confirmed value
  final bool confirmed = await _showModalByType() ?? false;

  // call on modal close callback
  onModalClose(confirmed);

  // dont return value if modal need confirmation and not confirmed
  if (modalConfig.useConfirm == true && confirmed != true) return;

  // return value
  if (selection.choice != null) {
    // return state to onChange callback
    onChange();
  }
}