loadSettings method
Loads all settings from repository
Implementation
Future<void> loadSettings() async {
emit(state.copyWith(isLoading: true));
// Load version info
PackageInfo? packageInfo;
try {
packageInfo = await PackageInfo.fromPlatform();
} catch (e) {
// Create fallback if package info fails
// ignore: avoid_print
print("⚠️ Version Error (Native Plugin not loaded?): $e");
packageInfo = null;
}
// Load electrical standard
final standardResult = await _repository.getDefaultElectricalStandard();
String standardId = 'rebt_spain';
standardResult.fold(
(failure) => null,
(id) => standardId = id,
);
// Load app preferences
final prefsResult = await _repository.getAppPreferences();
final prefs = prefsResult.getOrElse(() => AppPreferences.defaults());
emit(state.copyWith(
defaultStandardId: standardId,
locale: prefs.locale,
textSize: prefs.textSize,
themeMode: prefs.themeMode,
notificationsEnabled: prefs.notificationsEnabled,
highContrastEnabled: prefs.highContrastEnabled,
version: packageInfo != null
? "Versión ${packageInfo.version} (Build ${packageInfo.buildNumber})"
: (state.isLoading ? "" : "Requiere Reinicio (Plugin Nativo)"),
isLoading: false,
));
// Sync theme with ThemeCubit
_themeCubit?.setTheme(state.themeMode);
}