import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:dartedflib/dartedflib.dart';
class ShenqiPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final axisPaint = Paint()
..color = Colors.white
..strokeWidth = 1
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round;
canvas.drawRect(
Rect.fromCircle(center: const Offset(75, 75), radius: 75), axisPaint);
}
@override
bool shouldRepaint(ShenqiPainter oldDelegate) => false;
@override
bool shouldRebuildSemantics(ShenqiPainter oldDelegate) => false;
}
class linesPainter extends CustomPainter {
final List<double> widgets;
linesPainter({required this.widgets});
@override
void paint(Canvas canvas, Size size) {
final linesPaint = Paint()
..color = const Color.fromARGB(255, 232, 6, 6)
..strokeWidth = 0.5
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
int i, j;
Path path1 = Path()..moveTo(0, 100);
for (i = 0; i < widgets.length; i ++) {
path1.lineTo(i.toDouble(), widgets[i]);
}
canvas.drawPath(path1, linesPaint);
// for (i = 0; i <= 150; i += 10) {
// for (j = 0; j <= 150; j += 10) {
// canvas.drawLine(Offset(j, i), Offset(j + 10, i), linesPaint);
// }
// }
}
@override
bool shouldRepaint(linesPainter oldDelegate) => false;
@override
bool shouldRebuildSemantics(linesPainter oldDelegate) => false;
}
class myrun extends StatefulWidget {
const myrun({super.key});
@override
State<myrun> createState() => _myrunState();
}
class _myrunState extends State<myrun> {
late List<double> firstChannelData;
List<double> shuzi = [25, 61, 85, 64, 98, 51];
List<double> data = List.filled(100, 0.0);
@override
void initState() {
super.initState();
final edfReader = EdfReader("E:/test_subsecond.edf");
// 获取第一个通道的物理数据,如果需要,可以指定起始点和长度
firstChannelData =
edfReader.readSignal(0).map((num value) => value.toDouble()).toList();
edfReader.close();
int i;
for(i=0;i<data.length;i++){
data[i]=firstChannelData[i];
}
gengxin();
}
void gengxin(){
const duration = Duration(milliseconds: 100);
Timer.periodic(duration, (Timer t) {
updateData();
}
);
}
int j = 0;
void updateData() {
setState(() {
data.removeAt(0);
double lastPrice =
firstChannelData[j]; // Assuming firstChannelData is your updated data
data.add(lastPrice);
j++;
if (j > firstChannelData.length - 1) {
j = 0;
}
});
}
@override
Widget build(BuildContext context) {
return Container(
child: CustomPaint(
painter: linesPainter(widgets:data),
),
);
}
}
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('ECG Chart')),
body: Padding(padding: EdgeInsets.all(80.0), child: myrun()),
),
));
}
有没有佬帮忙看看这个代码为什么实现不了功能