LightAnalysis.fromJson constructor
LightAnalysis.fromJson(
- Map<String, dynamic> json
)
Implementation
factory LightAnalysis.fromJson(Map<String, dynamic> json) {
final condStr = json['condition'] as String? ?? 'normal';
final condition = LightCondition.values.firstWhere(
(c) => c.name == condStr,
orElse: () => LightCondition.normal,
);
return LightAnalysis(
condition: condition,
averageLuminance: (json['averageLuminance'] as num?)?.toDouble() ?? 0.5,
estimatedLux: (json['estimatedLux'] as num?)?.toDouble() ?? 500.0,
torchRecommended: json['torchRecommended'] as bool? ?? false,
);
}