news_state.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class NewsState {
  2. int? activeTabIndex =0;
  3. int? curPage =0;
  4. int? pageSize =10;
  5. int? filterCount =0;
  6. List<String>? tabsList = ['News', 'Following', 'For You'];
  7. List<Map<String, dynamic>>? list = [];
  8. NewsState({
  9. this.activeTabIndex,
  10. this.curPage,
  11. this.pageSize,
  12. this.filterCount,
  13. this.tabsList,
  14. this.list,
  15. });
  16. NewsState copyWith({
  17. int? activeTabIndex,
  18. int? curPage,
  19. int? pageSize,
  20. int? filterCount,
  21. List<String>? tabsList,
  22. List<Map<String, dynamic>>? list,
  23. }) {
  24. return NewsState(
  25. activeTabIndex: activeTabIndex ?? this.activeTabIndex,
  26. curPage: curPage ?? this.curPage,
  27. pageSize: pageSize ?? this.pageSize,
  28. filterCount: filterCount ?? this.filterCount,
  29. tabsList: tabsList ?? this.tabsList,
  30. list: list ?? this.list,
  31. );
  32. }
  33. Map<String, dynamic> toMap() {
  34. return {
  35. 'activeTabIndex': this.activeTabIndex,
  36. 'curPage': this.curPage,
  37. 'pageSize': this.pageSize,
  38. 'filterCount': this.filterCount,
  39. 'tabsList': this.tabsList,
  40. 'list': this.list,
  41. };
  42. }
  43. factory NewsState.fromMap(Map<String, dynamic> map) {
  44. return NewsState(
  45. activeTabIndex: map['activeTabIndex'] as int,
  46. curPage: map['curPage'] as int,
  47. pageSize: map['pageSize'] as int,
  48. filterCount: map['filterCount'] as int,
  49. tabsList: map['tabsList'] as List<String>,
  50. list: map['list'] as List<Map<String, dynamic>>,
  51. );
  52. }
  53. }