Get request using dio package.
void fetchData() async {
try {
var response = await dio.get(
"http://localhost:8888/api/screen",
);
if (response.statusCode == 200) {
setState(() {
lineData = response.data;
});
}
} on DioError catch (err) {
print(err);
}
}
Getting response after printing lineData. This flutter keyword is added to my data.
flutter: [{_id: id1, day: 1, data: 7.3, percent: 1.3}, {_id: id2, day: 2, data: 1.2,
percent: 0.5}]
Server response in post man. Without flutter at the start.
[
{
"_id": "<id1>",
"day": 1,
"data": 7.3,
"percent": 1.3
},
{
"_id": "<id2>",
"day": 2,
"data": 1.2,
"percent": 0.5
}
]
CodePudding user response:
change this code
void fetchData() async {
try {
var response = await dio.get(
"http://localhost:8888/api/screen",
);
if (response.statusCode == 200) {
setState(() {
lineData = jsonDecode(response.data);
});
}
} on DioError catch (err) {
print(err);
}
}
CodePudding user response:
Probably, you are printing your response on your debug console. If you are trying to print this response, IDE will always add a flutter append to your response.
You can try to show this response on your screen (for example, with Text()
)