title: late initialization error flutter: Field _origin has not been initialized
body: <p>Here is the error message drawn from the debug console:
  The following LateError was thrown building MapScreen(dirty, state: _MapScreenState#53750):
  LateInitializationError: Field '_origin' has not been initialized.
  The relevant error-causing widget was:
  MapScreen</p>
  <p>Here is the code snippet drawn from the MapScreen dart file:</p>
  <pre><code>class _MapScreenState extends State&lt;MapScreen&gt; {
    static const _initialCameraPosition = CameraPosition(
      target: LatLng(-1.286389, 36.817223),
      zoom: 11.5,
    );
    late GoogleMapController _googleMapController;
    late Marker _origin;
    late Marker _destination;
    late Directions _info;
    @override
    void dispose() {
      _googleMapController.dispose();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          centerTitle: false,
          title: const Text('Google Maps'),
          actions: [
            TextButton(
              onPressed: () =&gt; _googleMapController.animateCamera(
                CameraUpdate.newCameraPosition(
                  CameraPosition(
                    target: _origin.position,
                    zoom: 14.5,
                    tilt: 50.0,
                  ),
                ),
              ),
              style: TextButton.styleFrom(
                primary: Colors.green,
                textStyle: const TextStyle(fontWeight: FontWeight.w600),
              ),
              child: const Text('ORIGIN'),
            ),
            TextButton(
              onPressed: () =&gt; _googleMapController.animateCamera(
                CameraUpdate.newCameraPosition(
                  CameraPosition(
                      target: _destination.position, zoom: 14.5, tilt: 50.0),
                ),
              ),
              style: TextButton.styleFrom(
                primary: Colors.blue,
                textStyle: const TextStyle(fontWeight: FontWeight.w600),
              ),
              child: const Text('DEST'),
            ),
          ],
        ),
        body: Stack(
          alignment: Alignment.center,
          children: [
            GoogleMap(
              myLocationButtonEnabled: false,
              zoomControlsEnabled: false,
              initialCameraPosition: _initialCameraPosition,
              onMapCreated: (controller) =&gt; _googleMapController = controller,
              markers: {
                if (_origin != null) _origin,
                if (_destination != null) _destination,
              },
              polylines: {
                if (_info != null)
                Polyline(polylineId: const PolylineId('overview_polyline'),
                color: Colors.red,
                width: 5,
                points: _info.polylinePoints
                .map((e) =&gt; LatLng(e.latitude, e.longitude))
                .toList(),
                ),
              },
              onLongPress: _addMarker,
            ),
            if (_info != null)
              Positioned(
              top: 20.0,
              child: Container(
                padding: const EdgeInsets.symmetric(
                vertical: 6.0, 
                horizontal: 12.0
                ),
              decoration: BoxDecoration(
                color: Colors.yellowAccent,
                borderRadius: BorderRadius.circular(20.0),
                boxShadow: const [
                  BoxShadow(
                    color: Colors.black26,
                    offset: Offset (0, 2),
                    blurRadius: 6.0,
                  ),
                ]
              ),
              child: Text(
                '${_info.totalDistance}, ${_info.totalDuration}',
                style: const TextStyle(
                  fontSize: 18.0,
                  fontWeight: FontWeight.w600,
                ),
              ),
              ),
              ),
              
          ],
        ),
        floatingActionButton: FloatingActionButton(
          backgroundColor: Theme.of(context).primaryColor,
          foregroundColor: Colors.black,
          onPressed: () =&gt; _googleMapController.animateCamera(
            _info != null
            ? CameraUpdate.newLatLngBounds(_info.bounds, 100.0)
            : CameraUpdate.newCameraPosition(_initialCameraPosition),
          ),
          child: const Icon(Icons.center_focus_strong),
        ),
      );
    }
  
    Future&lt;void&gt; _addMarker(LatLng pos) async {
      if (_origin == null || (_origin != null &amp;&amp; _destination != null)) {
        setState(() {
          _origin = Marker(
            markerId: const MarkerId('origin'),
            infoWindow: const InfoWindow(title: 'origin'),
            icon:
                BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueGreen),
            position: pos,
          );
          //Reset Destination
          var __destination = null;
          _destination = __destination;
          var __info = null;
          _info = __info;
        });
      } else {
        setState(() {
          _origin = Marker(
            markerId: const MarkerId('destination'),
            infoWindow: const InfoWindow(title: 'destination'),
            icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueBlue),
            position: pos,
          );
        });
        final directions = await DirectionsRepository()
        .getDirections(origin: _origin.position, destination: pos);
        setState(() =&gt; _info = directions!);
      }
    }
  }
  </code></pre>