Hibok
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

63 wiersze
1.2 KiB

  1. import 'dart:async';
  2. import 'package:photo_manager/photo_manager.dart';
  3. class AssetProvider {
  4. Map<AssetPathEntity, AssetPaging> _dataMap = {};
  5. AssetPathEntity _current;
  6. AssetPathEntity get current => _current;
  7. set current(AssetPathEntity current) {
  8. _current = current;
  9. if (_dataMap[current] == null) {
  10. final paging = AssetPaging(current);
  11. _dataMap[current] = paging;
  12. }
  13. }
  14. List<AssetEntity> get data => _dataMap[current]?.data ?? [];
  15. Future<void> loadMore() async {
  16. final paging = getPaging();
  17. if (paging != null) {
  18. await paging.loadMore();
  19. }
  20. }
  21. AssetPaging getPaging() => _dataMap[current];
  22. bool get noMore => getPaging()?.noMore ?? false;
  23. int get count => data?.length ?? 0;
  24. }
  25. class AssetPaging {
  26. int page = 0;
  27. List<AssetEntity> data = [];
  28. final AssetPathEntity path;
  29. final int pageCount;
  30. bool noMore = false;
  31. AssetPaging(this.path, {this.pageCount = 50});
  32. Future<void> loadMore() async {
  33. if (noMore == true) {
  34. print('noMore');
  35. return;
  36. }
  37. var data = await path.getAssetListPaged(page, pageCount);
  38. if (data.length == 0) {
  39. print('数据长度为0');
  40. noMore = true;
  41. }
  42. page++;
  43. this.data.addAll(data);
  44. }
  45. }