initialize method
Initializes Places for the given application context with the given API key.
All Places API responses are localized using the device's locale. This method should only be called once prior to using the Places API. You may call this method again to update the API key used; if so, all widgets and instances of PlacesClient will now use this new key.
Implementation
@override
Future<void> initialize(String apiKey, {Locale? locale}) async {
if (_svcAutoComplete != null) {
return;
}
final completer = Completer();
_completer = completer;
_initMap = _doInit.toJS;
html.Element? scriptExist =
html.window.document.querySelector('#$_SCRIPT_ID');
if (scriptExist != null) {
_doInit();
} else {
final body = html.window.document.querySelector('body')!;
var src =
'https://maps.googleapis.com/maps/api/js?key=${apiKey}&loading=async&libraries=places&callback=initMap';
if (locale?.languageCode != null) {
_language = locale?.languageCode;
}
body.append(html.ScriptElement()
..id = _SCRIPT_ID
..src = src
..async = true
..type = 'application/javascript');
}
return completer.future.then((_) {});
}