I have a long string of around 1042 characters stored in the database, I tried hitting API to retrieve this string, when I ran it in Postman it worked, but when I hit request in flutter the application suddenly stopped and froze.
This is the code:
@override
Future<ResponseAPI> getPrivacyPolicy() async {
try {
Dio http = await dio();
Response response = await http.get("/setting/type", queryParameters: {
"type": 7,
});
final data = response.data;
return ResponseAPI.fromJson(data);
} on DioException catch (e) {
if (e.response?.statusCode == 403) {
return ResponseAPI(
message: e.response?.data['message'],
statusCode: 403,
);
} else {
return const ResponseAPI(
message: "There's something wrong, please try again later",
statusCode: 500,
);
}
} catch (e) {
return const ResponseAPI(
message: "There's something wrong, please try again later",
statusCode: 500,
);
}
}
and here’s the response in Postman:
2
Answers
Try defining responseType for the Dio request Options
Also, check for any exception thrown on the runtime environment or by using try and catch
First you need to make a model
Then you have to make a model as follows