3

I'm getting the below error in my code when I try to display the profile image which is connected through my API. how to resolve this. how to display profile picture correctly.

Invalid argument(s): No host specified in URI file:///

//display profile picture

 CircleAvatar(
                  radius: 18,
                  child: Image.network(profilePicture,  fit: BoxFit.cover,)),

//API integration

 List<Map<String, dynamic>>? responseJson;
  var response;
  getdata() async {
    try {
      response = await Dio().get(BASE_API + "user/getUserById/" +loginUserData["id"]!);
      print("response: $response");
      response = json.decode(response.toString());
      for(var items in response){
        responseJson!.add(items);
      }
      setState(() {
        profilePicture = responseJson![0]["profilePicture"]; // new line added
      });
      // print(responseJson['data']['userName']);
    } catch (e) {
      print(e);
    }
  }

2 Answers 2

1

Print this profile picture path and search on browser to check if its exist or not. Furthermore image path returning from API usually doesn't contain base URL, if so you need to concatenate base URL in profileImage address.

Sign up to request clarification or add additional context in comments.

Comments

1

Print this BASE_API and check if it contains http:// or https:// at the beginning. The Constant BASE_API should contain http:// or https:// at the beginning.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.