Repository: flutter
Issue: [image_picker]  App freezes on Backgrounding During Multi-Image Selection
Labels: platform-ios,p: image_picker,package,e: OS-version specific,P2,team-ios,triaged-ios

### Steps to reproduce


This issue occurs when the app is sent to the background after selecting a large number of images with `image_picker` before the `pickMultiImage` future completes. 

- Ensure you have the `image_picker` plugin installed in your Flutter project.
- Implement a functionality to select multiple images using `image_picker.pickMultiImage()`.
- Select a high number of images from the picker (e.g. 50 or more) to trigger the issue.
- After selecting images but before the `pickMultiImage` future resolves, send the app to the background.
- Return to the app 

This is similar to #90779. While #90779 addresses performance slowdowns during pickMultiImage with large files, this new issue addresses a bug that occurs specifically when the app is sent to the background before pickMultiImage finishes processing a large number of images, independent of image size . This renders the app unusable, which differs from the performance delays mentioned in the existing issue. Therefore this new issue is to document this bug and investigate potential solutions.

Tested with 
- image_picker 1.0.7 and 1.0.4
- on iOS simulators iPhone 12 (iOS 16.4), iPhone 15 (iOS 17.4) 
- on real device on iPhone 12 iOS 16.61

### Expected results

- The app should be able to go into the background while pickMultiImage is processing images without any problems (i.e., gracefully handle it). It shouldn't crash or freeze.
- If the the selection is interrupted, the image_picker package should throw an error. This way, devs can be informed and take appropriate actions (like notifying the user or retrying the selection).

### Actual results

The app is and remains unresponsive when bringing the app back to the foreground

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(const MainApp());

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) => const MaterialApp(home: App());
}

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  List<File> imageFiles = [];
  bool isLoading = false;

  _openGallery() async {
    setState(() => isLoading = true);

    try {
      var pictures = await ImagePicker().pickMultiImage();

      if (pictures.isEmpty) {
        debugPrint('Picker returned without any image selected');
      } else {
        imageFiles = pictures.map((picture) => File(picture.path)).toList();
      }
    } catch (e) {
      debugPrint('Error picking images: $e');
    } finally {
      setState(() => isLoading = false);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('View Image'),
      ),
      body: Center(
        child: isLoading
            ? const CircularProgressIndicator()
            : Column(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  imageFiles.isEmpty
                      ? const Text('No Image Selected')
                      : Flexible(
                          child: Column(
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              const Text('Selected Images'),
                              const SizedBox(height: 10.0),
                              SizedBox(
                                height: 200.0,
                                child: ListView.builder(
                                  shrinkWrap: true,
                                  scrollDirection: Axis.horizontal,
                                  itemCount: imageFiles.length,
                                  itemBuilder: (context, index) {
                                    return Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: Image.file(
                                        imageFiles[index],
                                        width: 200.0,
                                        height: 200.0,
                                      ),
                                    );
                                  },
                                ),
                              ),
                            ],
                          ),
                        ),
                  ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Colors.amber,
                    ),
                    child: const Text(
                      'Select Image',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 16.0,
                      ),
                    ),
                    onPressed: () => _openGallery(),
                  ),
                ],
              ),
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/34327253/8c277313-324b-4b95-abfa-cd2c4ec5c91a
 
</details>


### Logs

<details open><summary>Logs</summary>
No log output
</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.4 23E214 darwin-arm64, locale en-CA)
    • Flutter version 3.16.9 on channel stable at /Users/lenzpaul/dev/opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (8 weeks ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/lenzpaul/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.87.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.84.0

[✓] Connected device (5 available)
     • iPhone 15 (mobile)        • 3C7C7551-A280-425F-A465-FCC6AA3F84A2 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-4
      (simulator)
    • iPhone 12 (mobile)        • C84069BC-654F-4021-9401-63B7803AA945 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4
      (simulator)
    • macOS (desktop)           • macos                                • darwin-arm64   • macOS 14.4 23E214 darwin-arm64
    • Chrome (web)              • chrome                               • web-javascript • Google Chrome 122.0.6261.129

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>