Getting error for Flutter http.get('url') parameter It's not accepting Url String


I’m trying to fetch all json data which api returns, to use it in my flutter app

var api="";
var res=await http.get(api);
drinks= jsonDecode(res.body)["drinks"];

but it gives red underline under api parameter in http.get(api) function call that "argument of type string cannot be converted to URI"
How to Resolve this? I even tried using
res=await http.get(Uri.https('','/api/json/v1/1/filter.php?c=Cocktail'));

but got error "Error connecting to the service protocol: failed to connect to"/_fprblq_tiY=/"


Instead of using Uri.https(), try using Uri.parse()

Answered By – S. M. JAHANGIR

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *