Poll.fromMap constructor

Poll.fromMap(
  1. Map<String, dynamic> map
)

Implementation

factory Poll.fromMap(Map<String, dynamic> map) {
  return Poll(
    id: map['id'] != null ? map['id'] as String : '',
    question: map['question'] as String,
    type: map['type'] as String,
    options: List<String>.from(map['options'] as List),
    votes: map['votes'] == null
        ? []
        : (map['votes'] as List)
            .map((e) => e is int ? e : int.tryParse(e.toString()) ?? 0)
            .toList(),
    status: map['status'] != null ? map['status'] as String : 'inactive',
    voters: map['voters'] == null
        ? {}
        : Map<String, int>.fromEntries(
            (map['voters'] as Map).entries.map((e) {
              final key = e.key.toString();
              final value = e.value is int
                  ? e.value
                  : int.tryParse(e.value.toString()) ?? 0;
              return MapEntry(key, value);
            }),
          ),
  );
}