Added daily steps reading from server

This commit is contained in:
Benjamin Ramhorst 2022-02-14 20:19:04 +00:00
parent 540e124ec4
commit 260767d8c1
3 changed files with 37 additions and 6 deletions

View file

@ -0,0 +1,17 @@
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,
},
);
print(jsonDecode(response.body)['cumulative_steps_today']);
return jsonDecode(response.body)['cumulative_steps_today'];
}
}

View file

@ -2,4 +2,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 getStepsToday = "https://leg-barkr.nw.r.appspot.com/readings/last/steps";

View file

@ -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';
@ -23,16 +24,27 @@ class _StepsPageState extends State<StepsPage> {
];
Future<int> onStepsRetrieved() async{
return await StepsService().getStepsToday("132-567-001");
}
@override
Widget build(BuildContext context) {
onStepsRetrieved();
return Padding(
padding: EdgeInsets.fromLTRB(0.0, 50.0, 10.0, 0.0),
child: Column(
child: FutureBuilder(
future: onStepsRetrieved(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
StepsToday(5123),
StepsToday(snapshot.data),
new Expanded(child: StepsChart(data))
],
);
},
)
);
}