novel.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'package:flutter/material.dart';
  2. import 'package:shuqi/model/sq_color.dart';
  3. import 'chapter.dart';
  4. class Novel {
  5. late String id;
  6. late String name;
  7. late String imgUrl;
  8. late String firstChapter;
  9. late Chapter lastChapter;
  10. late String author;
  11. late double price;
  12. late double score;
  13. late String type;
  14. late String introduction;
  15. late int chapterCount;
  16. late int recommendCount;
  17. late int commentCount;
  18. late int firstArticleId;
  19. late List<String> roles;
  20. late String status;
  21. late double wordCount;
  22. late List<String> tags;
  23. late bool isLimitedFree;
  24. Novel.fromJson(Map data) {
  25. id = data['bid'] ?? '';
  26. firstArticleId = data['first_article_id'] ?? 0;
  27. name = data['bookname'];
  28. imgUrl = data['book_cover'];
  29. firstChapter = data['topic_first'] ?? '';
  30. if (data['lastChapter'] != null) {
  31. lastChapter = Chapter.fromJson(data['lastChapter']);
  32. }
  33. score = data['score'] ?? 0;
  34. author = data['author_name'];
  35. price = double.parse(data['price'] ?? '0');
  36. type = data['class_name'] ?? '';
  37. introduction = data['introduction'] ?? '';
  38. chapterCount = int.parse(data['chapterNum'] ?? '0');
  39. recommendCount = int.parse(data['recommend_num'] ?? '0');
  40. commentCount = int.parse(data['comment_count'] ?? '0');
  41. status = data['stat_name'] ?? '';
  42. wordCount = data['wordCount'] ?? 0;
  43. tags = (data['tag'] ?? []).cast<String>()?.toList();
  44. isLimitedFree = data['is_free'] == 1;
  45. }
  46. String recommendCountStr() {
  47. if (recommendCount >= 10000) {
  48. return (recommendCount / 10000).toStringAsFixed(1) + '万人推荐';
  49. } else {
  50. return recommendCount.toString() + '人推荐';
  51. }
  52. }
  53. Color statusColor() {
  54. return status == '连载' ? SQColor.blue : SQColor.primary;
  55. }
  56. }