|
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
5
|
5
|
import 'package:photo/src/delegate/badge_delegate.dart';
|
6
|
6
|
import 'package:photo/src/delegate/loading_delegate.dart';
|
7
|
7
|
import 'package:photo/src/engine/lru_cache.dart';
|
|
8
|
+import 'package:photo/src/engine/throttle.dart';
|
8
|
9
|
import 'package:photo/src/entity/options.dart';
|
9
|
10
|
import 'package:photo/src/provider/config_provider.dart';
|
10
|
11
|
import 'package:photo/src/provider/gallery_list_provider.dart';
|
|
@@ -72,20 +73,24 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
72
|
73
|
|
73
|
74
|
bool get useAlbum => widget.photoList == null || widget.photoList.isEmpty;
|
74
|
75
|
|
|
76
|
+ Throttle _changeThrottle;
|
|
77
|
+
|
75
|
78
|
@override
|
76
|
79
|
void initState() {
|
77
|
80
|
super.initState();
|
78
|
81
|
_refreshList();
|
79
|
82
|
scaffoldKey = GlobalKey();
|
80
|
83
|
scrollController = ScrollController();
|
81
|
|
- PhotoManager.addChangeCallback(_onAssetChange);
|
|
84
|
+ _changeThrottle = Throttle(onCall: _onAssetChange);
|
|
85
|
+ PhotoManager.addChangeCallback(_changeThrottle.call);
|
82
|
86
|
PhotoManager.startChangeNotify();
|
83
|
87
|
}
|
84
|
88
|
|
85
|
89
|
@override
|
86
|
90
|
void dispose() {
|
87
|
|
- PhotoManager.removeChangeCallback(_onAssetChange);
|
|
91
|
+ PhotoManager.removeChangeCallback(_changeThrottle.call);
|
88
|
92
|
PhotoManager.stopChangeNotify();
|
|
93
|
+ _changeThrottle.dispose();
|
89
|
94
|
scaffoldKey = null;
|
90
|
95
|
super.dispose();
|
91
|
96
|
}
|
|
@@ -353,8 +358,8 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
353
|
358
|
setState(() {});
|
354
|
359
|
}
|
355
|
360
|
|
356
|
|
- void _onGalleryChange(AssetPathEntity value) {
|
357
|
|
- _currentPath = value;
|
|
361
|
+ void _onGalleryChange(AssetPathEntity assetPathEntity) {
|
|
362
|
+ _currentPath = assetPathEntity;
|
358
|
363
|
|
359
|
364
|
_currentPath.assetList.then((v) {
|
360
|
365
|
_sortAssetList(v);
|
|
@@ -460,8 +465,38 @@ class _PhotoMainPageState extends State<PhotoMainPage>
|
460
|
465
|
|
461
|
466
|
void _onAssetChange() {
|
462
|
467
|
if (useAlbum) {
|
463
|
|
- _refreshList();
|
|
468
|
+ _onPhotoRefresh();
|
|
469
|
+ }
|
|
470
|
+ }
|
|
471
|
+
|
|
472
|
+ void _onPhotoRefresh() async {
|
|
473
|
+ List<AssetPathEntity> pathList;
|
|
474
|
+ switch (options.pickType) {
|
|
475
|
+ case PickType.onlyImage:
|
|
476
|
+ pathList = await PhotoManager.getImageAsset();
|
|
477
|
+ break;
|
|
478
|
+ case PickType.onlyVideo:
|
|
479
|
+ pathList = await PhotoManager.getVideoAsset();
|
|
480
|
+ break;
|
|
481
|
+ default:
|
|
482
|
+ pathList = await PhotoManager.getAssetPathList();
|
|
483
|
+ }
|
|
484
|
+
|
|
485
|
+ if (pathList == null) {
|
|
486
|
+ return;
|
|
487
|
+ }
|
|
488
|
+
|
|
489
|
+ this.galleryPathList.clear();
|
|
490
|
+ this.galleryPathList.addAll(pathList);
|
|
491
|
+
|
|
492
|
+ if (!this.galleryPathList.contains(this.currentPath)) {
|
|
493
|
+ // current path is deleted , 当前的相册被删除, 应该提示刷新
|
|
494
|
+ if (this.galleryPathList.length > 0) {
|
|
495
|
+ _onGalleryChange(this.galleryPathList[0]);
|
|
496
|
+ }
|
|
497
|
+ return;
|
464
|
498
|
}
|
|
499
|
+ // Not deleted
|
|
500
|
+ _onGalleryChange(this.currentPath);
|
465
|
501
|
}
|
466
|
|
-
|
467
|
502
|
}
|