news_state.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import 'package:widgets/load_state_layout.dart';
  2. class NewsState {
  3. //页面 LoadView 状态的展示
  4. LoadState loadingState;
  5. String? errorMessage;
  6. int? page;
  7. int? limit = 10;
  8. int? count = 0;
  9. List<Map<String, dynamic>>? list = [];
  10. NewsState({
  11. this.loadingState = LoadState.State_Loading,
  12. String? errorMessage,
  13. this.page = 1,
  14. this.limit = 10,
  15. this.count = 0,
  16. this.list,
  17. });
  18. NewsState copyWith({
  19. LoadState? loadingState,
  20. String? errorMessage,
  21. int? page,
  22. int? limit,
  23. int? count,
  24. List<Map<String, dynamic>>? list,
  25. List<String>? tabsList,
  26. }) {
  27. return NewsState(
  28. loadingState: loadingState ?? this.loadingState,
  29. errorMessage: errorMessage ?? this.errorMessage,
  30. page: page ?? this.page,
  31. limit: limit ?? this.limit,
  32. count: count ?? this.count,
  33. list: list ?? this.list,
  34. );
  35. }
  36. Map<String, dynamic> toMap() {
  37. return {
  38. 'loadingState': this.loadingState,
  39. 'errorMessage': this.errorMessage,
  40. 'page': this.page,
  41. 'limit': this.limit,
  42. 'count': this.count,
  43. 'list': this.list,
  44. };
  45. }
  46. factory NewsState.fromMap(Map<String, dynamic> map) {
  47. return NewsState(
  48. loadingState: map['loadingState'] as LoadState,
  49. errorMessage: map['errorMessage'] as String,
  50. page: map['page'] as int,
  51. limit: map['limit'] as int,
  52. count: map['count'] as int,
  53. list: map['list'] as List<Map<String, dynamic>>,
  54. );
  55. }
  56. }