submitObservation method
Submits a mosquito observation to the remote server.
Sends observation data including location, species information, and other metadata to the central database.
finalPayload A map containing all observation data to submit.
Returns an Observation object representing the submitted record.
Throws an exception if submission fails.
Implementation
Future<Observation> submitObservation({
required Map<String, dynamic> finalPayload,
}) async {
final url = Uri.parse(_mosquitoObservationUrl);
final response = await _httpClient.post(
url,
headers: {'Content-Type': 'application/json; charset=UTF-8'},
body: json.encode(finalPayload),
);
if (response.statusCode >= 200 && response.statusCode < 300) {
return Observation.fromJson(json.decode(response.body));
} else {
throw Exception('Failed to submit observation: ${response.statusCode} - ${response.body}');
}
}