submit method

dynamic submit(
  1. BuildContext context,
  2. dynamic callback(),
  3. String previousValue,
  4. Function post,
  5. String url,
  6. String param,
)

Implementation

submit(BuildContext context, Function() callback, String previousValue,
    Function post, String url, String param) async {
  _pressed = true;
  notifyListeners();
  var response = await post(
    url: url,
    body: <String, dynamic>{
      param.toLowerCase(): _value,
    },
  );
  if (response != null && response.statusCode == 200) {
    showSuccess("$param information updated");
    callback();
  } else {
    value = previousValue;
    try {
      var data = jsonDecode(response.body);
      showError("${data["error"]}.");
    } catch (_) {
      showError("Could not update ${param.toLowerCase()} information.");
    }
  }
  try {
    _pressed = false;
    notifyListeners();
  } catch (_) {}
}