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:fl_chart/fl_chart.dart'; import 'package:flutter/material.dart'; class MonthCurvedChartBloodPressure extends StatelessWidget { final String title; final List timeSeries1; final List timeSeries2; final int indexes; final double horizontalInterval; MonthCurvedChartBloodPressure( {this.title, this.timeSeries1, this.indexes, this.timeSeries2, this.horizontalInterval = 20.0}); List xAxixs = List(); List yAxixs = List(); @override Widget build(BuildContext context) { getXaxix(); return AspectRatio( aspectRatio: 1.0, child: Container( decoration: const BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(18)), // color: Colors.white, ), child: Stack( children: [ Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const SizedBox( height: 15, ), Text( title, style: TextStyle( color: Colors.black, fontSize: 15, letterSpacing: 2), textAlign: TextAlign.center, ), SizedBox( height: 10, ), Expanded( child: Padding( padding: const EdgeInsets.only(right: 18.0, left: 16.0, top: 15), child: LineChart( sampleData1(context), swapAnimationDuration: const Duration(milliseconds: 250), ), ), ), SizedBox( height: 10, ), Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Row( children: [ Container( width: 20, height: 20, decoration: BoxDecoration( shape: BoxShape.rectangle, color: Theme.of(context).primaryColor), ), SizedBox( width: 5, ), Texts(TranslationBase.of(context).systolicLng) ], ), SizedBox( width: 15, ), Row( children: [ Container( width: 20, height: 20, decoration: BoxDecoration( shape: BoxShape.rectangle, color: Colors.grey), ), SizedBox( width: 5, ), Texts(TranslationBase.of(context).diastolicLng) ], ), ], ) ], ), ], ), ), ); } getXaxix() { for (int index = 0; index < timeSeries1.length; index++) { int mIndex = indexes * index; if (mIndex < timeSeries1.length) { xAxixs.add(mIndex); } } } LineChartData sampleData1(context) { return LineChartData( lineTouchData: LineTouchData( touchTooltipData: LineTouchTooltipData( tooltipBgColor: Colors.white, ), touchCallback: (LineTouchResponse touchResponse) {}, handleBuiltInTouches: true, ), gridData: FlGridData( show: true, drawVerticalLine: true, drawHorizontalLine: true), titlesData: FlTitlesData( bottomTitles: SideTitles( showTitles: true, getTextStyles: (value) => const TextStyle( color: Colors.black, fontSize: 10, ), margin: 22, getTitles: (value) { return ''; }, ), leftTitles: SideTitles( showTitles: true, interval:getMaxY() - getMinY() <=500?50:getMaxY() - getMinY() <=1000?100:200, getTextStyles: (value) => const TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: 10, ), // getTitles: (value) { // // if (value.toInt() == 0) // // return '${value.toInt()}'; // // else if (value.toInt() % horizontalInterval == 0) // // return '${value.toInt()}'; // // else // return '${value.toInt()}'; // }, margin: 12, ), ), borderData: FlBorderData( show: true, border: const Border( bottom: BorderSide( color: Colors.black, width: 0.5, ), left: BorderSide( color: Colors.black, ), right: BorderSide( color: Colors.black, ), top: BorderSide( color: Colors.transparent, ), ), ), minX: 0, maxX: (timeSeries1.length - 1).toDouble(), maxY: getMaxY() + 0.3, minY: getMinY(), lineBarsData: getData(context), ); } double getMaxY() { double max = 0; timeSeries1.forEach((element) { double resultValueDouble = element.sales; if (resultValueDouble > max) max = resultValueDouble; }); timeSeries2.forEach((element) { double resultValueDouble = element.sales; if (resultValueDouble > max) max = resultValueDouble; }); return max.roundToDouble(); } double getMinY() { double min = timeSeries1[0].sales; timeSeries1.forEach((element) { double resultValueDouble = element.sales; if (resultValueDouble < min) min = resultValueDouble; }); timeSeries2.forEach((element) { double resultValueDouble = element.sales; if (resultValueDouble < min) min = resultValueDouble; }); int value = min.toInt(); return value.toDouble(); } List getData(context) { List spots = List(); for (int index = 0; index < timeSeries1.length; index++) { spots.add(FlSpot(index.toDouble(), timeSeries1[index].sales)); } List spots2 = List(); for (int index = 0; index < timeSeries2.length; index++) { spots2.add(FlSpot(index.toDouble(), timeSeries2[index].sales)); } final LineChartBarData lineChartBarData1 = LineChartBarData( spots: spots, isCurved: true, colors: [Colors.red], barWidth: 5, isStrokeCapRound: true, dotData: FlDotData( show: false, ), belowBarData: BarAreaData( show: false, ), ); final LineChartBarData lineChartBarData2 = LineChartBarData( spots: spots2, isCurved: true, colors: [Theme.of(context).primaryColor], barWidth: 5, isStrokeCapRound: true, dotData: FlDotData( show: false, ), belowBarData: BarAreaData( show: false, ), ); return [lineChartBarData1, lineChartBarData2]; } }