xCMD_AddNew_FromCliente<T, XFDataItem> method
Future
xCMD_AddNew_FromCliente<T, XFDataItem>(
- T newObj,
- List<
Contact> liContatti, - List<
DynamicCli> liCliente, { - Future onAddObj_FromCliExist(
- T newOBJ,
- DynamicCli cliente
- Future onAddObj_FromCliRubrica()?,
- Future onAddObj_FromCliInput()?,
- Future onSaveAfter_Cliente(
- T newOBJ
- bool isActive_input_ALIAS = true,
- bool isActive_input_NOME = true,
- bool isActive_input_COGNOME = true,
- bool isActive_input_CELL = true,
- bool isActive_input_EMAIL = true,
- bool isActive_input_REFERENTE = true,
BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL /// BL Comando per l'Aggiunta di una Riga all'elenco partendo da un cliente !!! OBBLIGATORIO passargli un Cliente !!!
Implementation
///Comando per l'Aggiunta di una Riga all'elenco partendo da un cliente
/// !!! OBBLIGATORIO passargli un Cliente !!!
Future xCMD_AddNew_FromCliente<T, XFDataItem>(
T newObj,
List<Contact> liContatti,
List<DynamicCli> liCliente, {
Future Function(T newOBJ, DynamicCli cliente)? onAddObj_FromCliExist,
Future Function(T newOBJ, String alias, String nome, String cognome, String cell, String email, String referente)? onAddObj_FromCliRubrica,
Future Function(T newOBJ, String alias, String nome, String cognome, String cell, String email, String referente)? onAddObj_FromCliInput,
Future Function(T newOBJ)? onSaveAfter_Cliente,
bool isActive_input_ALIAS = true,
bool isActive_input_NOME = true,
bool isActive_input_COGNOME = true,
bool isActive_input_CELL = true,
bool isActive_input_EMAIL = true,
bool isActive_input_REFERENTE = true,
}) async {
dynamic cliente_UI;
TextEditingController alias_textEditingController_UI = TextEditingController();
TextEditingController nome_textEditingController_UI = TextEditingController();
TextEditingController cognome_textEditingController_UI = TextEditingController();
TextEditingController cell_textEditingController_UI = TextEditingController();
TextEditingController email_textEditingController_UI = TextEditingController();
TextEditingController nomeReferente_textEditingController_UI = TextEditingController();
String? _alias_UI;
String? _nome_UI;
String? _cognome_UI;
String? _cell_UI;
String? _email_UI;
String? _nomeReferente_UI;
Contact? xclContact;
bool cli_exist = false;
bool cli_rubrica = false;
bool loadingRubrica = false;
var res = await showDialog<bool?>(
barrierDismissible: false,
context: context,
builder: (context) {
return StatefulBuilder(builder: (context, setState) {
return Container(
child: XAlertDialog(
height: 200,
colorBackGround: Colors.grey[900],
actionsBTNarea_Padding: EdgeInsets.all(5),
content_VerticalPadding: 5,
btnNO_OnPressed: () => Navigator.pop(context, false),
btnYES_OnPressed: () => Navigator.pop(context, true),
btnYES_label: "Avanti",
btnNO_label: "Annulla",
title_Text: "Contatto della Richiesta:",
child: Container(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Row(children: [
isActive_input_NOME
? Expanded(
child: Autocomplete<DynamicCli>(
fieldViewBuilder: (BuildContext context, TextEditingController textEditingController, FocusNode focusNode, VoidCallback onFieldSubmitted) {
return XTextFormField(
controller: nome_textEditingController_UI,
borderWidth: 2,
height: null,
colorBorder: Colors.grey[900],
focusNode: focusNode,
autoFocus: true,
border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
disabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
contentPadding: EdgeInsets.only(bottom: 5, top: 8),
hintText: "nome cliente...",
labelStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textStyle: XStyles.xStyTextForSubLabel(textColor: Colors.white),
hintStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textCapitalization: TextCapitalization.sentences,
inputFormatters: [],
onChanged: (value) {
textEditingController.text = value;
setState(() {
if (value == "") {
_nome_UI = null;
} else {
_nome_UI = value;
}
if (cliente_UI != null) {
cliente_UI = null;
} else {}
});
},
);
},
displayStringForOption: (option) {
return (option.nome ?? "") + " " + (option.cognome ?? "");
},
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return Iterable<DynamicCli>.empty();
} else {
return liCliente.where((element) => element.nome!.toLowerCase().contains(textEditingValue.text.toLowerCase()));
}
},
onSelected: (cli) {
setState(() {
cliente_UI = cli.getCloneFull();
_nome_UI = "";
alias_textEditingController_UI.text = cliente_UI!.nickname;
nome_textEditingController_UI.text = cliente_UI!.nome ?? "";
cognome_textEditingController_UI.text = cliente_UI!.cognome ?? "";
email_textEditingController_UI.text = cliente_UI!.email ?? "";
cell_textEditingController_UI.text = cliente_UI!.cell ?? "";
});
},
initialValue: TextEditingValue(text: _nome_UI ?? ""),
))
: Container(),
SizedBox(width: 10),
isActive_input_COGNOME
? Expanded(
child: Autocomplete<DynamicCli>(
fieldViewBuilder: (BuildContext context, TextEditingController textEditingController, FocusNode focusNode, VoidCallback onFieldSubmitted) {
return XTextFormField(
controller: cognome_textEditingController_UI,
borderWidth: 2,
colorBorder: Colors.grey[900],
focusNode: focusNode,
autoFocus: false,
border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
disabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
contentPadding: EdgeInsets.only(bottom: 5, top: 8),
hintText: "cognome cliente...",
labelStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textStyle: XStyles.xStyTextForSubLabel(textColor: Colors.white),
hintStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textCapitalization: TextCapitalization.sentences,
inputFormatters: [],
onChanged: (value) {
textEditingController.text = value;
setState(() {
if (value == "") {
_cognome_UI = null;
} else {
_cognome_UI = value;
}
if (cliente_UI != null) {
cliente_UI = null;
} else {}
});
},
);
},
displayStringForOption: (option) {
return (option.cognome ?? "") + " " + (option.nome ?? "");
},
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return Iterable<DynamicCli>.empty();
} else {
return liCliente.where((element) => element.cognome!.toLowerCase().contains(textEditingValue.text.toLowerCase()));
}
},
onSelected: (cli) {
setState(() {
cliente_UI = cli.getCloneFull();
_cognome_UI = "";
alias_textEditingController_UI.text = cliente_UI!.nickname;
nome_textEditingController_UI.text = cliente_UI!.nome ?? "";
cognome_textEditingController_UI.text = cliente_UI!.cognome ?? "";
email_textEditingController_UI.text = cliente_UI!.email ?? "";
cell_textEditingController_UI.text = cliente_UI!.cell ?? "";
});
},
initialValue: TextEditingValue(text: _nome_UI ?? ""),
))
: Container(),
]),
isActive_input_ALIAS
? Row(children: [
Expanded(
child: XTextFormField(
controller: alias_textEditingController_UI,
borderWidth: 2,
colorBorder: Colors.grey[900],
autoFocus: true,
border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
height: null,
disabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
contentPadding: EdgeInsets.only(bottom: 5, top: 8),
hintText: "alias...",
labelStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textStyle: XStyles.xStyTextForSubLabel(textColor: Colors.white),
hintStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textCapitalization: TextCapitalization.sentences,
inputFormatters: [],
onChanged: (value) {
alias_textEditingController_UI.text = value;
setState(() {
if (value == "")
_alias_UI = null;
else
_alias_UI = value;
if (cliente_UI != null) cliente_UI = null;
});
})),
SizedBox(width: 10)
])
: Container(),
isActive_input_REFERENTE
? Row(children: [
Expanded(
child: XTextFormField(
controller: nomeReferente_textEditingController_UI,
borderWidth: 2,
height: null,
colorBorder: Colors.grey[900],
border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
disabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
contentPadding: EdgeInsets.only(bottom: 5, top: 8),
hintText: "nome referente...",
textCapitalization: TextCapitalization.sentences,
keyboardType: TextInputType.name,
labelStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textStyle: XStyles.xStyTextForSubLabel(textColor: Colors.white),
hintStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
inputFormatters: [],
onChanged: (value) {
nomeReferente_textEditingController_UI.text = value;
setState(() {
if (value == "")
_nomeReferente_UI = null;
else
_nomeReferente_UI = value;
if (cliente_UI != null) cliente_UI = null;
});
}))
])
: Container(),
isActive_input_CELL
? Row(children: [
Expanded(
child: XTextFormField(
controller: cell_textEditingController_UI,
borderWidth: 2,
height: null,
colorBorder: Colors.grey[900],
border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
disabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
contentPadding: EdgeInsets.only(bottom: 5, top: 8),
hintText: "cell...",
textCapitalization: TextCapitalization.sentences,
keyboardType: TextInputType.phone,
labelStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textStyle: XStyles.xStyTextForSubLabel(textColor: Colors.white),
hintStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
inputFormatters: [],
onChanged: (value) {
cell_textEditingController_UI.text = value;
setState(() {
if (value == "")
_cell_UI = null;
else
_cell_UI = value;
if (cliente_UI != null) cliente_UI = null;
});
}))
])
: Container(),
isActive_input_EMAIL
? Row(children: [
Expanded(
child: XTextFormField(
controller: email_textEditingController_UI,
borderWidth: 2,
height: null,
colorBorder: Colors.grey[900],
border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
disabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.grey[600]!)),
contentPadding: EdgeInsets.only(bottom: 5, top: 8),
hintText: "email...",
keyboardType: TextInputType.emailAddress,
labelStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
textStyle: XStyles.xStyTextForSubLabel(textColor: Colors.white),
hintStyle: XStyles.xStyTextForSubLabel(textColor: Colors.grey[600]!),
inputFormatters: [],
onChanged: (value) {
email_textEditingController_UI.text = value;
setState(() {
if (value == "")
_email_UI = null;
else
_email_UI = value;
if (cliente_UI != null) cliente_UI = null;
});
}))
])
: Container(),
SizedBox(height: 20),
Row(children: [
onAddObj_FromCliRubrica != null
? Expanded(
child: loadingRubrica
? Container(child: XStatefulWidgetBase.LoaderIndicator(loadingRubrica, fixHeight: 40, fixWidth: 40, label: "Caricamento"))
: XBtnbase(
backGroundColor: Colors.grey[800],
toolTip_Message: "Inserisci un nuovo Cliente dalla Rubrica",
label: "Da Rubrica",
label_Color: Colors.blue,
onPressed: () async {
cli_rubrica = true;
setState(() => loadingRubrica = true);
xclContact = await xCMD_AddFromRubrica(liContatti);
setState(() => loadingRubrica = false);
if (xclContact != null) {
setState(() {
if (xclContact!.phones != null && xclContact!.phones!.isNotEmpty) {
_alias_UI = (xclContact!.givenName ?? "") + " " + (xclContact!.familyName ?? "");
_nome_UI = (xclContact!.givenName ?? "");
_cognome_UI = (xclContact!.familyName ?? "");
_cell_UI = xclContact!.phones!.first.value ?? "";
_email_UI = "";
}
});
}
Navigator.pop(context, true);
}))
: Container(),
(onAddObj_FromCliRubrica != null && onAddObj_FromCliExist != null) ? SizedBox(width: 10) : Container(),
onAddObj_FromCliExist != null
? Expanded(
child: XBtnbase(
backGroundColor: Colors.grey[800],
toolTip_Message: "Usa un Cliente gia esistente",
label: "Da Esistente",
label_Color: Colors.green,
onPressed: () {
cliente_UI = null;
cli_exist = true;
Navigator.pop(context, true);
}))
: Container(),
])
])))));
});
});
if (res != null && res) {
if (cli_exist) {
var res = await cmd_AddCliFromExist(liCliente);
if (res != null) {
await onAddObj_FromCliExist!(newObj, res);
} else {
return xCMD_AddNew_FromCliente(newObj, liContatti, liCliente);
}
} else if (cli_rubrica) {
if (xclContact != null) await onAddObj_FromCliRubrica!(newObj, _alias_UI ?? "", _nome_UI ?? "", _cognome_UI ?? "", _cell_UI ?? "", _email_UI ?? "", _nomeReferente_UI ?? "");
} else {
if (_alias_UI != "") await onAddObj_FromCliInput!(newObj, _alias_UI ?? "", _nome_UI ?? "", _cognome_UI ?? "", _cell_UI ?? "", _email_UI ?? "", _nomeReferente_UI ?? "");
}
await onSaveAfter_Cliente!(newObj);
}
}