fixed google map rendering on API < 23
This commit is contained in:
parent
685d5c6944
commit
1eb007e43b
1 changed files with 9 additions and 17 deletions
|
@ -12,7 +12,6 @@ import 'package:latlong2/latlong.dart' as ll;
|
||||||
|
|
||||||
class PlatformMobileServices extends MobileServices {
|
class PlatformMobileServices extends MobileServices {
|
||||||
bool _isAvailable = false;
|
bool _isAvailable = false;
|
||||||
bool _canRenderMaps = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
|
@ -21,21 +20,14 @@ class PlatformMobileServices extends MobileServices {
|
||||||
debugPrint('Device has Google Play Services=$_isAvailable');
|
debugPrint('Device has Google Play Services=$_isAvailable');
|
||||||
|
|
||||||
final androidInfo = await DeviceInfoPlugin().androidInfo;
|
final androidInfo = await DeviceInfoPlugin().androidInfo;
|
||||||
_canRenderMaps = androidInfo.version.sdkInt >= 21;
|
final mapsImplementation = GoogleMapsFlutterPlatform.instance;
|
||||||
if (_canRenderMaps) {
|
if (mapsImplementation is GoogleMapsFlutterAndroid) {
|
||||||
final mapsImplementation = GoogleMapsFlutterPlatform.instance;
|
// As of Flutter v3.22.2 / google_maps_flutter_android 2.12.0,
|
||||||
if (mapsImplementation is GoogleMapsFlutterAndroid) {
|
// using Texture Layer Hybrid Composition (`useAndroidViewSurface = false`)
|
||||||
// as of flutter v3.7.10 / google_maps_flutter v2.2.5 / google_maps_flutter_android v2.4.10,
|
// is the default and the best. But it fails to render on API < 23, yielding:
|
||||||
// setting `useAndroidViewSurface` to true (default):
|
// "UnsupportedOperationException: Platform views cannot be displayed below API level 23"
|
||||||
// + issue #241 exists but workaround is efficient
|
// so we fall back to Hybrid Composition (`useAndroidViewSurface = true`)
|
||||||
// - page stack and page animation perf is bad
|
mapsImplementation.useAndroidViewSurface = androidInfo.version.sdkInt < 23;
|
||||||
// - overlay blur is disabled
|
|
||||||
// setting `useAndroidViewSurface` to false:
|
|
||||||
// - issue #241 exists and workaround is inefficient
|
|
||||||
// + page stack and page animation perf is OK
|
|
||||||
// + overlay blur is effective
|
|
||||||
mapsImplementation.useAndroidViewSurface = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +38,7 @@ class PlatformMobileServices extends MobileServices {
|
||||||
EntryMapStyle get defaultMapStyle => EntryMapStyle.googleNormal;
|
EntryMapStyle get defaultMapStyle => EntryMapStyle.googleNormal;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<EntryMapStyle> get mapStyles => (isServiceAvailable && _canRenderMaps)
|
List<EntryMapStyle> get mapStyles => isServiceAvailable
|
||||||
? [
|
? [
|
||||||
EntryMapStyle.googleNormal,
|
EntryMapStyle.googleNormal,
|
||||||
EntryMapStyle.googleHybrid,
|
EntryMapStyle.googleHybrid,
|
||||||
|
|
Loading…
Reference in a new issue