0

What the title says, I have tried many things, but I honostly don't know what I am doing. The problem always seems to be on this line " infoWindow: const InfoWindow(title: _startPos), " I have tried creating an initState with startPos and endPos. startPos and endPos are simple strings. Tried adding Text(_startPos), but then it complains about String not the same as String? and adding "?? ''" results in right side never called.

class MapPage extends StatefulWidget {
  final String startPos;
  final String endPos;
  const MapPage({Key? key, required this.startPos, required this.endPos})
      : super(key: key);

  @override
  _MapPageState createState() => _MapPageState();
}

class _MapPageState extends State<MapPage> {
  late String _startPos;
  late String _endPos;

  @override
  void initState() {
    super.initState();
    _startPos = widget.startPos;
    _endPos = widget.endPos;
  }

  // GoogleMapController _mapController;
  Marker origin = const Marker(
      markerId: MarkerId("origin"), position: LatLng(60.3913, 5.3221));

  Marker destination = Marker(
      infoWindow: const InfoWindow(title: 'Destination'),
      markerId: const MarkerId("destination"),
      icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueBlue),
      position:
          const LatLng(60.36852657310426, 5.350100429246856)); // HVL Coords

  static const noPos = LatLng(0.0, 0.0);

  Marker _aPlace = Marker(
    markerId: const MarkerId("_aPlace"),
    infoWindow: const InfoWindow(title: _startPos),`

1 Answers1

0

Either you can remove the const keyword or you can access variables directly in the state like infoWindow: const InfoWindow(title: widget.startPos)

Edit: Instead of directly assigning a variable, use getters

Marker get _aPlace => Marker(......);

or functions:

Marker _aPlace() => Marker(......);
Jobin
  • 376
  • 2
  • 6