fluttercandies / flutter_photo_manager

A Flutter plugin that provides images, videos, and audio abstraction management APIs without interface integration, available on Android, iOS, macOS and OpenHarmony.
https://pub.dev/packages/photo_manager
Apache License 2.0
694 stars 315 forks source link

[Feature] Paginated asset path list #91

Closed SvenSchoene closed 5 years ago

SvenSchoene commented 5 years ago

Is your feature request related to a problem? Please describe.

Fatal Exception: NSRangeException
*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray

Fatal Exception: NSRangeException
0  CoreFoundation                 0x1cf0e127c __exceptionPreprocess
1  libobjc.A.dylib                0x1ce2bb9f8 objc_exception_throw
2  CoreFoundation                 0x1ceff67bc -[__NSCFArray count]
3  Photos                         0x1ddb2500c -[PHFetchResult objectAtIndex:]
4  photo_manager                  0x1032f4b34 (Missing)
5  photo_manager                  0x1032f47a4 (Missing)
6  libdispatch.dylib              0x1ceb20a38 _dispatch_call_block_and_release
7  libdispatch.dylib              0x1ceb217d4 _dispatch_client_callout
8  libdispatch.dylib              0x1ceafcdec _dispatch_lane_serial_drain$VARIANT$armv81
9  libdispatch.dylib              0x1ceafd92c _dispatch_lane_invoke$VARIANT$armv81
10 libdispatch.dylib              0x1ceb05e08 _dispatch_workloop_worker_thread
11 libsystem_pthread.dylib        0x1ced01114 _pthread_wqthread
12 libsystem_pthread.dylib        0x1ced03cd4 start_wqthread

and

Fatal Exception: NSRangeException
*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray

Fatal Exception: NSRangeException
0  CoreFoundation                 0x1cf0e127c __exceptionPreprocess
1  libobjc.A.dylib                0x1ce2bb9f8 objc_exception_throw
2  CoreFoundation                 0x1ceff67bc -[__NSCFArray count]
3  Photos                         0x1ddb2500c -[PHFetchResult objectAtIndex:]
4  photo_manager                  0x1032f4b34 (Missing)
5  photo_manager                  0x1032f47a4 (Missing)
6  libdispatch.dylib              0x1ceb20a38 _dispatch_call_block_and_release
7  libdispatch.dylib              0x1ceb217d4 _dispatch_client_callout
8  libdispatch.dylib              0x1ceafcdec _dispatch_lane_serial_drain$VARIANT$armv81
9  libdispatch.dylib              0x1ceafd92c _dispatch_lane_invoke$VARIANT$armv81
10 libdispatch.dylib              0x1ceb05e08 _dispatch_workloop_worker_thread
11 libsystem_pthread.dylib        0x1ced01114 _pthread_wqthread
12 libsystem_pthread.dylib        0x1ced03cd4 start_wqthread

My assumption is that requesting too many assets at once is the issue here. I'm happy to be proved wrong and given ideas regarding alternative solutions, though. πŸ™‚

Describe the solution you'd like I'm currently working on a second paginated version of getAssetPathList.
Ideally one can pass in both, the current page (e.g. page=1), as well as the number of items per page (e.g. per_page=40). However, I'd also be happy with a fixed number of per_page at the moment. What's most important to me is that pagination is possible.

Since the largest issues in our team currently are on iOS devices, that's the first thing I'm tackling -- and simply hope that there are good solutions for Android as well.

In fact, this is the lead I'm trying to follow here as it looks pretty promising: https://stackoverflow.com/questions/47936192/how-to-add-pagination-to-phasset-fetching-from-photos-framework

Let's see how this turns out.

Additional context Unfortunately I have never in my life touched Objective C and find the learning curve just for reading the syntax incredibly steep. Additionally, my Java-skills are also sorely lacking. If this was Dart, Go, PHP or Javascript, adding pagination would merely be routine work. However, this is a bit more involved for me.

One of the issues is that even if I manage to implement the pagination for getGalleryIdList, there is still other state in the ImageScanner-class that would have to be adjusted, specifically the logic sorrounding refreshGallery and refreshGalleryDict.
I'm willing to fight my way through this, though, and see what comes up.

The reason I open this ticket is that I have two questions:

  1. Since I'm an absolute n00b in both ObjectiveC, as well as Java, do you believe that this is something you could implement in the library?
  2. If you are not willing to implement this for any reason, which is absolutely fine, are there any pointers you can give me? Any pieces of advice? Anything I should keep in mind?

Other than this: thanks for this great library which is sorely needed on Flutter. This is the first library that makes scrolling through a large list of images a breeze. After lots of banging our heads against the wall this library is a life-saver. Thanks for the hard work and sharing it! πŸ‘

CaiJingLong commented 5 years ago

Pagination is a reasonable requirement, but I may not have that much time to finish it soon.

SvenSchoene commented 5 years ago

That is fully understandable.

I have sent you an email to the address in your Github profile. Let me know if that's something you're willing to talk about. If not: Again, I fully understand. πŸ™‚

CaiJingLong commented 5 years ago

The feature has merged in #94 , but for some other reason, I will update it to the pub within a few days.