Skip to content

Commit

Permalink
fix: the end of PhotoManager.getAssetListRange
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiJingLong committed Aug 4, 2023
1 parent 1819691 commit 194134b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
89 changes: 89 additions & 0 deletions example/lib/page/developer/issues_page/issue_962.dart
Original file line number Diff line number Diff line change
@@ -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<Issue962> createState() => _Issue962State();
}

class _Issue962State extends State<Issue962> with IssueBase<Issue962> {
int start = 0;
int end = 5;

ValueNotifier<String> logNotifier = ValueNotifier<String>('');

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;
}
2 changes: 2 additions & 0 deletions example/lib/page/developer/issues_page/issue_index_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -23,6 +24,7 @@ class IssuePage extends StatelessWidget {
children: <Widget>[
Issue734Page(),
Issue918Page(),
Issue962(),
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/core/PMManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ - (NSUInteger)getAssetCountWithType:(int)type option:(NSObject<PMBaseFilter> *)f
PHFetchResult<PHAsset *> *result = [PHAsset fetchAssetsWithOptions:options];

NSUInteger endOffset = end;
if (endOffset < result.count) {
if (endOffset > result.count) {
endOffset = result.count;
}

Expand Down

0 comments on commit 194134b

Please sign in to comment.