vkdart

Форк
0
117 строк · 3.8 Кб
1
import 'package:vkdart/vkontakte.dart';
2

3
/// Model Poll
4
///
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');
9

10
  /// Date of creation in Unixtime format.
11
  int? get createdAt => payload['created'];
12

13
  /// Question text.
14
  String? get question => payload['question'];
15

16
  /// The number of votes.
17
  int? get votesCount => payload['votes'];
18

19
  /// An array of objects that contain information about answer options.
20
  List<PollAttachmentAnswerModel>? get answers => (payload['answers'] as List?)
21
      ?.map(
22
          (e) => PollAttachmentAnswerModel((e as Map).cast<String, dynamic>()))
23
      .toList();
24

25
  /// Whether the survey is anonymous.
26
  bool? get isAnonymous => payload['anonymous'];
27

28
  /// Does the survey allow for multiple answer options.
29
  bool? get isMultiple => payload['multiple'];
30

31
  /// IDs of the answer options selected by the current user.
32
  List<int>? get answerIds => (payload['answer_ids'] as List?)?.cast<int>();
33

34
  /// The date when the survey was completed in Unixtime. 0 if the survey is open-ended.
35
  int? get endDate => payload['end_date'];
36

37
  /// Whether the survey is completed.
38
  bool? get isClosed => payload['closed'];
39

40
  /// Whether the survey is attached to the discussion.
41
  bool? get isBoard => payload['is_board'];
42

43
  /// Is it possible to edit the survey?
44
  bool? get isCanEdit => payload['can_edit'];
45

46
  /// Is it possible to vote in the poll.
47
  bool? get isCanVote => payload['can_vote'];
48

49
  /// Is it possible to complain about the survey.
50
  bool? get isCanReport => payload['can_report'];
51

52
  /// Is it possible to share the survey?
53
  bool? get isCanShare => payload['can_share'];
54

55
  /// The ID of the survey author.
56
  int? get authorId => payload['author_id'];
57

58
  /// The photo is the background of the survey snippet.
59
  PhotoAttachmentModel? get photo =>
60
      payload['photo'] != null ? PhotoAttachmentModel(payload['photo']) : null;
61

62
  Map<String, dynamic>? get _background => payload['background'];
63

64
  /// background ID.
65
  int? get backgroundId => _background?['id'];
66

67
  /// the type of background. Possible values: `gradient`, `tile`.
68
  String? get backgroundType => _background?['type'];
69

70
  /// (for type = gradient) the angle of the gradient along the X-axis.
71
  int? get backgroundAngle => _background?['angle'];
72

73
  /// The HEX code of the replacement color (without #).
74
  String? get backgroundColor => _background?['color'];
75

76
  /// (for type = tile) the width of the pattern tile.
77
  int? get backgroundWidth => _background?['width'];
78

79
  /// (for type = tile) the height of the pattern tile.
80
  int? get backgroundHeight => _background?['height'];
81

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>>();
85

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))
90
          .toList();
91

92
  /// The IDs of the 3 friends who voted in the poll.
93
  List<int>? get friends => (payload['friends'] as List?)?.cast<int>();
94
}
95

96
/// Model Poll Answer
97
///
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);
102

103
  /// Payload.
104
  final Map<String, dynamic> answerObject;
105

106
  /// Id answer.
107
  int get id => answerObject['id'];
108

109
  /// Text answer.
110
  String get text => answerObject['text'];
111

112
  /// Number of people who voted for this answer.
113
  int get votes => answerObject['votes'];
114

115
  /// Answer rating.
116
  int? get rate => answerObject['rate'];
117
}
118

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.