0

I have the problem that when I start the application my map appears one way and then on passing from the bottomnavigatioBar tab it gets completely redrawn when I return.

I think it is a problem with the block and state map.

I need to know what the solution would be so that it does not get redrawn, that is, if I leave the map in a position and step in the tab, when I come back, it looks where I left it.

my map bloc:

     class MapaBloc extends Bloc<MapaEvent, MapaState> {
  MapaBloc() : super(new MapaState());

  GoogleMapController _mapController;

  void initMapa(GoogleMapController controller) {
    {
      this._mapController = controller;
      this._mapController.setMapStyle(jsonEncode(testMapTheme));

      add(OnMapaListo());
    }
  }

  void moverCamara(LatLng destino) {
    final cameraUpdate = CameraUpdate.newLatLng(destino);
    this._mapController?.animateCamera(cameraUpdate);
  }

  @override
  Stream<MapaState> mapEventToState(MapaEvent event) async* {
    if (event is OnMapaListo) {
      yield state.copyWith(mapaListo: true);
    }
  }
}

my map event:

@immutable
abstract class MapaEvent {}

class OnMapaListo extends MapaEvent {}

my map state

@immutable
class MapaState {
  final bool mapaListo;

  MapaState({this.mapaListo = false});

  MapaState copyWith({bool mapaListo}) =>
      MapaState(mapaListo: mapaListo ?? this.mapaListo);
}

1 Answers1

0

Unless there's something else triggering a rebuild on those pages you didn't show, should be as simple as adding the AutomaticKeepAliveClientMixin that you're using on your home page, to all the other screens.

Loren.A
  • 4,872
  • 1
  • 10
  • 17
  • I have tried but it keeps redrawing completely. I think it must be a problem with the bloc and state. I added that code in case you can think of what the problem would be. – Federico Lombardozzi Mar 24 '21 at 04:25
  • I'll have a look at this tomorrow but you should also show the code you have for the pages that are rebuilding when you don't want them to. – Loren.A Mar 24 '21 at 05:01