mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-12-22 21:45:48 +00:00
Added daily steps reading from server
This commit is contained in:
parent
540e124ec4
commit
260767d8c1
17
lib/service/steps_service.dart
Normal file
17
lib/service/steps_service.dart
Normal 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'];
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
|
||||
|
||||
|
|
|
@ -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))
|
||||
],
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue