解决 Flutter BUFFERQUEUE HAS BEEN ABANDONED

13 min read

解决 Flutter BUFFERQUEUE HAS BEEN ABANDONED

I had the same problem and I fixed it adding "with AutomaticKeepAliveClientMixin" to my statefulwidget. It'll make your widget never die and save you from the exception about present too much frames. This: E/BufferQueueProducer( 9243): [SurfaceTexture-0-9243-14] dequeueBuffer: BufferQueue has been abandoned will be still in debug terminal but it's not an error.

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class GoThereView extends StatefulWidget {
  @override
  _GoThereViewState createState() => _GoThereViewState();
}

class _GoThereViewState extends State<GoThereView> with AutomaticKeepAliveClientMixin {
  GoogleMapController _controller;

  @override
  bool get wantKeepAlive => true;

  void _onMapCreated(GoogleMapController controller) {
    if( _controller == null )
      _controller = controller;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Stack(
        children: <Widget>[
          GoogleMap(
            onMapCreated: _onMapCreated,
            initialCameraPosition: CameraPosition(target: LatLng(26.8206, 30.8025)),
          )
        ],
      ),
    );
  }
}