Reputation: 91
After upgrading to Flutter version 3.19.3 and latest version of google_maps_flutter (2.6.0) the google maps widget freezes after returning to it. It happens only on android platform when navigating from page with google maps widget to a new page. When any of text fields on this page get focus and the keyboard is shown the google maps widget freezes after returning to it.
There is no problem on IOS.
When this happens the debug log shows:
E/ImageTextureRegistryEntry( 6009): Dropping PlatformView Frame
E/BufferQueueProducer( 6009): [ImageReader-1080x2062f22m4-6009-37](id:177900000039,api:1,p:413,c:6009) dequeueBuffer: BufferQueue has been abandoned
E/BufferQueueProducer( 6009): [ImageReader-1080x2062f22m4-6009-37](id:177900000039,api:1,p:413,c:6009) dequeueBuffer: BufferQueue has been abandoned
E/BufferQueueProducer( 6009): [ImageReader-1080x2062f22m4-6009-37](id:177900000039,api:1,p:413,c:6009) dequeueBuffer: BufferQueue has been abandoned
After a lot of research and debugging it looks like the problem occurs in the platform specific implementation of google_maps_flutter for android platform.
Upvotes: 3
Views: 692
Reputation: 91
I posted this question because I wanted to help others who have encountered the same problem. After a lot of research I found that the problem is related to initialisation of google maps renderer.
The renderer should be initialised with this code (code is taken from example from package google_maps_flutter):
import 'dart:async';
import 'package:google_maps_flutter_android/google_maps_flutter_android.dart';
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
Completer<AndroidMapRenderer?>? _initializedRendererCompleter;
/// Initializes map renderer to the `latest` renderer type for Android platform.
///
/// The renderer must be requested before creating GoogleMap instances,
/// as the renderer can be initialized only once per application context.
Future<AndroidMapRenderer?> initializeMapRenderer() async {
if (_initializedRendererCompleter != null) {
return _initializedRendererCompleter!.future;
}
final Completer<AndroidMapRenderer?> completer =
Completer<AndroidMapRenderer?>();
_initializedRendererCompleter = completer;
final GoogleMapsFlutterPlatform mapsImplementation =
GoogleMapsFlutterPlatform.instance;
if (mapsImplementation is GoogleMapsFlutterAndroid) {
unawaited(mapsImplementation
.initializeWithRenderer(AndroidMapRenderer.latest)
.then((AndroidMapRenderer initializedRenderer) =>
completer.complete(initializedRenderer)));
} else {
completer.complete(null);
}
return completer.future;
}
Then call this from yor main() function:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isAndroid) {
final GoogleMapsFlutterPlatform mapsImplementation =
GoogleMapsFlutterPlatform.instance;
if (mapsImplementation is GoogleMapsFlutterAndroid) {
mapsImplementation.useAndroidViewSurface = true;
initializeMapRenderer();
}
}
...
This solution solved my problem and there are no more "dequeueBuffer: BufferQueue has been abandoned" messages in the debug console and the app is working again without any problems.
Interesting fact is that this problem occurred always on simulators while on physical devices it occurred sporadically only in rare cases.
Upvotes: 6