agenda.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import 'package:get/get.dart';
  2. import 'package:json_annotation/json_annotation.dart';
  3. part 'agenda.g.dart';
  4. @JsonSerializable()
  5. class Agenda {
  6. @JsonKey(name: 'id', fromJson: _intToString, toJson: _stringToInt)
  7. String id;
  8. @JsonKey(name: 'talkId')
  9. String talkId;
  10. @JsonKey(name: 'name')
  11. String? name;
  12. @JsonKey(name: 'content')
  13. final Rx<String> _content = ''.obs;
  14. @JsonKey(name: 'createTime')
  15. String? createTime;
  16. @JsonKey(name: 'updateTime')
  17. String? updateTime;
  18. @JsonKey(ignore: true)
  19. RxBool todo = false.obs;
  20. @JsonKey(name: 'example')
  21. bool? isExample;
  22. @JsonKey(ignore: true)
  23. Rxn<AgendaStatus>? agendaStatus;
  24. Agenda(
  25. {required this.id,
  26. required this.talkId,
  27. this.name,
  28. this.createTime,
  29. this.updateTime,
  30. this.isExample});
  31. String get content => _content.value;
  32. set content(String newContent) {
  33. _content.value = newContent;
  34. }
  35. factory Agenda.fromJson(Map<String, dynamic> json) {
  36. final agenda = _$AgendaFromJson(json);
  37. agenda.todo.value =
  38. json.containsKey('todo') ? json['todo'] as bool? ?? false : false;
  39. bool? finish = json['finish'] as bool?;
  40. if (finish == true) {
  41. agenda.agendaStatus = Rxn(AgendaStatus.done);
  42. } else if (finish == false) {
  43. agenda.agendaStatus = Rxn(AgendaStatus.todo);
  44. }
  45. agenda._content.value = json['content'] as String? ?? '';
  46. return agenda;
  47. }
  48. static String _intToString(int value) => value.toString();
  49. static int _stringToInt(String value) => int.parse(value);
  50. }
  51. enum AgendaStatus {
  52. todo,
  53. completing,
  54. done,
  55. }