var dio =Dio();Response response =await dio.get('https://google.com');print(response.data);
The above example will make a request to http://google.com and print the result.
Additional Examples
Performing a GET request:
import'package:dio/dio.dart';Response response;Dio dio =newDio();response =await dio.get("/test?id=12&name=wendu");print(response.data.toString());// Optionally the request above could also be done asresponse =await dio.get("/test", queryParameters: {"id":12, "name":"wendu"});print(response.data.toString());
You can create an instance of Dio with an optional BaseOptions object:
Dio dio =newDio(); // with default Options// Set default configsdio.options.baseUrl ="https://www.xx.com/api";dio.options.connectTimeout =5000; //5sdio.options.receiveTimeout =3000;// or new Dio with a BaseOptions instance.BaseOptions options =newBaseOptions( baseUrl:"https://www.xx.com/api", connectTimeout:5000, receiveTimeout:3000,);Dio dio =newDio(options);