xCMD_AddFromRubrica method

Future<Contact?> xCMD_AddFromRubrica(
  1. List<Contact> listContact
)

Implementation

Future<Contact?> xCMD_AddFromRubrica(List<Contact> listContact) async {
  await _getContactPermission();
  if (listContact.isEmpty) {
    var res = await ContactsService.getContacts();
    listContact.addAll(res);
  }
  Contact? xclContatto;
  var x = await showDialog<Contact>(
      context: context,
      builder: (context) {
        return StatefulBuilder(builder: (context, setState) {
          return XAlertDialog(
              title_Text: "Scegli il contatto dalla tua RUBRICA:",
              height: null,
              content_VerticalPadding: 30,
              child: XDropSearch<Contact>(
                dropDownMode: "Dialog",
                al_Title: "",
                al_BackGroundColor: Colors.grey[900],
                itemSelected: xclContatto,
                liItems: listContact.where((element) => element.phones!.isNotEmpty).toList(),
                label: "",
                itemAsString: (p0) => (p0.givenName ?? "") + " " + (p0.familyName ?? ""),
                onChanged_ItemOfDD: (contact) {
                  setState(() => xclContatto = contact);
                },
              ),
              actionsBTNarea_Child: Row(children: [
                Expanded(
                    child: XBtnbase(
                  label: "Annulla",
                  onPressed: () => Navigator.pop(context, null),
                  label_Style: XStyles.xStyTextForSubLabel(textColor: XColors.undo),
                )),
                xclContatto != null
                    ? Expanded(
                        child: XBtnbase(
                        label: "Avanti",
                        onPressed: () => Navigator.pop(context, xclContatto),
                        label_Style: XStyles.xStyTextForSubLabel(textColor: XColors.done),
                      ))
                    : Container()
              ]));
        });
      });
  if (x != null && xclContatto != null)
    return xclContatto;
  else
    return null;
}