Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Future sendEmail(datiForm) async {
- var body = Map<String, dynamic>();
- var htmlToSend = '';
- var extraInfo = '';
- var corpoEmail = Map<String, dynamic>();
- if (datiForm is DatiFormStore) {
- if (datiForm.problemaDaSegnalare == 'Prezzo Errato') {
- extraInfo = "questo è l'ID dell'articolo ${datiForm.productId}";
- }
- htmlToSend = '''
- <p style="font-size: 16px;">Form Compilato ${datiForm.email_object}</p>
- <p>L'utente ha trovato un problema per quanto riguarda ${datiForm.problemaDaSegnalare} riguardo il seguente store ${datiForm.storeID} </p>
- <p> messaggio: ${datiForm.message}</p>
- <p>${extraInfo}</p>
- ''';
- corpoEmail = datiForm.itemToJson(datiForm);
- body = {
- "bodyEmail": corpoEmail,
- "email_object": datiForm.email_object,
- "email": datiForm.email,
- "htmlToSend": htmlToSend
- };
- }
- if (datiForm is DatiFormProduct) {
- htmlToSend = '''
- <p style="font-size: 16px;">Form Compilato ${datiForm.email_object}</p>
- <p>L'utente ha trovato un problema per quanto riguarda ${datiForm.problemaDaSegnalare} riguardo il seguente prodotto ${datiForm.productId} </p>
- <p> messaggio: ${datiForm.message}</p>
- ''';
- corpoEmail = datiForm.itemToJson(datiForm);
- body = {
- "bodyEmail": corpoEmail,
- "email_object": datiForm.email_object,
- "email": datiForm.email,
- "htmlToSend": htmlToSend
- };
- }
- if (datiForm is DatiForm) {
- if (datiForm.haveStore) {
- extraInfo = '''
- <li>nome dell'azienda: ${datiForm.company_name}</li>
- <li>indirizzo dell'azienda: ${datiForm.companyAddress}</li>
- ''';
- }
- htmlToSend = '''
- <p style="font-size: 16px;">Form Compilato</p>
- <br />
- <ul>
- <li>nome utente: ${datiForm.name}</li>
- <li>email utente: ${datiForm.email}</li>
- <li>città: ${datiForm.city}</li>
- <li>messaggio dell'utente: ${datiForm.message}</li>
- ${extraInfo}
- </ul>
- ''';
- corpoEmail = datiForm.itemToJson(datiForm);
- body = {
- "bodyEmail": corpoEmail,
- "email_object": datiForm.email_object,
- "email": datiForm.email,
- "htmlToSend": htmlToSend
- };
- }
- const url =
- 'https://europe-west1-beonbuy-b3638.cloudfunctions.net/sendMail';
- const header = {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- };
- await http
- .post(url, body: json.encode(body), headers: header)
- .then((response) {
- print(response.body);
- });
- }
- class DatiForm {
- var city,
- companyAddress,
- company_name,
- email,
- name,
- message,
- email_object = '';
- var haveStore, acceptedPolicy = false;
- DatiForm() {
- city = '';
- company_name = '';
- companyAddress = '';
- email = '';
- name = '';
- email_object = '';
- haveStore = false;
- acceptedPolicy = false;
- }
- Map<String, dynamic> itemToJson(DatiForm instance) {
- return <String, dynamic>{
- 'City': instance.city,
- 'CompanyName': instance.company_name,
- 'CompanyAddress': instance.companyAddress,
- 'Name': instance.name,
- 'EmailObject': instance.email_object,
- 'Message': instance.message,
- };
- }
- }
- class DatiFormStore {
- var email,
- message,
- problemaDaSegnalare,
- productId,
- storeID,
- email_object = '';
- DatiFormStore() {
- email = '';
- email_object = '';
- productId = '';
- storeID = '';
- }
- Map<String, dynamic> itemToJson(DatiFormStore instance) {
- return <String, dynamic>{
- 'ProductID': instance.productId,
- 'StoreID': instance.storeID,
- 'EmailObject': instance.email_object,
- 'Message': instance.message,
- 'ProblemaDaSegnalare': instance.problemaDaSegnalare
- };
- }
- }
- class DatiFormProduct {
- var email, message, problemaDaSegnalare, productId, email_object = '';
- DatiFormProduct() {
- email = '';
- email_object = '';
- productId = '';
- }
- Map<String, dynamic> itemToJson(DatiFormProduct instance) {
- return <String, dynamic>{
- 'ProductID': instance.productId,
- 'EmailObject': instance.email_object,
- 'Message': instance.message,
- 'ProblemaDaSegnalare': instance.problemaDaSegnalare
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement