You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
567 lines
19 KiB
Dart
567 lines
19 KiB
Dart
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
import 'package:diplomaticquarterapp/models/SmartWatch/WeeklyStepsResModel.dart';
|
|
import 'package:diplomaticquarterapp/models/SmartWatch/YearlyStepsResModel.dart';
|
|
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
|
|
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:diplomaticquarterapp/uitl/utils.dart';
|
|
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
|
|
import 'package:diplomaticquarterapp/widgets/charts/app_time_series_chart.dart';
|
|
import 'package:diplomaticquarterapp/widgets/charts/show_chart.dart';
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class StepsTracker extends StatefulWidget {
|
|
@override
|
|
_StepsTrackerState createState() => _StepsTrackerState();
|
|
}
|
|
|
|
class _StepsTrackerState extends State<StepsTracker> with SingleTickerProviderStateMixin {
|
|
TabController _tabController;
|
|
|
|
ProjectViewModel projectViewModel;
|
|
|
|
int weeklyStatsAvgValue = 0;
|
|
int monthlyStatsAvgValue = 0;
|
|
int yearlyStatsAvgValue = 0;
|
|
|
|
int avgWeeklyStepsValue = 0;
|
|
int avgMonthlyStepsValue = 0;
|
|
int avgYearlyStepsValue = 0;
|
|
|
|
int weeklyDataLength = 0;
|
|
int monthlyDataLength = 0;
|
|
int yearlyDataLength = 0;
|
|
|
|
List<WeeklyStepsResModel> weekyStepsList = List();
|
|
List<WeeklyStepsResModel> monthlyStepsList = List();
|
|
List<YearlyStepsResModel> yearlyStepsList = List();
|
|
|
|
List<TimeSeriesSales2> weeklyTimeSeriesData = [];
|
|
List<TimeSeriesSales2> monthlyTimeSeriesData = [];
|
|
List<TimeSeriesSales2> yearlyTimeSeriesData = [];
|
|
|
|
bool isWeeklyDataLoaded = false;
|
|
bool isMonthlyDataLoaded = false;
|
|
bool isYearlyDataLoaded = false;
|
|
|
|
@override
|
|
void initState() {
|
|
_tabController = new TabController(length: 3, vsync: this);
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
getWeeklyStepsData();
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
projectViewModel = Provider.of(context);
|
|
return AppScaffold(
|
|
isShowAppBar: true,
|
|
appBarTitle: TranslationBase.of(context).steps,
|
|
showNewAppBar: true,
|
|
showNewAppBarTitle: true,
|
|
isShowDecPage: false,
|
|
body: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TabBar(
|
|
controller: _tabController,
|
|
indicatorWeight: 3.0,
|
|
indicatorSize: TabBarIndicatorSize.tab,
|
|
labelColor: Color(0xff2B353E),
|
|
unselectedLabelColor: Color(0xff575757),
|
|
labelPadding: EdgeInsets.only(top: 0, bottom: 0, left: 20, right: 20),
|
|
labelStyle: TextStyle(
|
|
fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins',
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.48,
|
|
),
|
|
unselectedLabelStyle: TextStyle(
|
|
fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins',
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.48,
|
|
),
|
|
tabs: [
|
|
Tab(text: TranslationBase.of(context).weekly),
|
|
Tab(text: TranslationBase.of(context).monthlyTab),
|
|
Tab(text: TranslationBase.of(context).yearly),
|
|
],
|
|
onTap: (value) {
|
|
if (value == 0) {
|
|
getWeeklyStepsData();
|
|
} else if (value == 1) {
|
|
getMonthlyStepsData();
|
|
} else {
|
|
getYearlyStepsData();
|
|
}
|
|
},
|
|
),
|
|
Expanded(
|
|
child: new TabBarView(
|
|
physics: NeverScrollableScrollPhysics(),
|
|
children: [
|
|
isWeeklyDataLoaded ? getWeeklyStepsDetails() : Container(),
|
|
isMonthlyDataLoaded ? getMonthlyStepsDetails() : Container(),
|
|
isYearlyDataLoaded ? getYearlyStepsDetails() : Container()
|
|
],
|
|
controller: _tabController,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
getWeeklyStepsData() {
|
|
avgWeeklyStepsValue = 0;
|
|
weeklyDataLength = 0;
|
|
DoctorsListService service = new DoctorsListService();
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
service.getPatientHealthDataStats(6, 1, context).then((res) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
weekyStepsList.clear();
|
|
res['Med_GetWeekStepsTransactionsStsList'].forEach((element) {
|
|
weekyStepsList.add(new WeeklyStepsResModel.fromJson(element));
|
|
if (element['Value'] != null) {
|
|
num value = num.tryParse(element['Value'] ?? "0");
|
|
avgWeeklyStepsValue += value.toInt();
|
|
weeklyDataLength++;
|
|
}
|
|
});
|
|
generateWeekData();
|
|
setState(() {
|
|
weeklyStatsAvgValue = avgWeeklyStepsValue ~/ weeklyDataLength;
|
|
isWeeklyDataLoaded = true;
|
|
});
|
|
}).catchError((err) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
print(err);
|
|
});
|
|
}
|
|
|
|
getMonthlyStepsData() {
|
|
avgMonthlyStepsValue = 0;
|
|
monthlyDataLength = 0;
|
|
DoctorsListService service = new DoctorsListService();
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
service.getPatientHealthDataStats(6, 2, context).then((res) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
monthlyStepsList.clear();
|
|
res['Med_GetMonthStepsTransactionsStsList'].forEach((element) {
|
|
monthlyStepsList.add(new WeeklyStepsResModel.fromJson(element));
|
|
if (element['Value'] != null) {
|
|
num value = num.tryParse(element['Value'] ?? "0");
|
|
avgMonthlyStepsValue += value.toInt();
|
|
monthlyDataLength++;
|
|
}
|
|
});
|
|
generateMonthData();
|
|
setState(() {
|
|
monthlyStatsAvgValue = avgMonthlyStepsValue ~/ monthlyDataLength;
|
|
isMonthlyDataLoaded = true;
|
|
});
|
|
}).catchError((err) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
print(err);
|
|
});
|
|
}
|
|
|
|
getYearlyStepsData() {
|
|
avgYearlyStepsValue = 0;
|
|
yearlyDataLength = 0;
|
|
DoctorsListService service = new DoctorsListService();
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
service.getPatientHealthDataStats(6, 3, context).then((res) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
yearlyStepsList.clear();
|
|
res['Med_GetYearStepsTransactionsStsList'].forEach((element) {
|
|
yearlyStepsList.add(new YearlyStepsResModel.fromJson(element));
|
|
if (element['ValueSum'] != null) {
|
|
num value = element['ValueSum'];
|
|
avgYearlyStepsValue += value.toInt();
|
|
yearlyDataLength++;
|
|
}
|
|
});
|
|
generateYearData();
|
|
setState(() {
|
|
yearlyStatsAvgValue = avgYearlyStepsValue ~/ yearlyDataLength;
|
|
isYearlyDataLoaded = true;
|
|
});
|
|
}).catchError((err) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
print(err);
|
|
});
|
|
}
|
|
|
|
generateWeekData() {
|
|
if (weekyStepsList.length > 0) {
|
|
weeklyTimeSeriesData.clear();
|
|
weekyStepsList.forEach(
|
|
(element) {
|
|
weeklyTimeSeriesData.add(
|
|
TimeSeriesSales2(
|
|
DateUtil.convertStringToDate(element.machineDate),
|
|
element.value != null ? element.value.toDouble() : 0.0,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
generateMonthData() {
|
|
if (monthlyStepsList.length > 0) {
|
|
monthlyTimeSeriesData.clear();
|
|
monthlyStepsList.forEach(
|
|
(element) {
|
|
monthlyTimeSeriesData.add(
|
|
TimeSeriesSales2(
|
|
DateUtil.convertStringToDate(element.machineDate),
|
|
element.value != null ? element.value.toDouble() : 0.0,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
generateYearData() {
|
|
if (yearlyStepsList.length > 0) {
|
|
yearlyTimeSeriesData.clear();
|
|
yearlyStepsList.forEach(
|
|
(element) {
|
|
yearlyTimeSeriesData.add(
|
|
TimeSeriesSales2(
|
|
new DateTime(element.year, element.month, 1),
|
|
element.valueSum != null ? double.tryParse(element.valueSum.toString()) : 0.0,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
getWeeklyStepsDetails() {
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
child: ShowChart(
|
|
title: "",
|
|
timeSeries: weeklyTimeSeriesData,
|
|
indexes: weeklyTimeSeriesData.length ~/ 5.5,
|
|
horizontalInterval: 8,
|
|
isWeeklyOrMonthly: true,
|
|
),
|
|
),
|
|
Container(
|
|
child: Container(
|
|
decoration: cardRadius(12),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.fromLTRB(30.0, 15.0, 30.0, 5.0),
|
|
child: Text(TranslationBase.of(context).avgSteps, style: TextStyle(fontSize: 18.0)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(bottom: 10.0),
|
|
child: Text(weeklyStatsAvgValue.toString() + " " + TranslationBase.of(context).steps, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
decoration: cardRadius(12),
|
|
margin: EdgeInsets.only(left: 16, top: 16, right: 16, bottom: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(TranslationBase.of(context).details,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.48,
|
|
)),
|
|
),
|
|
Container(
|
|
padding: EdgeInsets.all(10),
|
|
color: Colors.transparent,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
weekyStepsList.isEmpty
|
|
? Container(
|
|
child: Center(
|
|
child: Text(TranslationBase.of(context).noDataAvailable),
|
|
),
|
|
)
|
|
: Table(
|
|
columnWidths: {
|
|
0: FlexColumnWidth(2.5),
|
|
},
|
|
children: fullDataWeekly(context),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
getMonthlyStepsDetails() {
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
child: ShowChart(
|
|
title: "",
|
|
timeSeries: monthlyTimeSeriesData,
|
|
indexes: monthlyTimeSeriesData.length ~/ 5.5,
|
|
horizontalInterval: 8,
|
|
isWeeklyOrMonthly: true,
|
|
),
|
|
),
|
|
Container(
|
|
child: Container(
|
|
decoration: cardRadius(12),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.fromLTRB(30.0, 15.0, 30.0, 5.0),
|
|
child: Text(TranslationBase.of(context).avgSteps, style: TextStyle(fontSize: 18.0)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(bottom: 10.0),
|
|
child: Text(monthlyStatsAvgValue.toString() + " " + TranslationBase.of(context).steps, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
decoration: cardRadius(12),
|
|
margin: EdgeInsets.only(left: 16, top: 16, right: 16, bottom: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(TranslationBase.of(context).details,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.48,
|
|
)),
|
|
),
|
|
Container(
|
|
padding: EdgeInsets.all(10),
|
|
color: Colors.transparent,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
monthlyStepsList.isEmpty
|
|
? Container(
|
|
child: Center(
|
|
child: Text(TranslationBase.of(context).noDataAvailable),
|
|
),
|
|
)
|
|
: Table(
|
|
columnWidths: {
|
|
0: FlexColumnWidth(2.5),
|
|
},
|
|
children: fullDataMonthly(context),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
getYearlyStepsDetails() {
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
child: ShowChart(
|
|
title: "",
|
|
timeSeries: yearlyTimeSeriesData,
|
|
indexes: yearlyTimeSeriesData.length ~/ 5.5,
|
|
horizontalInterval: 8,
|
|
),
|
|
),
|
|
Container(
|
|
child: Container(
|
|
decoration: cardRadius(12),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.fromLTRB(30.0, 15.0, 30.0, 5.0),
|
|
child: Text(TranslationBase.of(context).avgSteps, style: TextStyle(fontSize: 18.0)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(bottom: 10.0),
|
|
child: Text(yearlyStatsAvgValue.toString() + " " + TranslationBase.of(context).steps, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
decoration: cardRadius(12),
|
|
margin: EdgeInsets.only(left: 16, top: 16, right: 16, bottom: 8),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(TranslationBase.of(context).details,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: -0.48,
|
|
)),
|
|
),
|
|
Container(
|
|
padding: EdgeInsets.all(10),
|
|
color: Colors.transparent,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
yearlyStepsList.isEmpty
|
|
? Container(
|
|
child: Center(
|
|
child: Text(TranslationBase.of(context).noDataAvailable),
|
|
),
|
|
)
|
|
: Table(
|
|
columnWidths: {
|
|
0: FlexColumnWidth(2.5),
|
|
},
|
|
children: fullData(context),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
List<TableRow> fullData(BuildContext context) {
|
|
List<TableRow> tableRow = [];
|
|
tableRow.add(
|
|
TableRow(
|
|
children: [
|
|
Utils.tableColumnTitle(TranslationBase.of(context).date),
|
|
Utils.tableColumnTitle(TranslationBase.of(context).steps),
|
|
],
|
|
),
|
|
);
|
|
yearlyStepsList.forEach(
|
|
(step) {
|
|
tableRow.add(
|
|
TableRow(
|
|
children: [
|
|
Utils.tableColumnValue(
|
|
'${DateUtil.getDayMonthYearDateFormatted(
|
|
new DateTime(step.year, step.month, 1),
|
|
)} ',
|
|
isCapitable: false,
|
|
mProjectViewModel: projectViewModel),
|
|
Utils.tableColumnValue(step.valueSum.toString(), isCapitable: false, mProjectViewModel: projectViewModel),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
return tableRow;
|
|
}
|
|
|
|
List<TableRow> fullDataWeekly(BuildContext context) {
|
|
List<TableRow> tableRow = [];
|
|
tableRow.add(
|
|
TableRow(
|
|
children: [
|
|
Utils.tableColumnTitle(TranslationBase.of(context).date),
|
|
Utils.tableColumnTitle(TranslationBase.of(context).steps),
|
|
],
|
|
),
|
|
);
|
|
weekyStepsList.forEach(
|
|
(step) {
|
|
tableRow.add(
|
|
TableRow(
|
|
children: [
|
|
Utils.tableColumnValue(
|
|
'${DateUtil.getDayMonthYearDateFormatted(
|
|
DateUtil.convertStringToDate(step.machineDate),
|
|
)} ',
|
|
isCapitable: false,
|
|
mProjectViewModel: projectViewModel),
|
|
Utils.tableColumnValue(step.value.toString(), isCapitable: false, mProjectViewModel: projectViewModel),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
return tableRow;
|
|
}
|
|
|
|
List<TableRow> fullDataMonthly(BuildContext context) {
|
|
List<TableRow> tableRow = [];
|
|
tableRow.add(
|
|
TableRow(
|
|
children: [
|
|
Utils.tableColumnTitle(TranslationBase.of(context).date),
|
|
Utils.tableColumnTitle(TranslationBase.of(context).steps),
|
|
],
|
|
),
|
|
);
|
|
monthlyStepsList.forEach(
|
|
(step) {
|
|
tableRow.add(
|
|
TableRow(
|
|
children: [
|
|
Utils.tableColumnValue(
|
|
'${DateUtil.getDayMonthYearDateFormatted(
|
|
DateUtil.convertStringToDate(step.machineDate),
|
|
)} ',
|
|
isCapitable: false,
|
|
mProjectViewModel: projectViewModel),
|
|
Utils.tableColumnValue(step.value.toString(), isCapitable: false, mProjectViewModel: projectViewModel),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
return tableRow;
|
|
}
|
|
}
|