Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 27, 2025

Fixes #1343

PhotoManager.presentLimited() throws type '() => String' is not a subtype of type '() => int' of 'ifAbsent' on iOS.

Root cause: When presentLimited passes {'type': type.value} to invokeMethod, Dart infers Map<String, int>. The putIfAbsent callback returns a String (cancel token key), causing the type mismatch.

Fix:

  • Create a Map<String, dynamic> copy before calling putIfAbsent to ensure the map accepts mixed value types
// Before: fails when arguments is Map<String, int>
arguments.putIfAbsent(PMConstants.cancelTokenKey, () => PMCancelToken().key);

// After: works with any map type
final Map<String, dynamic> args = Map<String, dynamic>.from(arguments);
args.putIfAbsent(PMConstants.cancelTokenKey, () => PMCancelToken().key);

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dart.dev
    • Triggering command: /usr/bin/curl curl -fsSL REDACTED -o /tmp/dart-sdk.zip (dns block)
  • dl-ssl.google.com
    • Triggering command: /usr/bin/wget wget -qO- REDACTED (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug report] presentLimited throws type error on 3.8.0+</issue_title>
<issue_description>### Version

3.8.0, 3.8.1

Platforms

iOS

Device Model

iPhone 13pro(iOS18.6)

flutter info

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.35.5, on macOS 15.1.1 24B91 darwin-arm64 (Rosetta), locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2025.2)
[✓] VS Code (version 1.106.2)
[✓] Connected device (3 available)
    ! Error: Browsing on the local area network for iPhone12. Ensure the device is unlocked and attached with a cable or associated with the same local
      area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for iPhone15 Pro. Ensure the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for iPhone14. Ensure the device is unlocked and attached with a cable or associated with the same
      local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for iPhone 16 Pro. Ensure the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same
      local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources

• No issues found!

How to reproduce?

  1. Upgrade to PhotoManager 3.7.1 → 3.8.0 or 3.8.1
  2. Call PhotoManager.presentLimited()

Logs

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: type '() => String' is not a subtype of type '() => int' of 'ifAbsent'
fluttercandies/flutter_photo_manager#0      _LinkedHashMapMixin.putIfAbsent (dart:_compact_hash:657)
fluttercandies/flutter_photo_manager#1      PMMethodChannel.invokeMethod (package:photo_manager/src/internal/plugin.dart:42)
fluttercandies/flutter_photo_manager#2      PhotoManagerPlugin.presentLimited (package:photo_manager/src/internal/plugin.dart:668)
fluttercandies/flutter_photo_manager#3      PhotoManager.presentLimited (package:photo_manager/src/managers/photo_manager.dart:104)

Example code (optional)

Contact

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@fluttercandies-dev **AI Summary:** The `presentLimited` method throws a type error after upgrading to versions 3.8.0 or 3.8.1. The error indicates a mismatch between expected and actual return types.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix type error in presentLimited on iOS 3.8.0+ Fix presentLimited type error on 3.8.0+ Nov 27, 2025
Copilot AI requested a review from AlexV525 November 27, 2025 07:18
Copilot finished work on behalf of AlexV525 November 27, 2025 07:18
@github-actions
Copy link

Download apk from here for 392f6c1

@AlexV525 AlexV525 marked this pull request as ready for review November 27, 2025 08:59
@AlexV525 AlexV525 merged commit c301dd3 into main Nov 27, 2025
13 checks passed
@AlexV525 AlexV525 deleted the copilot/fix-present-limited-type-error branch November 27, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug report] presentLimited throws type error on 3.8.0+

2 participants