Home > Net >  Wp api for flutter
Wp api for flutter

Time:04-24

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

CodePudding user response:

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: {...} ));

  • Related