2

I am making a restaurant app that uses the Yelp API to return search results about restaurants, and I thought the best way to do that would be through the Dio package. I have a feeling that my problem is very simple but I just don't know how to solve it even after hours of research.

Here is the search page StatefulWidget:

class SearchPage extends StatefulWidget {
 final api = Dio(BaseOptions(baseUrl: 'https://api.yelp.com/v3/businesses/search', headers: {
   'Authorization': '<MY_API_KEY>',
 }));

 @override
 State<SearchPage> createState() => _SearchPageState();
}

I actually put in my real API key above^

Then I call this function when the user searches from the search bar, and pass in their search to the query parameter:

void searchResturaunts(String query) async {
    final response = await widget.api.get('',queryParameters: {
      'q': query,
    });
  }

But I always get this error when I try to run it:

Unhandled Exception: DioError [DioErrorType.response]: Http status error [400]

I'm not sure how to make Dio work with my API from Yelp.

Here is the Yelp Fusion docs: https://www.yelp.com/developers/documentation/v3/get_started

Nimantha
  • 6,405
  • 6
  • 28
  • 69

0 Answers0