How to get images from bing web search apiv7 in my flutter application
382
webSearchUrl
is pointing to a web page with search results, that's why it's not working inside Image.network()
. Try to change it to contentUrl
for the full image ur; from third party web or thumbnailUrl
for the bing hosted small thumbnail url.
Author by
Azhan Khan
Updated on December 09, 2022Comments
-
Azhan Khan over 1 year
How can I use Bing web search Apiv7 to get photos in my flutter application?
I got the API and end points from the official site but I was not able to get JSON file to call it in item builder child.
Example-child:
new Image.network('${data['value']['webSearchUrl']}'
I don't know what to put in this child and where to put the API key...
class _PageOneState extends State<PageOne> { @override Widget build(BuildContext context) { return Scaffold( body: new FutureBuilder( future: getPics(), builder: (context, snapShot){ Map data = snapShot.data; if(snapShot.hasError){ print(snapShot.error); return Text('Failed to get data from server', style: TextStyle(color: Colors.red, fontSize: 22.0),); }else if(snapShot.hasData){ return new Center( child: new ListView.builder( itemCount: data.length, itemBuilder: (context, index){ return new Column( children: <Widget>[ new Container( child: new InkWell( onTap: (){}, child: new Image.network( '${data['value']['webSearchUrl']}' ), ), ), new Padding(padding: const EdgeInsets.all(5.0)), ], ); }), ); } else if(!snapShot.hasData){ return new Center(child: CircularProgressIndicator(),); } } ), ); and below the code - Future<Map> getPics() async{ String url = 'https://api.cognitive.microsoft.com/bing/v7.0/images'; http.Response response = await http.get(url); return json.decode(response.body); }