Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

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);
    }
  }
like image 227
nayo Avatar asked Dec 03 '25 04:12

nayo


2 Answers

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.

like image 191
K_Chandio Avatar answered Dec 05 '25 19:12

K_Chandio


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.

like image 39
Goutham J B Avatar answered Dec 05 '25 21:12

Goutham J B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!