Working on steps tracking

merge-update-with-lab-changes
haroon amjad 5 years ago
parent e495d3e5ad
commit b55681a056

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

@ -0,0 +1,36 @@
class YearlyStepsResModel {
double valueSum;
int medCategoryID;
int month;
String monthName;
int patientID;
int year;
YearlyStepsResModel(
{this.valueSum,
this.medCategoryID,
this.month,
this.monthName,
this.patientID,
this.year});
YearlyStepsResModel.fromJson(Map<String, dynamic> json) {
valueSum = json['ValueSum'];
medCategoryID = json['MedCategoryID'];
month = json['Month'];
monthName = json['MonthName'];
patientID = json['PatientID'];
year = json['Year'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['ValueSum'] = this.valueSum;
data['MedCategoryID'] = this.medCategoryID;
data['Month'] = this.month;
data['MonthName'] = this.monthName;
data['PatientID'] = this.patientID;
data['Year'] = this.year;
return data;
}
}

@ -1,7 +1,9 @@
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:diplomaticquarterapp/models/SmartWatch/YearlyStepsResModel.dart';
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/charts/app_time_series_chart.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
@ -14,6 +16,19 @@ class _StepsTrackerState extends State<StepsTracker>
with SingleTickerProviderStateMixin {
TabController _tabController;
int weeklyStatsAvgValue = 0;
int monthlyStatsAvgValue = 0;
int yearlyStatsAvgValue = 0;
int avgStepsValue = 0;
int dataLength = 0;
List<YearlyStepsResModel> yearlyStepsList = List();
List<TimeSeriesSales> yearlyTimeSeriesData = [];
bool isDataLoaded = false;
@override
void initState() {
_tabController = new TabController(length: 3, vsync: this);
@ -31,7 +46,7 @@ class _StepsTrackerState extends State<StepsTracker>
isShowDecPage: false,
body: Container(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisSize: MainAxisSize.min,
children: [
TabBar(
tabs: [
@ -45,9 +60,9 @@ class _StepsTrackerState extends State<StepsTracker>
child: new TabBarView(
physics: NeverScrollableScrollPhysics(),
children: [
getWeeklyStepsDetails(),
getMonthlyStepsDetails(),
getYearlyStepsDetails()
isDataLoaded ? getWeeklyStepsDetails() : Container(),
isDataLoaded ? getMonthlyStepsDetails() : Container(),
isDataLoaded ? getYearlyStepsDetails() : Container()
],
controller: _tabController,
),
@ -59,18 +74,66 @@ class _StepsTrackerState extends State<StepsTracker>
}
getYearlyStepsData() {
avgStepsValue = 0;
dataLength = 0;
DoctorsListService service = new DoctorsListService();
GifLoaderDialogUtils.showMyDialog(context);
service.getPatientHealthDataStats(6, 3, context).then((res) {
GifLoaderDialogUtils.hideDialog(context);
print(res['Med_GetYearStepsTransactionsStsList']);
yearlyStepsList.clear();
res['Med_GetYearStepsTransactionsStsList'].forEach((element) {
yearlyStepsList.add(new YearlyStepsResModel.fromJson(element));
if (element['ValueSum'] != null) {
double value = element['ValueSum'];
avgStepsValue += value.toInt();
dataLength++;
}
});
print(avgStepsValue);
print(dataLength);
setState(() {
yearlyStatsAvgValue = avgStepsValue ~/ dataLength;
isDataLoaded = true;
});
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
AppToast.showErrorToast(message: err);
// AppToast.showErrorToast(message: err);
print(err);
});
}
generateData() {
if (yearlyStepsList.length > 0) {
yearlyTimeSeriesData.clear();
yearlyStepsList.forEach(
(element) {
yearlyTimeSeriesData.add(
TimeSeriesSales(
new DateTime(element.year, element.month, 1),
element.valueSum != null ? element.valueSum.toInt() : 0,
),
);
},
);
yearlyTimeSeriesData.forEach((element) {
print(element.sales);
print(element.time);
});
}
return [
new charts.Series<TimeSeriesSales, DateTime>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.red.shadeDefault,
domainFn: (TimeSeriesSales sales, _) => sales.time,
measureFn: (TimeSeriesSales sales, _) => sales.sales,
data: yearlyTimeSeriesData,
)
];
}
getWeeklyStepsDetails() {
return Container(
child: Text("Weekly"),
@ -85,7 +148,101 @@ class _StepsTrackerState extends State<StepsTracker>
getYearlyStepsDetails() {
return Container(
child: Text("Yearly"),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: AppTimeSeriesChart(
seriesList: generateData(),
chartName: "Steps",
startDate: DateTime(
yearlyStepsList[0].year, yearlyStepsList[0].month, 1),
endDate: DateTime(
yearlyStepsList[yearlyStepsList.length - 1].year,
yearlyStepsList[yearlyStepsList.length - 1].month,
1),
),
),
Container(
margin: EdgeInsets.only(top: 5.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Colors.grey[400], width: 0.6)),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: EdgeInsets.fromLTRB(30.0, 15.0, 30.0, 15.0),
child:
Text("Average Steps", style: TextStyle(fontSize: 18.0)),
),
Container(
margin: EdgeInsets.only(bottom: 10.0),
child: Text(yearlyStatsAvgValue.toString() + " Steps",
style: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.bold)),
),
],
),
),
),
Container(
margin: EdgeInsets.all(10.0),
child: Divider(
color: Colors.grey[500],
),
),
Container(
transform: Matrix4.translationValues(0.0, -10.0, 0.0),
margin: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 5.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("History", style: TextStyle(fontSize: 14.0)),
Row(
children: [
Text("view more", style: TextStyle(fontSize: 14.0)),
Container(
margin: EdgeInsets.only(left: 3.0, right: 3.0),
transform: Matrix4.translationValues(0.0, 1.5, 0.0),
width: 30.0,
height: 30.0,
child: Image.asset(
"assets/images/new-design/view_more.png",
fit: BoxFit.contain),
),
],
),
],
),
),
Container(
margin: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 5.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(color: Colors.grey[400], width: 0.6)),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: EdgeInsets.fromLTRB(30.0, 15.0, 30.0, 15.0),
child: Text("Date",
style: TextStyle(
fontSize: 18.0, fontWeight: FontWeight.bold)),
),
Container(
padding: EdgeInsets.fromLTRB(30.0, 0.0, 30.0, 0.0),
child: Text("Steps", style: TextStyle(fontSize: 18.0)),
),
],
),
),
),
],
),
);
}
}

Loading…
Cancel
Save