Last active
July 4, 2020 07:36
-
-
Save PatilShreyas/3b19df2e464fec7de4c70f20fc567ad3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert' as convert; | |
import 'package:http/http.dart' as http; | |
import '../model/form.dart'; | |
/// FormController is a class which does work of saving FeedbackForm in Google Sheets using | |
/// HTTP GET request on Google App Script Web URL and parses response and sends result callback. | |
class FormController { | |
// Google App Script Web URL. | |
static const String URL = "https://script.google.com/macros/s/AKfycbyAaNh-1JK5pSrUnJ34Scp3889mTMuFI86DkDp42EkWiSOOycE/exec"; | |
// Success Status Message | |
static const STATUS_SUCCESS = "SUCCESS"; | |
/// Async function which saves feedback, parses [feedbackForm] parameters | |
/// and sends HTTP GET request on [URL]. On successful response, [callback] is called. | |
void submitForm( | |
FeedbackForm feedbackForm, void Function(String) callback) async { | |
try { | |
await http.post(URL, body: feedbackForm.toJson()).then((response) async { | |
if (response.statusCode == 302) { | |
var url = response.headers['location']; | |
await http.get(url).then((response) { | |
callback(convert.jsonDecode(response.body)['status']); | |
}); | |
} else { | |
callback(convert.jsonDecode(response.body)['status']); | |
} | |
}); | |
} catch (e) { | |
print(e); | |
} | |
} | |
} |
I'll suggest you to print Http response so that you'll get know about response coming.
thanks for your response , but as ı still new at programming I would ask you to give m a hint for that
For step by step guide, please read article on it which is written by me.
It's available on repository main page (README.md)
…On Fri 14 Feb, 2020, 5:35 PM albazy, ***@***.***> wrote:
thanks for your response , but as ı still new at programming I would ask
you to give m a hint for that
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/3b19df2e464fec7de4c70f20fc567ad3?email_source=notifications&email_token=AEVWFOFQKG2KXNIUBVMYWH3RC2CHNA5CNFSM4KJJUYQKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAGB466#gistcomment-3176943>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEVWFODHGFXZTGQSTMP6XETRC2CHNANCNFSM4KJJUYQA>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for such a great job . I tried the codes and it worked very well on my computer and on android virtual compiler where when I installed the app on my android phone it woked too but didnt submet the info to the Gsheet , I mean the submetting message shows up but the "Submetted" message didnt and as a result wasnt able to send them to gsheet . Can you help me to figure out the problem ?? Thanks in advanced !