Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to select image using flutter image picker on iOS simulator

I am learning how to select images from gallery. I have implemented flutter image picker for the same. But when I try to select the image in simulator, I am not able to do so.

Please help

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.26.0-17.3.pre, on macOS 11.1 20C69 darwin-arm, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Android Studio (version 4.1)
[✓] Connected device (1 available)

• No issues found!

My code

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

void main() {
  runApp(MaterialApp(
    home: Play(),
    // theme: ThemeData.dark(),
  ));
}

class Play extends StatefulWidget {
  @override
  _PlayState createState() => _PlayState();
}

class _PlayState extends State<Play> {
  File _file;

  ImagePicker _picker = ImagePicker();

  PickedFile _pickedFile;

  Future _getImageFromGallery() async {
    print("Getting Image from Gallery.");
    _pickedFile = await _picker.getImage(source: ImageSource.gallery);
    print(_pickedFile.path);
    setState(() {
      _file = File(_pickedFile.path);
    });
  }

  Future _getImageFromCamera() async {
    print("Getting Image from Camera.");
    _pickedFile = await _picker.getImage(source: ImageSource.camera);
    setState(() {
      _file = File(_pickedFile.path);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Play"),
      ),
      body: Column(
        children: [
          Center(
            child: ElevatedButton(
                onLongPress: _getImageFromCamera,
                onPressed: _getImageFromGallery,
                child: Text("Get Image")),
          ),
          _file != null
              ? Image.file(
                  _file,
                  height: 200,
                )
              : Icon(
                  Icons.image,
                  size: 100,
                ),
        ],
      ),
    );
  }
}

I am using M1 Mac air. I have switched to beta channel to get rid of some verbose error. Everything is working fine. Just, when I click on an image nothing happens. It doesn't get selected.

like image 770
OM KALE Avatar asked Feb 08 '21 14:02

OM KALE


1 Answers

I've tried your code and it works on my simulator:

enter image description here

There are discussions online including this GitHub post, that this could be an Apple bug and no known workaround.

In fact, there are people in Apple Developer Forums reports this kind of issue.

like image 119
MαπμQμαπkγVπ.0 Avatar answered Dec 05 '22 20:12

MαπμQμαπkγVπ.0