Flutter. У меня есть виджет слоя парковок на интерактивной карте, который отвечает за отрисовку маркеров. Логика реализована через BLoC и Repository. Ниже код виджета. Проблема в том, что при выборе (select) одного маркера, пропадает предыдущий выбранный маркер.

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart';
import 'package:forward_lo_app/src/core/ui_kit/ui_kit.dart';
import 'package:forward_lo_app/src/di/di.dart';
import 'package:forward_lo_app/src/feature/main/blocs/navigation_bar_overlay_widget_bloc/navigation_bar_overlay_widget_bloc.dart';
import 'package:forward_lo_app/src/feature/map/presentation/layers/parkings/blocs/parkings_bloc/parkings_bloc.dart';
import 'package:forward_lo_app/src/feature/map/presentation/layers/parkings/models/parking/parking.dart';
import 'package:latlong2/latlong.dart';

import 'parking_marker.dart';
import 'widgets/widgets.dart';

class ParkingsLayer extends StatefulWidget {
const ParkingsLayer({super.key});

@override
State
createState() => _ParkingsLayerState();
}

class _ParkingsLayerState extends State {
Set allMarkers = {};

@override
void initState() {
getIt.get().add(const ParkingsBlocEventGet());

getIt.get().add(
const NavigationBarOverlayWidgetAddEvent(
navigationBarOverlayWidget: AllParkingsNavigationBarOverlayWidget(),
navigationBarOverlayWidgetContent: AllParkingsNavigationBarOverlayWidgetContent(),
),
);

super.initState();
}

Future _createMarkers({
required List notSelectedNotActiveParkings,
required List activeParkings,
required ParkingModel? selectedParking,
}) async {
final markers = {};

// not selected not active parkings
if (notSelectedNotActiveParkings.isNotEmpty) {
final notSelectedNotActiveFutures = List>.generate(
notSelectedNotActiveParkings.length,
(index) => _createMarker(
notSelectedNotActiveParkings[index],
ParkingStatus.notSelectedNotActive,
),
);
markers.addAll(await Future.wait(notSelectedNotActiveFutures));
}

// selected not active parking
if (selectedParking != null && !activeParkings.contains(selectedParking)) {
final selectedNotActiveMarker = await _createMarker(
selectedParking,
ParkingStatus.selectedNotActive,
);
markers.add(selectedNotActiveMarker);
}

final List notSelectedActiveParkings = activeParkings;

// selected active parking
if (selectedParking != null && activeParkings.contains(selectedParking)) {
final selectedActiveMarker = await _createMarker(
selectedParking,
ParkingStatus.selectedActive,
);
markers.add(selectedActiveMarker);
notSelectedActiveParkings.remove(selectedParking);
}

// not selected active parkings
if (notSelectedActiveParkings.isNotEmpty) {
final notSelectedActiveFutures = List>.generate(
notSelectedActiveParkings.length,
(index) => _createMarker(
notSelectedActiveParkings[index],
ParkingStatus.notSelectedActive,
),
);
markers.addAll(await Future.wait(notSelectedActiveFutures));
}

allMarkers = markers;
setState(() {});
}

Future _createMarker(ParkingModel parking, ParkingStatus status) async {
final marker = Marker(
height: 30,
width: 30,
point: LatLng(parking.coordinate.latitude, parking.coordinate.longitude),
builder: (ctx) => ParkingMarker(
parking: parking,
parkingStatus: status,
),
);

return marker;
}

@override
Widget build(BuildContext context) {
final theme = AppTheme.of(context);
final mediaQuery = MediaQuery.of(context);

return BlocConsumer(
bloc: getIt.get(),
listener: (context, parkingsBlocState) {
if (parkingsBlocState is ParkingsBlocStateLoadSucceeded) {
final notSelectedNotActiveParkings = parkingsBlocState.allParkings;
notSelectedNotActiveParkings.removeAll(
[
...parkingsBlocState.activeParkings,
parkingsBlocState.selectedParking,
],
);

_createMarkers(
notSelectedNotActiveParkings: notSelectedNotActiveParkings.toList(),
activeParkings: parkingsBlocState.activeParkings.toList(),
selectedParking: parkingsBlocState.selectedParking,
);
}
},
builder: (context, parkingsBlocState) {
return MarkerClusterLayerWidget(
options: MarkerClusterLayerOptions(
maxClusterRadius: mediaQuery.size.width ~/ 1.5,
size: const Size(40, 40),
anchor: AnchorPos.align(AnchorAlign.center),
fitBoundsOptions: const FitBoundsOptions(
padding: EdgeInsets.all(50),
maxZoom: 15,
),
markers: allMarkers.toList(),
builder: (context, markers) {
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: theme.colors.system.primary,
),
child: Center(
child: BodyMedium14(markers.length.toString(), color: theme.colors.system.textAndIconsOnColors),
),
);
},
),
);
},
);
}
}