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

Time:05-31

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);
    }
  }

CodePudding user response:

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.

CodePudding user response:

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.

  • Related