Code refractoring & home (metrics) page implemented

This commit is contained in:
Benjamin Ramhorst 2022-02-15 01:04:13 +00:00
parent bd2e26313f
commit a3e997b06d
14 changed files with 121 additions and 60 deletions

View file

@ -1,6 +1,6 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:leg_barkr_app/home.dart';
import 'package:leg_barkr_app/view/home.dart';
import 'package:flutter/services.dart';
import 'package:leg_barkr_app/view/auth/login_form.dart';
import 'package:leg_barkr_app/view/auth/register_form.dart';

View file

@ -1,10 +1,9 @@
class LatitudeLongitude {
double latitude;
double longitude;
final double latitude;
final double longitude;
LatitudeLongitude(this.latitude, this.longitude);
factory LatitudeLongitude.fromJson(Map<String, dynamic> parsedJson){
return LatitudeLongitude(parsedJson['latitude'], parsedJson['longitude']);
}
LatitudeLongitude.fromJson(Map<String, dynamic> parsedJson):
latitude = parsedJson['latitude'], longitude = parsedJson['longitude'];
}

View file

@ -1,6 +1,6 @@
class MetricsData{
double currentReading, lowestReading, highestReading, minimumPossible, maximumPossible, lowCutOff, highCutOff;
String metric, units;
final double currentReading, lowestReading, highestReading, minimumPossible, maximumPossible, lowCutOff, highCutOff;
final String metric, units;
MetricsData(
this.currentReading,

View file

@ -0,0 +1,34 @@
class MetricsResponse {
final double lastAirTemp;
final double minAirTemp;
final double maxAirTemp;
final double lastSkinTemp;
final double minSkinTemp;
final double maxSkinTemp;
final double lastHumidity;
final double maxHumidity;
final double minHumidity;
MetricsResponse(
this.lastAirTemp,
this.minAirTemp,
this.maxAirTemp,
this.lastSkinTemp,
this.minSkinTemp,
this.maxSkinTemp,
this.lastHumidity,
this.maxHumidity,
this.minHumidity
);
MetricsResponse.fromJson(Map<String, dynamic> parsedJson) :
lastAirTemp = parsedJson['last_air_temp'].toDouble(),
minAirTemp = parsedJson['min_air_temp'].toDouble(),
maxAirTemp = parsedJson['max_air_temp'].toDouble(),
lastSkinTemp = parsedJson['last_skin_temp'].toDouble(),
minSkinTemp = parsedJson['min_skin_temp'].toDouble(),
maxSkinTemp = parsedJson['max_skin_temp'].toDouble(),
lastHumidity = parsedJson['last_humidity'].toDouble(),
maxHumidity = parsedJson['min_humidity'].toDouble(),
minHumidity = parsedJson['max_humidity'].toDouble();
}

View file

@ -26,7 +26,6 @@ class MapService{
}
}
return await Geolocator.getCurrentPosition();
}
}

View file

@ -0,0 +1,17 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:leg_barkr_app/model/metrics_response.dart';
import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints;
class MetricsService {
Future<MetricsResponse> getMetricsSummary(deviceId) async {
final response = await http.get(
Uri.parse(Endpoints.getMetricsSummary),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'deviceid': deviceId,
},
);
return MetricsResponse.fromJson(jsonDecode(response.body));
}
}

View file

@ -4,3 +4,4 @@ const String verify = "https://leg-barkr.nw.r.appspot.com/authentication/verify"
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";
const String getMetricsSummary = "https://leg-barkr.nw.r.appspot.com/readings/metrics-summary";

View file

@ -1,7 +1,7 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:leg_barkr_app/home.dart';
import 'package:leg_barkr_app/view/home.dart';
import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints;
import 'package:leg_barkr_app/view/auth/login_form.dart';

View file

@ -3,7 +3,7 @@ import 'package:firebase_auth/firebase_auth.dart';
import 'package:leg_barkr_app/view/metrics/metrics_page.dart';
import 'package:leg_barkr_app/view/steps/steps_page.dart';
import 'package:leg_barkr_app/view/map/map_page.dart';
import 'package:leg_barkr_app/view/settings_page.dart';
import 'package:leg_barkr_app/view/settings/settings_page.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);

View file

@ -1,26 +0,0 @@
import 'package:flutter/material.dart';
class MetricsMinMax extends StatelessWidget {
double lowest, highest;
String units;
MetricsMinMax(this.lowest, this.highest, this.units);
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.fromLTRB(0.0, 10.0, 5.0, 10.0),
child: Text("Minimum\n" + lowest.toString() + " " + units, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 16, fontWeight: FontWeight.bold))
),
Padding(
padding: EdgeInsets.fromLTRB(5.0, 10.0, 0.0, 10.0),
child: Text("Maximum\n" + highest.toString() + " " + units, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 16, fontWeight: FontWeight.bold))
)
],
);
}
}

View file

