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); | |
} | |
} | |
} |
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 your response , but as ı still new at programming I would ask you to give m a hint for that