Im trying to compile this custom function but it doesnt work:
import 'dart:convert';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import '/flutter_flow/lat_lng.dart';
import '/flutter_flow/place.dart';
import '/flutter_flow/uploaded_file.dart';
import '/flutter_flow/custom_functions.dart';
import '/backend/backend.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import '/backend/schema/structs/index.dart';
import '/backend/schema/enums/enums.dart';
import '/backend/supabase/supabase.dart';
import '/auth/supabase_auth/auth_util.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
Future<String?> reverseCityGeocoding(LatLng coordinates) async {
/// MODIFY CODE ONLY BELOW THIS LINE
final apiKey = 'API KEY';
final url =
'https://maps.googleapis.com/maps/api/geocode/json?latlng=${coordinates.latitude},${coordinates.longitude}&key=$apiKey';
try {
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
final data = json.decode(response.body);
if (data['results'] != null && data['results'].isNotEmpty) {
for (var component in data['results'][0]['address_components']) {
if (component['types'].contains('locality')) {
return component['long_name'];
}
}
}
} else {
print('Error in reverse geocoding: ${response.statusCode}');
}
} catch (e) {
print('Exception in reverse geocoding: $e');
}
return null;
/// MODIFY CODE ONLY ABOVE THIS LINE
}
The function is empty or cannot be parsed. Make sure not to modify code outside of the designated area.
I need to do this as a function or call my custom API call "reverseGeocoding" insidethe function.
How can I make it work? im desperate