mind_node.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ///
  2. ///图片大小对象
  3. ///
  4. class ImageSize {
  5. final int width;
  6. final int height;
  7. ImageSize({required this.width, required this.height});
  8. factory ImageSize.fromJson(Map<String, dynamic> json) {
  9. int w = json['width'] ?? 0;
  10. int h = json['height'] ?? 0 ;
  11. return ImageSize(width: w, height: h);
  12. }
  13. Map<String, dynamic> _$ImageSizeToJson(ImageSize instance) {
  14. var map = <String, dynamic>{};
  15. map['width'] = instance.width;
  16. map['height'] = instance.height;
  17. return map;
  18. }
  19. Map<String, dynamic> toJson() => _$ImageSizeToJson(this);
  20. }
  21. ///
  22. ///脑图节点数据对象
  23. ///
  24. class NodeData {
  25. String? id;
  26. int? created;
  27. String? text;
  28. int? priority; //优先级
  29. int? progress; //进度
  30. String? image; //图片地址 根据图片id 生成图片地址
  31. String? imageTitle; //图片标题
  32. String? imageId;// 图片id 图片存储在file模块
  33. ImageSize? imageSize; //图片大小
  34. String? hyperlink; //超链接
  35. String? hyperlinkTitle; // 超链接标题
  36. NodeData(
  37. {this.id,
  38. this.created,
  39. this.text,
  40. this.priority,
  41. this.progress,
  42. this.image,
  43. this.imageId,
  44. this.imageTitle,
  45. this.imageSize,
  46. this.hyperlink,
  47. this.hyperlinkTitle});
  48. factory NodeData.fromJson(Map<String, dynamic> json) {
  49. return NodeData(
  50. id: json['id'],
  51. created: json['created'],
  52. text: json['text'],
  53. priority: json['priority'],
  54. progress: json['progress'],
  55. image: json['image'],
  56. imageId: json['imageId'],
  57. imageTitle: json['imageTitle'],
  58. imageSize: json['imageSize'] == null ? null : ImageSize.fromJson(json['imageSize'] as Map<String, dynamic>),
  59. hyperlink: json['hyperlink'],
  60. hyperlinkTitle: json['hyperlinkTitle'],
  61. );
  62. }
  63. Map<String, dynamic> _$NodeDataToJson(NodeData instance) {
  64. var map = <String, dynamic>{};
  65. if(instance.id!=null) {
  66. map['id'] = instance.id;
  67. }
  68. if(instance.created!=null) {
  69. map['created'] = instance.created;
  70. }
  71. if(instance.text!=null) {
  72. map['text'] = instance.text;
  73. }
  74. if(instance.priority!=null) {
  75. map['priority'] = instance.priority;
  76. }
  77. if(instance.progress!=null) {
  78. map['progress'] = instance.progress;
  79. }
  80. if(instance.image!=null) {
  81. map['image'] = instance.image;
  82. }
  83. if(instance.imageId!=null) {
  84. map['imageId'] = instance.imageId;
  85. }
  86. if(instance.imageTitle!=null) {
  87. map['imageTitle'] = instance.imageTitle;
  88. }
  89. if(instance.imageSize!=null ) {
  90. map['imageSize'] = instance.imageSize?.toJson();
  91. }
  92. if(instance.hyperlink!=null) {
  93. map['hyperlink'] = instance.hyperlink;
  94. }
  95. if(instance.hyperlinkTitle!=null) {
  96. map['hyperlinkTitle'] = instance.hyperlinkTitle;
  97. }
  98. return map;
  99. }
  100. Map<String, dynamic> toJson() => _$NodeDataToJson(this);
  101. }
  102. ///
  103. ///脑图节点对象
  104. ///
  105. class Node {
  106. NodeData data;
  107. List<Node> children;
  108. Node({required this.data, required this.children});
  109. factory Node.fromJson(Map<String, dynamic> json) {
  110. List<Node> nodes = [];
  111. if(json['children'] != null) {
  112. var list = json['children'] as List;
  113. nodes = list.map((i) => Node.fromJson(i)).toList();
  114. }
  115. return Node(
  116. data: NodeData.fromJson(json['data']),
  117. children: nodes
  118. );
  119. }
  120. Map<String, dynamic> _$NodeToJson(Node instance) {
  121. var map = <String, dynamic>{};
  122. map['data'] = instance.data.toJson();
  123. var list = <Map<String, dynamic>>[];
  124. for (var child in instance.children) {
  125. list.add(child.toJson());
  126. }
  127. map['children'] = list;
  128. return map;
  129. }
  130. Map<String, dynamic> toJson() => _$NodeToJson(this);
  131. }
  132. ///
  133. /// 节点内容的类型
  134. ///
  135. enum NodeElement {
  136. background, // 背景 rrect circle
  137. border, // rrect(stroke) line
  138. text,
  139. progress,
  140. priority,
  141. image,
  142. hyperlink
  143. }