submit method

dynamic submit(
  1. BuildContext context,
  2. dynamic callback(),
  3. String text,
  4. Map<String, dynamic> body,
  5. Function post,
  6. Function route,
)

Implementation

submit(BuildContext context, Function() callback, String text,
    Map<String, dynamic> body, Function post, Function route) async {
  if (_groupValue != -1) {
    showDoubleButtonContentAlert(
      context,
      title: "Confirm Results",
      content: Text(
        text,
        style: Theme.of(context).textTheme.bodyText2,
      ),
      onSubmit: () async {
        Navigator.pop(context);
        _pressed = true;
        notifyListeners();
        var response = await post(
          url: '/result/add/',
          body: body,
        );

        if (response != null && response.statusCode == 201) {
          await callback();
          showSuccess("Test result submitted.");
          try {
            route(response);
          } catch (_) {}
        } else {
          try {
            var data = jsonDecode(response.body);
            showError("${data["error"]}.");
          } catch (_) {
            showError("Something went wrong.");
          }
          try {
            _pressed = false;
            notifyListeners();
          } catch (_) {}
        }
      },
    );
  } else {
    showError("Something went wrong.");
    try {
      _pressed = false;
      notifyListeners();
    } catch (_) {}
  }
}