Skip to content

Commit

Permalink
fix: presentLimited for android API 34 (#1052)
Browse files Browse the repository at this point in the history
Signed-off-by: CaiJingLong <[email protected]>
  • Loading branch information
CaiJingLong authored Dec 1, 2023
1 parent 568b946 commit 5202dc9
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ that can be found in the LICENSE file. -->

# CHANGELOG

## 3.0.0-dev.4

- Fix presentLimit have no result on android API 34. [#1051](https://github.com/fluttercandies/flutter_photo_manager/issues/1051)

## 3.0.0-dev.3

- Fix: Dispatch channel in main thread on Darwin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ abstract class PermissionDelegate {

protected fun requestPermission(
permissionsUtils: PermissionsUtils,
permission: MutableList<String>
permission: MutableList<String>,
requestCode: Int = PermissionDelegate.requestCode
) {
val activity = permissionsUtils.getActivity()
?: throw NullPointerException("Activity for the permission request is not exist.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class PermissionDelegate34 : PermissionDelegate() {
permissions.add(mediaImage)
}

requestPermission(permissionsUtils, permissions)
requestPermission(permissionsUtils, permissions, limitedRequestCode)
}

override fun getAuthValue(
Expand Down
40 changes: 40 additions & 0 deletions example/lib/page/developer/issues_page/issue_1051.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:photo_manager_example/page/developer/issues_page/issue_index_page.dart';

class Issus1051 extends StatefulWidget {
const Issus1051({Key? key}) : super(key: key);

@override
State<Issus1051> createState() => _Issus1051State();
}

class _Issus1051State extends State<Issus1051> with IssueBase<Issus1051> {
Future<void> _test() async {
final status = await PhotoManager.requestPermissionExtend();
if (status.hasAccess) {
await PhotoManager.presentLimited();
print('present limited');
}

print('status: $status');
}

@override
Widget build(BuildContext context) {
return buildScaffold([
buildButton(
'Test presentLimited',
_test,
),
]);
}

@override
int get issueNumber => 1051;

@override
List<TargetPlatform>? get supportPlatforms => [
TargetPlatform.android,
];
}
84 changes: 63 additions & 21 deletions example/lib/page/developer/issues_page/issue_index_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:oktoast/oktoast.dart';
Expand All @@ -7,6 +9,7 @@ import 'package:url_launcher/url_launcher.dart';

import 'issue_1025.dart';
import 'issue_1031.dart';
import 'issue_1051.dart';
import 'issue_734.dart';
import 'issue_918.dart';
import 'issue_962.dart';
Expand All @@ -18,35 +21,58 @@ class IssuePage extends StatelessWidget {
Key? key,
}) : super(key: key);

List<Widget> currentPlatformWidgets(BuildContext context, List<Widget> list) {
final res = <Widget>[];

for (final item in list) {
if (item is StatefulWidget) {
// ignore: invalid_use_of_protected_member
final state = (item).createState();
if (state is IssueBase) {
if (state.supportCurrentPlatform()) {
res.add(item);
}
} else {
res.add(item);
}
}
}

return res;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Issue page list'),
),
body: NavColumn(
titleBuilder: (w) {
if (w is StatefulWidget) {
// ignore: invalid_use_of_protected_member
final state = (w).createState();

if (state is IssueBase) {
final issueNumber = state.issueNumber;
return 'Issue $issueNumber';
titleBuilder: (w) {
if (w is StatefulWidget) {
// ignore: invalid_use_of_protected_member
final state = (w).createState();

if (state is IssueBase) {
final issueNumber = state.issueNumber;
return 'Issue $issueNumber';
}
}
}
return w.toStringShort();
},
children: const <Widget>[
Issue734Page(),
Issue918Page(),
Issue962(),
Issue1025Page(),
Issue988(),
Issue1031Page(),
Issue979(),
],
),
return w.toStringShort();
},
children: currentPlatformWidgets(
context,
const <Widget>[
Issue734Page(),
Issue918Page(),
Issue962(),
Issue1025Page(),
Issue988(),
Issue1031Page(),
Issue979(),
Issus1051(),
],
)),
);
}
}
Expand All @@ -59,6 +85,22 @@ mixin IssueBase<T extends StatefulWidget> on State<T> {

final List<String> _logs = [];

List<TargetPlatform>? get supportPlatforms {
return null;
}

bool supportCurrentPlatform() {
final platforms = supportPlatforms;
if (platforms == null) {
return true;
}
return platforms
.map((e) => e.toString().toLowerCase())
.where((element) =>
element.contains(Platform.operatingSystem.toLowerCase()))
.isNotEmpty;
}

void addLog(String log) {
log = '[${DateTime.now().toIso8601String()}] $log';
_logs.insert(0, log);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: photo_manager
description: A Flutter plugin that provides assets abstraction management APIs on Android, iOS, and macOS.
repository: https://github.com/fluttercandies/flutter_photo_manager
version: 3.0.0-dev.3
version: 3.0.0-dev.4

environment:
sdk: ">=2.13.0 <4.0.0"
Expand Down

0 comments on commit 5202dc9

Please sign in to comment.