skip to Main Content

I’m new to Flutter and would love some help with an error.

While using the image_picker package, I noticed that I’m getting a value of null returned when I try to select an image from ios photo gallery.
(Specifically, [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_storage/object-not-found] No object exists at the desired reference.)

I read the package documentation where it says this is a known issue and to try it on a real device. I tried it on my real device an only got the desired result once. Can someone please shed some light on this? Below, I have provided the necessary code and a look and my flutter doctor. Thanks in advance!

P.S. To be clear, I am trying to test this on my physical ios device(iPhone 14 Pro Max), as I am aware of the issue with the ios Simulator and the image_picker package.

Please let me know if I need to provide more information to resolve this issue!

 String? photoUrl = " ";
File? image;

 Future pickImage() async {
    try {
      final image = await ImagePicker()
          .pickImage(source: ImageSource.gallery, requestFullMetadata: false);
      if (image == null) return;

      Reference ref = FirebaseStorage.instance.ref().child("profilepic.jpg");
      await ref.putFile(File(image.path));
      await ref.getDownloadURL().then((value) {print(value); setState(() {
        photoUrl = value;
      });});
    } on PlatformException catch (e) {
      debugPrint('Failed to pick image: $e');
    }
  }

  profilePic() {
    final Size size = MediaQuery.of(context).size;
    return SizedBox(
      height: size.height * 0.185,
      width: double.infinity,
      child: Column(children: [
        const Spacer(),
        photoUrl != null
            ?
            GestureDetector(
                onTap: () {
                  pickImage();
                },
                child: Container(
                  height: 120,
                  width: 160,
                  decoration: const BoxDecoration(
                    color: Colors.blue,
                    borderRadius: BorderRadius.all(
                      Radius.circular(20),
                    ),
                  ),
                  child: const Icon(
                    Icons.person,
                    size: 50,
                    color: Colors.white,
                  ),
                ),
              ):Image.network(photoUrl!),
      ],
      ),
    );
  }
[✓] Flutter (Channel stable, 3.7.0, on macOS 12.6.1 21G217 darwin-arm64, locale en-US)
• Flutter version 3.7.0 on channel stable at /Users/myronsp/Developer/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b06b8b2710 (9 days ago), 2023-01-23 16:55:55 -0800
• Engine revision b24591ed32
• Dart version 2.19.0
• DevTools version 2.20.1

[✓] Android toolchain – develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/myronsp/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• ANDROID_HOME = /Users/myronsp/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
• All Android licenses accepted.

[✓] Xcode – develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3

[✓] Chrome – develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
• 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.15+0-b2043.56-8887301)

[✓] Connected device (5 available)
• sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator)
• Myron’s iPhone (mobile) • 00008120-00016D500A80C01E • ios • iOS 16.0.2 20A380
• iPhone 14 Pro Max (mobile) • B8ACBFEA-35E5-4D2C-810C-46100D17EE63 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.6.1 21G217 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119

2

Answers


  1. hope you are included all the required steps for accessing gallery in android and iOS as mentioned here.

    other chances are out dated packages in the flutter project.

    please check the following link to rectify that link

    Login or Signup to reply.
  2. If i am understanding correctly, below your spacer widget in your column children the condition should be photoUrl == null instead of photoUrl != null.

    It would be good if you can share some findings.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search