load method
Implementation
Future<void> load(String assetPath) async {
if (_isInitialized) return;
try {
final String jsonString = await rootBundle.loadString(assetPath);
_rawJsonStyles = Map<String, Map<String, dynamic>>.from(json.decode(jsonString) as Map);
// Initialize _defaultStyle from JSON or fallback
final defaultJson = _rawJsonStyles['default'];
if (defaultJson != null) {
_defaultStyle = AppzStateStyle.fromJson(defaultJson, _fallbackDefaultStyle); // Base fallback for default itself
} else {
print("Warning: 'default' style not found in ui_config.json. Using hardcoded fallback default style.");
_defaultStyle = _fallbackDefaultStyle;
}
_isInitialized = true;
print("AppzStyleConfig loaded successfully from $assetPath.");
} catch (e) {
print("Error loading UI config from $assetPath: $e. Using hardcoded fallback default style for all states.");
_defaultStyle = _fallbackDefaultStyle; // Use fallback if any error occurs
_rawJsonStyles = {}; // Clear raw styles to ensure fallback is used consistently
_isInitialized = true;
}
}