Skip to content
Branch: master
Find file Copy path
Find file Copy path
duwen improve generic support 8c667b3 Mar 4, 2019
0 contributors

Users who have contributed to this file

37 lines (31 sloc) 1.15 KB
import 'package:dio/dio.dart';
main() async {
Dio dio = Dio(
baseUrl: "",
method: "GET",
Response response;
//No generic type, the ResponseType will work.
response = await dio.get("/test");
print( is Map);
Response<Map<String,dynamic>> r0= await dio.get("/test");
response = await dio.get<Map>("/test");
print( is Map);
response = await dio.get<String>("/test");
print( is String);
response = await dio.get("/test", options: Options(responseType: ResponseType.plain));
print( is String);
// the content of "" is a html file, So it can't be convert to Map type,
// it will cause a FormatException.
response = await dio.get<Map>("").catchError(print);
// This works well.
response = await dio.get("");
// This works well too.
response = await dio.get<String>("");
// This is the recommended way.
Response<String> r = await dio.get<String>("");
You can’t perform that action at this time.