getHeaders method
Get the headers required for calling Google APIs with a restricted key based on the platform (iOS or Android). For web, an empty header will be returned.
Implementation
Future<Map<String, String>> getHeaders() async {
if (_headers.isEmpty && !kIsWeb && !platform.isDesktop) {
final packageInfo = await PackageInfo.fromPlatform();
if (platform.isIos) {
_headers = {
"X-Ios-Bundle-Identifier": packageInfo.packageName,
};
} else if (platform.isAndroid) {
try {
final sha1 = await _channel.invokeMethod(
'getSigningCertSha1',
packageInfo.packageName,
);
_headers = {
"X-Android-Package": packageInfo.packageName,
"X-Android-Cert": sha1,
};
} on PlatformException {
_headers = {};
}
}
}
return _headers;
}