1
import 'package:vkdart/vkontakte.dart';
5
/// See https://dev.vk.com/ru/reference/objects/poll
6
class PollAttachmentModel extends CustomAttachmentModel {
7
// ignore: public_member_api_docs
8
PollAttachmentModel(super.payload) : super(attachType: 'poll');
10
/// Date of creation in Unixtime format.
11
int? get createdAt => payload['created'];
14
String? get question => payload['question'];
16
/// The number of votes.
17
int? get votesCount => payload['votes'];
19
/// An array of objects that contain information about answer options.
20
List<PollAttachmentAnswerModel>? get answers => (payload['answers'] as List?)
22
(e) => PollAttachmentAnswerModel((e as Map).cast<String, dynamic>()))
25
/// Whether the survey is anonymous.
26
bool? get isAnonymous => payload['anonymous'];
28
/// Does the survey allow for multiple answer options.
29
bool? get isMultiple => payload['multiple'];
31
/// IDs of the answer options selected by the current user.
32
List<int>? get answerIds => (payload['answer_ids'] as List?)?.cast<int>();
34
/// The date when the survey was completed in Unixtime. 0 if the survey is open-ended.
35
int? get endDate => payload['end_date'];
37
/// Whether the survey is completed.
38
bool? get isClosed => payload['closed'];
40
/// Whether the survey is attached to the discussion.
41
bool? get isBoard => payload['is_board'];
43
/// Is it possible to edit the survey?
44
bool? get isCanEdit => payload['can_edit'];
46
/// Is it possible to vote in the poll.
47
bool? get isCanVote => payload['can_vote'];
49
/// Is it possible to complain about the survey.
50
bool? get isCanReport => payload['can_report'];
52
/// Is it possible to share the survey?
53
bool? get isCanShare => payload['can_share'];
55
/// The ID of the survey author.
56
int? get authorId => payload['author_id'];
58
/// The photo is the background of the survey snippet.
59
PhotoAttachmentModel? get photo =>
60
payload['photo'] != null ? PhotoAttachmentModel(payload['photo']) : null;
62
Map<String, dynamic>? get _background => payload['background'];
65
int? get backgroundId => _background?['id'];
67
/// the type of background. Possible values: `gradient`, `tile`.
68
String? get backgroundType => _background?['type'];
70
/// (for type = gradient) the angle of the gradient along the X-axis.
71
int? get backgroundAngle => _background?['angle'];
73
/// The HEX code of the replacement color (without #).
74
String? get backgroundColor => _background?['color'];
76
/// (for type = tile) the width of the pattern tile.
77
int? get backgroundWidth => _background?['width'];
79
/// (for type = tile) the height of the pattern tile.
80
int? get backgroundHeight => _background?['height'];
82
/// (for type = tile) the image of the pattern tile.
83
List<Map<String, dynamic>>? get backgroundImages =>
84
(_background?['images'] as List?)?.cast<Map<String, dynamic>>();
86
/// (for type = gradient) gradient points.
87
List<(int position, String color)>? get backgroundPoints =>
88
(_background?['points'] as List?)
89
?.map((e) => ((e as Map)['position'] as int, e['color'] as String))
92
/// The IDs of the 3 friends who voted in the poll.
93
List<int>? get friends => (payload['friends'] as List?)?.cast<int>();
98
/// See https://dev.vk.com/ru/reference/objects/poll#answers
99
final class PollAttachmentAnswerModel {
100
// ignore: public_member_api_docs
101
PollAttachmentAnswerModel(this.answerObject);
104
final Map<String, dynamic> answerObject;
107
int get id => answerObject['id'];
110
String get text => answerObject['text'];
112
/// Number of people who voted for this answer.
113
int get votes => answerObject['votes'];
116
int? get rate => answerObject['rate'];