Steps page implemented

This commit is contained in:
Benjamin Ramhorst 2022-02-14 23:28:27 +00:00
parent 31b7ed3234
commit 5ee93dc6be
2 changed files with 33 additions and 19 deletions

View file

@ -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'];
}
} }

View file

@ -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) {
return Column( 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(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
StepsToday(snapshot.data), StepsToday(stepsToday),
new Expanded(child: StepsChart(data)) new Expanded(child: StepsChart(stepsSeries))
], ],
); );
}, },