lost connection to device. flutter when pick image using simulator

Viewed 58

I trying to get Image from Simulator but it crashes when click as the below GIF:

error

and this is the code snippet:

  Widget buildImage() => GestureDetector(
        child: buildAvatar(),
        onTap: () async {
          final image =
              await ImagePicker().getImage(source: ImageSource.gallery);

          if (image == null) return;

          final directory = await getApplicationDocumentsDirectory();
          final id = '_${widget.idUser}_${Uuid().v4()}';
          final imageFile = File('${directory.path}/${id}_avatar.png');
          final newImage = await File(image.path).copy(imageFile.path);

          setState(() => user = user.copy(imagePath: newImage.path));
        },
      );

and this is the error:

simple

Note that it works fine on real Android device

0 Answers
Related