Complete the code to create a Dio instance for HTTP requests.
final dio = Dio([1]);The Dio constructor accepts BaseOptions to configure base URL, headers, and more.
Complete the code to make a GET request using Dio.
final response = await dio.[1]('https://example.com/data');
Use get method to fetch data from a URL with Dio.
Fix the error in the code to add a request interceptor in Dio.
dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) async {
options.headers['Authorization'] = 'Bearer [1]';
return handler.next(options);
}));The options.headers expects a string token. Use a variable token holding the token string.
Fill both blanks to create a POST request with JSON data using Dio.
final response = await dio.[1]('https://example.com/login', data: [2]);
Use post method to send data. The data parameter accepts a map for JSON body.
Fill all three blanks to handle Dio errors with try-catch.
try { final response = await dio.[1]('https://example.com/data'); print(response.[2]); } on DioException catch ([3]) { print('Request failed'); }
Use get to fetch data. Access response body with data. Catch error with variable e.
