Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Wp api for flutter

I am trying to use the wordpress api, but it throws me an error when entering the url.
Error: The argument type "String" can’t be assigned to the parameter type Uri

Could someone explain the error to me and tell me how the code should look? Thanks

import 'package:http/http.dart' as http;
import 'dart:convert';


Future<List> blog() async {
  final response = await http.get(('https://bauk.blog/wp-json/wp/v2/posts?_embed': {"Accept": "application/json"}));
  var convertirajson = jsonDecode(response.body);
  return convertirajson;
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to parse the url before passing it to http.get()

For that declare your url variable like this:

var url = Uri.parse('https://bauk.blog/wp-json/wp/v2/posts?_embed');

And then pass it to http.get() like this

http.get((url: {...} ));

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading