I was trying to implement google map auto complete places in my flutter web app but i am getting this error:XMLHttpRequest error.
here is my networkUtil code:
import 'dart:developer';
import 'package:http/http.dart' as http;
class NetworkUtils {
static Future<String?> fetchUrl(Uri uri,
{Map<String, String>? headers}) async {
try {
final response = await http.get(uri, headers: headers);
if (response.statusCode == 200) {
return response.body;
}
} catch (e) {
log('error in network utils: $e');
}
return null;
}
}
i am calling it in my controller
void placeAutoComplete(String query) async {
Uri uri =
Uri.https("maps.googleapis.com", "maps/api/place/autocomplete/json", {
"input": query,
"Key": ApiConstant.cSecretApiKey,
});
String? response = await NetworkUtils.fetchUrl(uri);
if (response != null) {
log(response);
}
}
and i am calling placeAutoComplete function when a button is pressed to check
ontap: () {
controller.placeAutoComplete('Dubai');
}
i tried everything but none of them worked