initPlatformState method

Future<Null> initPlatformState ()

Implementation

Future<Null> initPlatformState() async {
  final SharedPreferences prefs = await _prefs;
  String username = prefs.getString("username");

  Map deviceParams = await bg.Config.deviceParams;

  // 1.  Listen to events (See docs for all 12 available events).
  bg.BackgroundGeolocation.onLocation(_onLocation);
  bg.BackgroundGeolocation.onMotionChange(_onMotionChange);
  bg.BackgroundGeolocation.onActivityChange(_onActivityChange);
  bg.BackgroundGeolocation.onProviderChange(_onProviderChange);
  bg.BackgroundGeolocation.onConnectivityChange(_onConnectivityChange);

  // 2.  Configure the plugin
  bg.BackgroundGeolocation.ready(bg.Config(
      desiredAccuracy: bg.Config.DESIRED_ACCURACY_NAVIGATION,
      distanceFilter: 10.0,
      stopOnTerminate: false,
      startOnBoot: true,
      foregroundService: true,
      stopTimeout: 1,
      debug: true,
      autoSync: true,
      url: 'http://tracker.transistorsoft.com/locations/$username',
      params: deviceParams,
      logLevel: bg.Config.LOG_LEVEL_VERBOSE
  )).then((bg.State state) {
    setState(() {
      _enabled = state.enabled;
      _isMoving = state.isMoving;
    });
  });
}