fix chart and duplicated data in Patient Lab Result
							parent
							
								
									4a43bcefe1
								
							
						
					
					
						commit
						4e823c2be4
					
				@ -0,0 +1,194 @@
 | 
			
		||||
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
 | 
			
		||||
import 'package:fl_chart/fl_chart.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
import '../../../../core/model/labs/LabOrderResult.dart';
 | 
			
		||||
 | 
			
		||||
class LineChartCurved extends StatefulWidget {
 | 
			
		||||
  final String title;
 | 
			
		||||
  final List<LabOrderResult> labResult;
 | 
			
		||||
 | 
			
		||||
  LineChartCurved({this.title, this.labResult});
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  State<StatefulWidget> createState() => LineChartCurvedState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class LineChartCurvedState extends State<LineChartCurved> {
 | 
			
		||||
  bool isShowingMainData;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
    isShowingMainData = true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return AspectRatio(
 | 
			
		||||
      aspectRatio: 1.23,
 | 
			
		||||
      child: Container(
 | 
			
		||||
        decoration: const BoxDecoration(
 | 
			
		||||
          borderRadius: BorderRadius.all(Radius.circular(18)),
 | 
			
		||||
          // color: Colors.white,
 | 
			
		||||
        ),
 | 
			
		||||
        child: Stack(
 | 
			
		||||
          children: <Widget>[
 | 
			
		||||
            Column(
 | 
			
		||||
              crossAxisAlignment: CrossAxisAlignment.stretch,
 | 
			
		||||
              children: <Widget>[
 | 
			
		||||
                const SizedBox(
 | 
			
		||||
                  height: 4,
 | 
			
		||||
                ),
 | 
			
		||||
                 Text(
 | 
			
		||||
                  widget.title,
 | 
			
		||||
                  style: TextStyle(
 | 
			
		||||
                      color: Colors.black,
 | 
			
		||||
                      fontSize: 32,
 | 
			
		||||
                      fontWeight: FontWeight.bold,
 | 
			
		||||
                      letterSpacing: 2),
 | 
			
		||||
                  textAlign: TextAlign.center,
 | 
			
		||||
                ),
 | 
			
		||||
 | 
			
		||||
                Expanded(
 | 
			
		||||
                  child: Padding(
 | 
			
		||||
                    padding: const EdgeInsets.only(right: 16.0, left: 6.0),
 | 
			
		||||
                    child: LineChart(
 | 
			
		||||
                      sampleData1(),
 | 
			
		||||
                      swapAnimationDuration: const Duration(milliseconds: 250),
 | 
			
		||||
                    ),
 | 
			
		||||
                  ),
 | 
			
		||||
                ),
 | 
			
		||||
                const SizedBox(
 | 
			
		||||
                  height: 10,
 | 
			
		||||
                ),
 | 
			
		||||
              ],
 | 
			
		||||
            ),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  LineChartData sampleData1() {
 | 
			
		||||
    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: 12,
 | 
			
		||||
          ),
 | 
			
		||||
          margin: 10,
 | 
			
		||||
          getTitles: (value) {
 | 
			
		||||
            print(value);
 | 
			
		||||
            if(widget.labResult.length>value.toInt())
 | 
			
		||||
          {  DateTime date = DateUtil.convertStringToDate(widget.labResult[value.toInt()].verifiedOnDateTime);
 | 
			
		||||
            return '${date.day}/ ${date.year}';}
 | 
			
		||||
            return '';
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          ,
 | 
			
		||||
        ),
 | 
			
		||||
        leftTitles: SideTitles(
 | 
			
		||||
          showTitles: true,
 | 
			
		||||
          getTextStyles: (value) => const TextStyle(
 | 
			
		||||
            color: Colors.black,
 | 
			
		||||
            fontWeight: FontWeight.bold,
 | 
			
		||||
            fontSize: 14,
 | 
			
		||||
          ),
 | 
			
		||||
          getTitles: (value) {
 | 
			
		||||
            return '${value.toInt()}';
 | 
			
		||||
          },
 | 
			
		||||
          margin: 8,
 | 
			
		||||
          //reservedSize: 30,
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
      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: (widget.labResult.length-1).toDouble(),
 | 
			
		||||
      maxY: getMaxY(),
 | 
			
		||||
      minY: getMinY(),
 | 
			
		||||
      lineBarsData: getData(),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  double getMaxY(){
 | 
			
		||||
    double max =0;
 | 
			
		||||
    widget.labResult.forEach((element) {
 | 
			
		||||
      double resultValueDouble =double.parse(element.resultValue);
 | 
			
		||||
      if(resultValueDouble>max)
 | 
			
		||||
        max = resultValueDouble;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return max.roundToDouble();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  double getMinY(){
 | 
			
		||||
    double min =double.parse(widget.labResult[0].resultValue);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    widget.labResult.forEach((element) {
 | 
			
		||||
      double resultValueDouble =double.parse(element.resultValue);
 | 
			
		||||
      if(resultValueDouble<min)
 | 
			
		||||
        min = resultValueDouble;
 | 
			
		||||
    });
 | 
			
		||||
     int value = min.toInt();
 | 
			
		||||
 | 
			
		||||
    return value.toDouble();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  List<LineChartBarData> getData() {
 | 
			
		||||
    List<FlSpot> spots = List();
 | 
			
		||||
    for (int index = 0; index < widget.labResult.length ; index++) {
 | 
			
		||||
      var resultValueDouble = double.parse(widget.labResult[index].resultValue);
 | 
			
		||||
      spots.add(FlSpot(index.toDouble(), resultValueDouble));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    final LineChartBarData lineChartBarData1 = LineChartBarData(
 | 
			
		||||
      spots: spots,
 | 
			
		||||
      isCurved: true,
 | 
			
		||||
      colors: [Theme.of(context).primaryColor],
 | 
			
		||||
      barWidth: 5,
 | 
			
		||||
      isStrokeCapRound: true,
 | 
			
		||||
      dotData: FlDotData(
 | 
			
		||||
        show: false,
 | 
			
		||||
      ),
 | 
			
		||||
      belowBarData: BarAreaData(
 | 
			
		||||
        show: false,
 | 
			
		||||
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    return [
 | 
			
		||||
      lineChartBarData1,
 | 
			
		||||
    ];
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue