mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-12-23 05:55:49 +00:00
Steps page implemented
This commit is contained in:
parent
31b7ed3234
commit
5ee93dc6be
|
@ -11,7 +11,18 @@ class StepsService {
|
||||||
'deviceid': deviceId,
|
'deviceid': deviceId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
print(jsonDecode(response.body)['cumulative_steps_today']);
|
|
||||||
return jsonDecode(response.body)['cumulative_steps_today'];
|
return jsonDecode(response.body)['cumulative_steps_today'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<dynamic>> getStepsLastFiveDays(deviceId) async {
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse(Endpoints.getStepsLastFiveDays),
|
||||||
|
headers: <String, String>{
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
'deviceid': deviceId,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
print(jsonDecode(response.body)['daily_steps'].runtimeType);
|
||||||
|
return jsonDecode(response.body)['daily_steps'];
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -12,36 +12,39 @@ class StepsPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _StepsPageState extends State<StepsPage> {
|
class _StepsPageState extends State<StepsPage> {
|
||||||
// Dummy metrics
|
|
||||||
final List<StepsSeries> data = [
|
|
||||||
StepsSeries(DateTime.utc(2022, 2, 9), 9867),
|
|
||||||
StepsSeries(DateTime.utc(2022, 2, 8), 8123),
|
|
||||||
StepsSeries(DateTime.utc(2022, 2, 7), 10234),
|
|
||||||
StepsSeries(DateTime.utc(2022, 2, 6), 6521),
|
|
||||||
StepsSeries(DateTime.utc(2022, 2, 5), 1021),
|
|
||||||
StepsSeries(DateTime.utc(2022, 2, 4), 10567),
|
|
||||||
StepsSeries(DateTime.utc(2022, 2, 3), 7500)
|
|
||||||
];
|
|
||||||
|
|
||||||
|
Future<List<int>> onStepsRetrieved() async{
|
||||||
Future<int> onStepsRetrieved() async{
|
List<dynamic> res = await StepsService().getStepsLastFiveDays("132-567-001");
|
||||||
return await StepsService().getStepsToday("132-567-001");
|
List<int> steps = [];
|
||||||
|
for (int i = 0; i < res.length; i++){
|
||||||
|
steps.add(res[i]);
|
||||||
|
}
|
||||||
|
return steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
onStepsRetrieved();
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.fromLTRB(0.0, 50.0, 10.0, 0.0),
|
padding: EdgeInsets.fromLTRB(0.0, 50.0, 10.0, 0.0),
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: onStepsRetrieved(),
|
future: onStepsRetrieved(),
|
||||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||||
|
int stepsToday = 0;
|
||||||
|
List<StepsSeries> stepsSeries = [];
|
||||||
|
if(snapshot.hasData) {
|
||||||
|
List<int> stepsLastFiveDays = snapshot.data;
|
||||||
|
stepsToday = stepsLastFiveDays[0];
|
||||||
|
for(int i = 0; i < stepsLastFiveDays.length; i++){
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
stepsSeries.add(StepsSeries(DateTime(now.year, now.month, now.day-i), stepsLastFiveDays[i]));
|
||||||
|
}
|
||||||
|
stepsSeries = List.from(stepsSeries.reversed);
|
||||||
|
}
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
StepsToday(snapshot.data),
|
StepsToday(stepsToday),
|
||||||
new Expanded(child: StepsChart(data))
|
new Expanded(child: StepsChart(stepsSeries))
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue