article.dart 801 B

12345678910111213141516171819202122232425262728293031323334
  1. class Article {
  2. late int id;
  3. late int novelId;
  4. late String title;
  5. late String content;
  6. late int price;
  7. late int index;
  8. late int nextArticleId;
  9. late int preArticleId;
  10. late List<Map<String, int>> pageOffsets;
  11. Article.fromJson(Map data) {
  12. id = data['id'];
  13. novelId = data['novel_id'];
  14. title = data['title'];
  15. content = data['content'];
  16. content = '  ' + content;
  17. content = content.replaceAll('\n', '\n  ');
  18. price = data['welth'] ?? 0;
  19. index = data['index'];
  20. nextArticleId = data['next_id'];
  21. preArticleId = data['prev_id'];
  22. }
  23. String stringAtPageIndex(int index) {
  24. var offset = pageOffsets[index];
  25. return this.content.substring(offset['start']!, offset['end']);
  26. }
  27. int get pageCount {
  28. return pageOffsets.length;
  29. }
  30. }