parseClassName static method
Parse className string and return style properties.
className
- Space-separated class names
componentType
- Type of component for specific parsing
context
- Build context for responsive design
Implementation
static Map<String, dynamic> parseClassName(
String className,
String componentType,
BuildContext context,
) {
if (className.isEmpty) return {};
// 生成缓存键
final screenWidth = MediaQuery.of(context).size.width;
final cacheKey = '$className:$componentType:$screenWidth';
// 生产环境使用缓存,开发环境每次重新解析以支持热重载
// if (kDebugMode) {
// print('🔥 DEBUG模式: 重新解析样式 - $className (缓存大小: ${_cache.length})');
// }
if (!kDebugMode && _cache.containsKey(cacheKey)) {
return Map<String, dynamic>.from(_cache[cacheKey]!);
}
var styles = <String, dynamic>{};
// 解析响应式类名
List<String> classes = _filterResponsiveClasses(className.split(' '), context);
// 解析基础样式
for (String cls in classes) {
cls = cls.trim();
if (cls.isEmpty) continue;
_parseBasicStyles(cls, styles);
}
// 处理渐变背景
_processGradient(styles);
// 生产环境缓存结果
if (!kDebugMode) {
_cache[cacheKey] = Map<String, dynamic>.from(styles);
}
return styles;
}