Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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);
}
}
}
@albazy

This comment has been minimized.

Copy link

@albazy albazy commented Jan 20, 2020

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 !

@PatilShreyas

This comment has been minimized.

Copy link
Owner Author

@PatilShreyas PatilShreyas commented Jan 21, 2020

I'll suggest you to print Http response so that you'll get know about response coming.

@albazy

This comment has been minimized.

Copy link

@albazy albazy commented Feb 14, 2020

thanks for your response , but as ı still new at programming I would ask you to give m a hint for that

@PatilShreyas

This comment has been minimized.

Copy link
Owner Author

@PatilShreyas PatilShreyas commented Feb 14, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment