diff --git a/CHANGELOG.md b/CHANGELOG.md index 448c0cf9..2502c758 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ that can be found in the LICENSE file. --> - Fix namespace on Android. - Remove the package definition from the manifest. - Use `math.pow(2^63)-1` to make Web compile work again. +- Fix: the `end` of `PhotoManager.getAssetListRange` is handled incorrectly.(#962) ## 2.7.0 diff --git a/example/lib/page/developer/issues_page/issue_962.dart b/example/lib/page/developer/issues_page/issue_962.dart new file mode 100644 index 00000000..82e129b3 --- /dev/null +++ b/example/lib/page/developer/issues_page/issue_962.dart @@ -0,0 +1,89 @@ +import 'package:flutter/material.dart'; +import 'package:oktoast/oktoast.dart'; +import 'package:photo_manager/photo_manager.dart'; + +import 'issue_index_page.dart'; + +class Issue962 extends StatefulWidget { + const Issue962({Key? key}) : super(key: key); + + @override + State createState() => _Issue962State(); +} + +class _Issue962State extends State with IssueBase { + int start = 0; + int end = 5; + + ValueNotifier logNotifier = ValueNotifier(''); + + void onChange() async { + if (start >= end) { + logNotifier.value = 'start must less than end'; + return; + } + + final assetList = await PhotoManager.getAssetListRange( + start: start, + end: end, + filterOption: FilterOptionGroup( + imageOption: const FilterOption(needTitle: true), + videoOption: const FilterOption(needTitle: true), + orders: [ + const OrderOption(type: OrderOptionType.createDate), + ], + ), + ); + + logNotifier.value = 'The assetList count: ${assetList.length}'; + } + + final node = FocusScopeNode(); + + @override + void dispose() { + node.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return buildScaffold([ + TextFormField( + initialValue: start.toString(), + decoration: const InputDecoration( + labelText: 'start', + ), + onChanged: (value) { + start = int.tryParse(value) ?? 0; + onChange(); + }, + ), + TextFormField( + initialValue: end.toString(), + decoration: const InputDecoration( + labelText: 'end', + ), + onChanged: (value) { + end = int.tryParse(value) ?? 0; + onChange(); + }, + ), + buildButton('Reproduct issue 962', onChange), + AnimatedBuilder( + animation: logNotifier, + builder: (context, w) { + return Text( + logNotifier.value, + style: const TextStyle( + fontSize: 12, + ), + ); + }, + ), + ]); + } + + @override + int get issueNumber => 962; +} diff --git a/example/lib/page/developer/issues_page/issue_index_page.dart b/example/lib/page/developer/issues_page/issue_index_page.dart index 68654ae9..af5f4a50 100644 --- a/example/lib/page/developer/issues_page/issue_index_page.dart +++ b/example/lib/page/developer/issues_page/issue_index_page.dart @@ -7,6 +7,7 @@ import 'package:url_launcher/url_launcher.dart'; import 'issue_734.dart'; import 'issue_918.dart'; +import 'issue_962.dart'; class IssuePage extends StatelessWidget { const IssuePage({ @@ -23,6 +24,7 @@ class IssuePage extends StatelessWidget { children: [ Issue734Page(), Issue918Page(), + Issue962(), ], ), ); diff --git a/ios/Classes/core/PMManager.m b/ios/Classes/core/PMManager.m index ca2db032..eb19d940 100644 --- a/ios/Classes/core/PMManager.m +++ b/ios/Classes/core/PMManager.m @@ -149,7 +149,7 @@ - (NSUInteger)getAssetCountWithType:(int)type option:(NSObject *)f PHFetchResult *result = [PHAsset fetchAssetsWithOptions:options]; NSUInteger endOffset = end; - if (endOffset < result.count) { + if (endOffset > result.count) { endOffset = result.count; }