@ -26,25 +26,29 @@ class MetricsNow extends StatelessWidget {
endValue: data.lowCutOff,
color: Colors.blue,
startWidth: 10,
endWidth: 10),
endWidth: 10
),
GaugeRange(
startValue: data.lowCutOff,
endValue: data.highCutOff,
color: textColor,
startWidth: 10,
endWidth: 10),
endWidth: 10
),
GaugeRange(
startValue: data.highCutOff,
endValue: data.maximumPossible,
color: Colors.red,
startWidth: 10,
endWidth: 10)
endWidth: 10
)
],
pointers: [
MarkerPointer(
value: data.currentReading,
color: Colors.black,
markerWidth: 20)
markerWidth: 20
)
],
annotations: [
GaugeAnnotation(

View file

@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:leg_barkr_app/model/metrics_data.dart';
import 'package:leg_barkr_app/model/metrics_response.dart';
import 'package:leg_barkr_app/model/temp_series.dart';
import 'package:leg_barkr_app/service/metrics_service.dart';
import 'metrics_row.dart';
import 'package:leg_barkr_app/utils/constants.dart' as Constants;
@ -15,7 +17,8 @@ class MetricsPage extends StatefulWidget {
class _MetricsPageState extends State<MetricsPage> {
// Dummy data, will be removed
final List<TempSeries> data = [
/*
final List<TempSeries> data = [
TempSeries(DateTime.parse('2022-02-09 20:00:00Z'), 38.4),
TempSeries(DateTime.parse('2022-02-09 19:30:00Z'), 38.8),
TempSeries(DateTime.parse('2022-02-09 19:00:00Z'), 38.2),
@ -23,31 +26,47 @@ class _MetricsPageState extends State<MetricsPage> {
TempSeries(DateTime.parse('2022-02-09 18:00:00Z'), 39.5),
TempSeries(DateTime.parse('2022-02-09 17:30:00Z'), 37.8)
];
*/
Future<MetricsResponse> onMetricsReceived() async{
return await MetricsService().getMetricsSummary("132-567-001");
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(0.0, 50.0, 0.0, 0.0),
child: Expanded(
child: ListView(
padding: EdgeInsets.all(5.0),
children: <Widget>[
Text("Today's summary", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 36, fontWeight: FontWeight.bold)),
child: FutureBuilder(
future: onMetricsReceived(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
MetricsResponse metricsResponse;
if (snapshot.hasData){
metricsResponse = snapshot.data;
} else {
metricsResponse = MetricsResponse(0, 0, 0, 0, 0, 0, 0, 0, 0);
}
// Dummy data
MetricsRow(new MetricsData(38.6, 38.1, 39.2, Constants.MIN_SKIN_TEMP, Constants.MAX_SKIN_TEMP, Constants.LOW_SKIN_TEMP_DOG, Constants.HIGH_SKIN_TEMP_DOG, "Skin temperature", "°C"), Colors.white, Colors.green, true),
MetricsRow(new MetricsData(22, 16, 34, Constants.MIN_HUMIDITY, Constants.MAX_HUMIDITY, Constants.LOW_HUMIDITY_DOG, Constants.HIGH_HUMIDITY_DOG, "Humidity", "%"), Colors.green, Colors.black, false),
MetricsRow(new MetricsData(24, 21, 29, Constants.MIN_AIR_TEMP, Constants.MAX_AIR_TEMP, Constants.LOW_AIR_TEMP_DOG, Constants.HIGH_AIR_TEMP_DOG, "Air temperature", "°C"), Colors.white, Colors.green, true),
return ListView(
padding: EdgeInsets.all(5.0),
children: <Widget>[
Text("Today's summary", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 36, fontWeight: FontWeight.bold)),
Padding(
padding: EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 0.0),
child: Text("Today's temperature", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 36, fontWeight: FontWeight.bold)),
),
TempChart(data)
// Dummy data
MetricsRow(new MetricsData(metricsResponse.lastSkinTemp, metricsResponse.minSkinTemp, metricsResponse.maxSkinTemp, Constants.MIN_SKIN_TEMP, Constants.MAX_SKIN_TEMP, Constants.LOW_SKIN_TEMP_DOG, Constants.HIGH_SKIN_TEMP_DOG, "Skin temperature", "°C"), Colors.white, Colors.green, true),
MetricsRow(new MetricsData(metricsResponse.lastHumidity, metricsResponse.minHumidity, metricsResponse.maxHumidity, Constants.MIN_HUMIDITY, Constants.MAX_HUMIDITY, Constants.LOW_HUMIDITY_DOG, Constants.HIGH_HUMIDITY_DOG, "Humidity", "%"), Colors.green, Colors.black, false),
MetricsRow(new MetricsData(metricsResponse.lastAirTemp, metricsResponse.minAirTemp, metricsResponse.maxAirTemp, Constants.MIN_AIR_TEMP, Constants.MAX_AIR_TEMP, Constants.LOW_AIR_TEMP_DOG, Constants.HIGH_AIR_TEMP_DOG, "Air temperature", "°C"), Colors.white, Colors.green, true),
]
)
Padding(
padding: EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 0.0),
child: Text("Today's temperature", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 36, fontWeight: FontWeight.bold)),
),
//TempChart(data)
]
);
}
)
);
}

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:leg_barkr_app/model/metrics_data.dart';
import 'metrics_min_max.dart';
class MetricsSummary extends StatelessWidget {
MetricsData data;
@ -10,6 +9,21 @@ class MetricsSummary extends StatelessWidget {
@override
Widget build(BuildContext context) {
Row metricMinMax = Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.fromLTRB(0.0, 10.0, 5.0, 10.0),
child: Text("Minimum\n" + data.lowestReading.toString() + " " + data.units, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 16, fontWeight: FontWeight.bold))
),
Padding(
padding: EdgeInsets.fromLTRB(5.0, 10.0, 0.0, 10.0),
child: Text("Maximum\n" + data.highestReading.toString() + " " + data.units, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 16, fontWeight: FontWeight.bold))
)
],
);
return Expanded(
child: Padding(
padding: EdgeInsets.all(15.0),
@ -17,7 +31,7 @@ class MetricsSummary extends StatelessWidget {
child: Column(
children: [
Text(data.metric, textAlign: TextAlign.center, style: TextStyle(color: textColour, fontSize: 24, fontWeight: FontWeight.bold)),
MetricsMinMax(data.lowestReading, data.highestReading, data.units)
metricMinMax
],
)
)