Skip to content

IOS Image Picker Never Return when no Image Selected #82519

@Peng-Qian

Description

@Peng-Qian

Problem

if no image selected, the process never return/end/complete.

Sample Code

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: LabScreen(title: 'Flutter Demo Home Page'),
    );
  }
}

class LabScreen extends StatefulWidget {
  LabScreen({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _LabScreenState createState() => _LabScreenState();
}

class _LabScreenState extends State<LabScreen> {
  bool _loading = false;
  File? _imageFile;

  void _selectedImage() async {
    print('start select image');
    setState(() {
      _loading = true;
    });
    final selectedImage = await ImagePicker().getImage(
      source: ImageSource.gallery,
      maxHeight: 480,
      maxWidth: 480,
    );

    if (selectedImage != null) {
      print('image selected: ${selectedImage.path}');
      setState(() {
        _imageFile = File(selectedImage.path);
        _loading = false;
      });
    } else {
      print('no image selected');
      setState(() {
        _loading = false;
      });
    }
    print('end select image');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: _loading
            ? CircularProgressIndicator()
            : Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    _imageFile != null ? _imageFile!.path.toString() : 'no file',
                  ),
                ],
              ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _selectedImage,
        tooltip: 'change image',
        child: Icon(Icons.add),
      ),
    );
  }
}

expected:

flutter: start select image
flutter: no image selected
flutter: end select image

actual:

flutter: start select image

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 2.3Found to occur in 2.3has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: image_pickerThe Image Picker plugin.packageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions