import 'package:diplomaticquarterapp/core/model/my_trakers/blood_pressur/BloodPressureResult.dart'; import 'package:diplomaticquarterapp/core/model/my_trakers/blood_sugar/DiabtecPatientResult.dart'; import 'package:diplomaticquarterapp/core/model/my_trakers/chartData/WeekChartDate.dart'; import 'package:diplomaticquarterapp/core/model/my_trakers/weight/WeightMeasurementResult.dart'; import 'package:diplomaticquarterapp/core/viewModels/medical/weight_pressure_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/medical/my_trackers/widget/LineChartCurved.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/charts/app_time_series_chart.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:charts_flutter/flutter.dart' as charts; import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; import "package:collection/collection.dart"; import 'package:provider/provider.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; class WeightYearPage extends StatelessWidget { final WeightPressureViewModel model; WeightYearPage({ Key key, this.model, }) : super(key: key); List monthlyGroup = []; @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); groupData(); return AppScaffold( isShowDecPage: false, body: ListView( children: [ Container( width: double.maxFinite, color: Colors.white, child: LineChartCurved( horizontalInterval: 2.0, title: TranslationBase.of(context).weight, timeSeries: model.weightYearTimeSeriesData.isEmpty ? [TimeSeriesSales2(DateTime.now(), 0.0)] : model.weightYearTimeSeriesData, indexes: model.weightYearTimeSeriesData.length ~/ 5.5 ?? "", )), SizedBox( height: 12, ), Padding( padding: const EdgeInsets.all(8.0), child: Texts(TranslationBase.of(context).details), ), Container( padding: EdgeInsets.all(10), color: Colors.transparent, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ model.weightYearTimeSeriesData.isEmpty ? Container( child: Center( child: Texts(TranslationBase.of(context).noDataAvailable), ), ) : Column(children: [ for (var monthly in monthlyGroup) Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: double.maxFinite, padding: EdgeInsets.only(top: 10, bottom: 10, left: 5, right: 5), decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Texts(monthly[0])), Table( columnWidths: { 0: FlexColumnWidth(2.5), }, children: fullData(context, projectViewModel, monthly[1]), ) ]) ]), ], ), ) ], ), ); } List fullData(BuildContext context, ProjectViewModel projectViewModel, model) { List tableRow = []; tableRow.add( TableRow( children: [ Utils.tableColumnTitle(TranslationBase.of(context).date), Utils.tableColumnTitle(TranslationBase.of(context).time), Utils.tableColumnTitle(TranslationBase.of(context).value), ], ), ); model.forEach( (diabtec) { tableRow.add( TableRow( children: [ Utils.tableColumnValue('${projectViewModel.isArabic ? DateUtil.getMonthDayYearDateFormattedAr(diabtec.weightDate) : DateUtil.getMonthDayYearDateFormatted(diabtec.weightDate)} ', isCapitable: false), Utils.tableColumnValue('${diabtec.weightDate.hour}:${diabtec.weightDate.minute}', isCapitable: false), Utils.tableColumnValue('${diabtec.weightMeasured}', isCapitable: false), ], ), ); }, ); return tableRow; } groupData() { monthlyGroup.clear(); var groupedArray = groupBy(model.yearWeightMeasurementResult.reversed, (obj) => DateUtil.getMonth(obj.weightDate.month) + ' ' + obj.weightDate.year.toString()); groupedArray.entries.forEach((e) => monthlyGroup.add([e.key, e.value])); } }