StaticChartDataSource.fromMapList constructor

StaticChartDataSource.fromMapList(
  1. List<Map<String, dynamic>> rawList
)

Convenient constructor to parse raw OHLCV maps (e.g. from a REST API) directly.

Implementation

factory StaticChartDataSource.fromMapList(List<Map<String, dynamic>> rawList) {
  final candles = rawList.map((map) {
    return Candle(
      timestamp: map['timestamp'] is DateTime
          ? map['timestamp'] as DateTime
          : DateTime.fromMillisecondsSinceEpoch(
              map['timestamp'] is int
                  ? map['timestamp'] as int
                  : int.tryParse(map['timestamp'].toString()) ?? 0,
            ),
      open: (map['open'] as num).toDouble(),
      high: (map['high'] as num).toDouble(),
      low: (map['low'] as num).toDouble(),
      close: (map['close'] as num).toDouble(),
      volume: (map['volume'] as num?)?.toDouble() ?? 0.0,
    );
  }).toList();
  return StaticChartDataSource(candles);
}