init method

Future<void> init()

Initialize settings. Must be called before using any settings.

Implementation

Future<void> init() async {
  if (_initialized) return;
  _initialized = true;

  _preferences ??= await SharedPreferences.getInstance();
  _packageInfo ??= await PackageInfo.fromPlatform();
  _appName = _packageInfo?.appName;
  _packageName = _packageInfo?.packageName;
  _version = _packageInfo?.version;
  _buildNumber = _packageInfo?.buildNumber;

  // ensure that the base carp path is created
  localApplicationPath.then((_) async => await carpBasePath);

  debug('$runtimeType - Shared Preferences: ${_preferences?.getKeys()}');

  // setting up time zone settings
  tz.initializeTimeZones();
  try {
    _timezone = (await FlutterTimezone.getLocalTimezone()).identifier;
  } catch (error) {
    warning(
      '$runtimeType - Could not get the local timezone - $error. '
      'Setting timezone to default: $_timezone',
    );
  }

  info('$runtimeType - Time zone set to $timezone');
  debug('$runtimeType - Time zone location: ${tz.getLocation(timezone)}');
  info('$runtimeType initialized');
}