mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2025-01-03 18:52:02 +00:00
Merge pull request #6 from LEG-Industries/steps-functionality
Steps functionality
This commit is contained in:
commit
bd2e26313f
28
lib/service/steps_service.dart
Normal file
28
lib/service/steps_service.dart
Normal file
|
@ -0,0 +1,28 @@
|
|||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints;
|
||||
|
||||
class StepsService {
|
||||
Future<int> getStepsToday(deviceId) async {
|
||||
final response = await http.get(
|
||||
Uri.parse(Endpoints.getStepsToday),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'deviceid': deviceId,
|
||||
},
|
||||
);
|
||||
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'];
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
const String home = "https://leg-barkr.nw.r.appspot.com/";
|
||||
const String register = "https://leg-barkr.nw.r.appspot.com/authentication/register";
|
||||
const String verify = "https://leg-barkr.nw.r.appspot.com/authentication/verify";
|
||||
const String getLastLocation = "https://leg-barkr.nw.r.appspot.com/readings/last/location";
|
||||
|
||||
const String getLastLocation = "https://leg-barkr.nw.r.appspot.com/readings/location/last";
|
||||
const String getStepsToday = "https://leg-barkr.nw.r.appspot.com/readings/steps/today";
|
||||
const String getStepsLastFiveDays = "https://leg-barkr.nw.r.appspot.com/readings/steps/last-five-days";
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:leg_barkr_app/model/steps_series.dart';
|
||||
import 'package:leg_barkr_app/service/steps_service.dart';
|
||||
import 'package:leg_barkr_app/view/steps/steps_chart.dart';
|
||||
import 'package:leg_barkr_app/view/steps/steps_today.dart';
|
||||
|
||||
|
@ -11,28 +12,42 @@ class StepsPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
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{
|
||||
List<dynamic> res = await StepsService().getStepsLastFiveDays("132-567-001");
|
||||
List<int> steps = [];
|
||||
for (int i = 0; i < res.length; i++){
|
||||
steps.add(res[i]);
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(0.0, 50.0, 10.0, 0.0),
|
||||
child: Column(
|
||||
child: FutureBuilder(
|
||||
future: onStepsRetrieved(),
|
||||
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(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
StepsToday(5123),
|
||||
new Expanded(child: StepsChart(data))
|
||||
StepsToday(stepsToday),
|
||||
new Expanded(child: StepsChart(stepsSeries))
|
||||
],
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue