ChartAlert.fromJson constructor
ChartAlert.fromJson(
- Map<String, dynamic> json
)
Implementation
factory ChartAlert.fromJson(Map<String, dynamic> json) {
return ChartAlert(
id: json['id'] as String,
symbol: json['symbol'] as String,
price: (json['price'] as num).toDouble(),
note: json['note'] as String? ?? 'Price Alert',
condition: AlertTriggerCondition.values.firstWhere(
(c) => c.name == json['condition'],
orElse: () => AlertTriggerCondition.crossing,
),
createdAt: DateTime.parse(json['createdAt'] as String),
isTriggered: json['isTriggered'] as bool? ?? false,
isActive: json['isActive'] as bool? ?? true,
triggeredAt: json['triggeredAt'] != null
? DateTime.tryParse(json['triggeredAt'] as String)
: null,
);
}