paged_state_mixin.dart 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'dart:collection';
  2. import 'package:get/get.dart';
  3. import 'package:vitalapp/architecture/defines.dart';
  4. import 'package:vitalapp/global.dart';
  5. /// 分页状态Mixin
  6. mixin PagedStateMixin<T> {
  7. final RxString _searchString = RxString("");
  8. final RxInt _pageIndex = RxInt(0);
  9. final RxInt _pageSize = RxInt(20);
  10. final RxInt _totalCount = RxInt(0);
  11. final RxList<T> _dataList = RxList<T>();
  12. final RxBool _isOnline = RxBool(kIsOnline);
  13. /// 当前在线状态
  14. bool get isOnline => _isOnline.value;
  15. set isOnline(bool val) => _isOnline.updateValue(val);
  16. /// 模糊搜索字符串
  17. String get searchString => _searchString.value;
  18. set searchString(String val) => _searchString.updateValue(val);
  19. /// 当前页索引
  20. int get pageIndex => _pageIndex.value;
  21. set pageIndex(int val) => _pageIndex.updateValue(val);
  22. /// 每页数量
  23. int get pageSize => _pageSize.value;
  24. set pageSize(int val) => _pageSize.updateValue(val);
  25. /// 总数据量
  26. int get totalCount => _totalCount.value;
  27. set totalCount(int val) => _totalCount.updateValue(val);
  28. /// 是否存在下一页
  29. bool get hasNextPage => _totalCount > pageIndex * pageSize;
  30. /// 列表数据集合
  31. List<T> get dataList => UnmodifiableListView(_dataList.toList());
  32. set dataList(List<T> val) => _dataList.value = val;
  33. /// 追加数据集合
  34. void appendDataList(List<T> arr) {
  35. List<T> newArray = List<T>.from(_dataList);
  36. newArray.addAll(arr);
  37. _dataList.value = newArray;
  38. }
  39. }