0
votes

I am trying to add a default profile picture for every user to chooses the signIn method as signinwithEmail.

Here is my code :

Future<FirebaseUser> signUpWithEmail(String email, String password) async {
    AuthResult authResult = await firebaseAuth.createUserWithEmailAndPassword(
        email: email, password: password);

    String url = 'assets/images/default_icon.png';

    if (authResult != null) {
      UserUpdateInfo updateInfo = UserUpdateInfo();
      updateInfo.displayName = email;
      updateInfo.photoUrl = url;

      FirebaseUser firebaseUser = authResult.user;

      if (firebaseUser != null) {
        await firebaseUser.updateProfile(updateInfo);

        await firebaseUser.reload();

        FirebaseUser currentuser = await firebaseAuth.currentUser();


        return currentuser;
      }
    }
    return null;
  }

I have added the image to my assets folder still I am getting an error as : ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ The following ArgumentError was thrown resolving an image codec: Invalid argument(s): No host specified in URI file:///assets/images/default_image.png

When the exception was thrown, this was the stack: #0 _HttpClient._openUrl (dart:_http/http_impl.dart:2313:9) #1 _HttpClient.getUrl (dart:_http/http_impl.dart:2208:48) #2 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:90:59) #3 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:51:14) #4 ImageProvider.resolveStreamForKey. (package:flutter/src/painting/image_provider.dart:505:13) #5 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:360:22) #6 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:503:80) #7 ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:108:19)

Image provider: NetworkImage("assets/images/default_image.png", scale: 1.0) Image key: NetworkImage("assets/images/default_image.png", scale: 1.0) ════════════════════════════════════════════════════════════════════════════════════════════════════

1
You cant use an Asset Image inside Network Image. - Dev

1 Answers

1
votes

The URL that you are saving in Firebase is the path to your local image asset, which cannot be passed to a NetworkImage widget.

In other words, the local image is not a valid URL or hosted on the internet, so you cannot use it in the NetworkImage widget.

Now, to solve your issue, you can do two things:

  1. Check whether the user has chosen the signInWithEmail method & use Image.asset instead of NetworkImage.

  2. Upload your image to your server / Firebase & provide the uploaded image's URL.