init method
Initializes settings. Must be called before using any settings.
Loads shared preferences and package info, creates carpBasePath, and reads the local timezone. Calling it again does nothing.
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');
}