initialize method

Future<void> initialize({
  1. TestController? testController,
})

Initializes the plugin with an optional TestController. If the TestController is not set then this acts as nothing more than a wrapper to the Geolocator.

Implementation

Future<void> initialize({
  TestController? testController,
}) async {
  if (_initialized != true) {
    _testController = testController;
    _initialized = true;

    _locationStreamController!.onListen = () {
      if (_locationSubscription == null && _overriddenLocation == null) {
        _locationSubscription =
            Geolocator.getPositionStream().listen((position) {
          if (_overriddenLocation == null) {
            _locationStreamController?.add(position);
          }
        });
      }
    };

    _locationStreamController!.onCancel = () {
      if (_locationStreamController?.hasListener != true) {
        _locationSubscription?.cancel();
        _locationSubscription = null;
      }
    };

    await refresh();
  }
}