Исключение: NoSuchMethodError: Class '_CompactLinkedHashSet' has no instance method 'add' with matching arguments

Я использую google_maps_flutter и пытаюсь сделать так, чтобы при нажатии на toggle button на карте появлялись маркеры из определенного массива json файла. Есть 4 такие кнопки, каждая связана с определенным массивом и списком, я определяю взаимосвязь названия, списка и массива через 2 метода:

  getSetMarkers(String title) {
    if (title == "Дома") {
      return _markersHouses;
    } else if (title == "Организации") {
      return _markersOrganizations;
    } else if (title == "Пространства") {
      return _markersPlases;
    } else if (title == "Мероприятия") {
      return _markersEvents;
    }
  }

  getJSON(String title) {
    if (title == "Дома") {
      return 'coordsHouses';
    } else if (title == "Организации") {
      return 'coordsOrganisations';
    } else if (title == "Пространства") {
      return 'coordsPlaces';
    } else if (title == "Мероприятия") {
      return 'coordsEvents';
    }
  }

Декодирование json и добавление маркеров выглядит так:

  Future loadMarkers() async {
    var jsonData = await rootBundle.loadString('assets/json/coords.json');
    var data = json.decode(jsonData);
    data["${getJSON(widget.title)}"].forEach((item) {
      getSetMarkers(widget.title).add(
        Marker(
            markerId: MarkerId(item["ID"]),
            position: LatLng(double.parse(item["latitude"]),
                double.parse(item["longitude"])),
            infoWindow: InfoWindow(
              title: item["comment"],
            ),
            icon:
                BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueRed)),
      );
    });
  }

Кнопка:

ToggleButtons(
      renderBorder: false,
      isSelected: isSelected,
      fillColor: getBorderColor(widget.title),
      children: <Widget>[
        Container(
          margin: EdgeInsets.all(5),
          color: getbgColor(widget.title),
          width: 180,
          padding: EdgeInsets.symmetric(horizontal: 24),
          child: Center(
              child: Text(widget.title,
                  style: TextStyle(fontSize: 18, color: Colors.white))),
        )
      ],
      onPressed: (int index) {
        loadMarkers();
        setState(() {
          isSelected[index] = !isSelected[index];
        });
      },
    );

При нажатии на кнопку получаю такую ошибку:

E/flutter ( 5048): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: NoSuchMethodError: Class '_CompactLinkedHashSet<Marker>' has no instance method 'add' with matching arguments.
E/flutter ( 5048): Receiver: _LinkedHashSet len:0
E/flutter ( 5048): Tried calling: add(null, Instance of 'Marker')
E/flutter ( 5048): Found: add(X0) => bool
E/flutter ( 5048): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
E/flutter ( 5048): #1      _ToggleButtonState.loadMarkers.<anonymous closure>
package:tos_parkoviy_app/…/3_catalog/5_section_map.dart:243
E/flutter ( 5048): #2      List.forEach (dart:core-patch/growable_array.dart:433:8)
E/flutter ( 5048): #3      _ToggleButtonState.loadMarkers
package:tos_parkoviy_app/…/3_catalog/5_section_map.dart:242
E/flutter ( 5048): <asynchronous suspension>

Ошибка в строках с декодированием. Не понимаю, что она значит, и как можно ее исправить.


Ответы (0 шт):