114 lines
3.6 KiB
Dart
114 lines
3.6 KiB
Dart
|
// ignore_for_file: must_be_immutable
|
||
|
|
||
|
import 'package:fl_chart/fl_chart.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:get/get.dart';
|
||
|
import 'package:intl/intl.dart';
|
||
|
|
||
|
import 'component/chart.dart';
|
||
|
import 'process.dart';
|
||
|
import 'realController.dart';
|
||
|
|
||
|
|
||
|
|
||
|
// 深度
|
||
|
class RealChart extends StatelessWidget {
|
||
|
RealChart({super.key});
|
||
|
ChartData chartData = ChartData(
|
||
|
[],
|
||
|
);
|
||
|
final RealController realController = Get.put(RealController());
|
||
|
List<ProcessEntity> processList = [];
|
||
|
format(double value, [int fix = 2]) {
|
||
|
return double.parse(value.toStringAsFixed(fix));
|
||
|
}
|
||
|
|
||
|
List<ProcessEntity> cache = [];
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
// 显示长度
|
||
|
int showlength = 30;
|
||
|
ever(realController.depth, (newValue) {
|
||
|
ProcessEntity process = ProcessEntity(
|
||
|
recvTime: DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
||
|
pileId: realController.pileId.value,
|
||
|
utc: 0,
|
||
|
tid: 100,
|
||
|
toatalFlow1: format(realController.totalFlow1.value),
|
||
|
toatalFlow2: format(realController.totalFlow2.value),
|
||
|
subtotalFlow1: format(realController.subtotalFlow1.value),
|
||
|
subtotalFlow2: format(realController.subtotalFlow2.value),
|
||
|
depth: format(realController.depth.value),
|
||
|
);
|
||
|
|
||
|
processList.add(process);
|
||
|
|
||
|
if (realController.sliderTime != null) {
|
||
|
if (DateTime.now().difference(realController.sliderTime!).inSeconds >
|
||
|
10) {
|
||
|
realController.updateProcessList(processList);
|
||
|
realController.updateSlider(processList.length.toDouble(), false);
|
||
|
} else {
|
||
|
return;
|
||
|
}
|
||
|
} else {
|
||
|
realController.updateProcessList(processList);
|
||
|
if (realController.startIndex.value != processList.length) {
|
||
|
realController.updateSlider(processList.length.toDouble(), false);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
ever(realController.pileId, (newValue) {
|
||
|
ProcessEntity process = ProcessEntity(
|
||
|
recvTime: DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
||
|
pileId: realController.pileId.value,
|
||
|
utc: 0,
|
||
|
tid: 100,
|
||
|
toatalFlow1: format(realController.totalFlow1.value),
|
||
|
toatalFlow2: format(realController.totalFlow2.value),
|
||
|
subtotalFlow1: format(realController.subtotalFlow1.value),
|
||
|
subtotalFlow2: format(realController.subtotalFlow2.value),
|
||
|
depth: format(realController.depth.value),
|
||
|
);
|
||
|
processList.length = 0;
|
||
|
processList.add(process);
|
||
|
realController.updateProcessList(processList.toList());
|
||
|
realController.startIndex.value = 0;
|
||
|
});
|
||
|
|
||
|
List<Widget> chartTitleWidget = chartData.chartTitleWeidget();
|
||
|
Widget chartWidget(List<ProcessEntity> processList) {
|
||
|
int startIndex = 0;
|
||
|
|
||
|
if ((realController.startIndex.value + showlength) < processList.length &&
|
||
|
realController.startIndex.value != 0) {
|
||
|
startIndex = realController.startIndex.value;
|
||
|
} else {
|
||
|
startIndex = ((processList.length - showlength < 0)
|
||
|
? 0
|
||
|
: (processList.length - showlength));
|
||
|
}
|
||
|
int endIndex = startIndex + showlength > processList.length
|
||
|
? processList.length
|
||
|
: startIndex + showlength;
|
||
|
ChartData chartData = ChartData(
|
||
|
processList.sublist(startIndex, endIndex),
|
||
|
);
|
||
|
return LineChart(chartData.lineChart);
|
||
|
}
|
||
|
|
||
|
return Column(
|
||
|
children: [
|
||
|
Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: chartTitleWidget,
|
||
|
),
|
||
|
Expanded(
|
||
|
flex: 1,
|
||
|
child: Obx(
|
||
|
() => SizedBox(child: chartWidget(realController.processList))))
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
}
|