ECG Graph implemented
parent
b6a3ae2380
commit
433616c7b6
@ -0,0 +1,25 @@
|
|||||||
|
class EKGFileDetailResponseModel {
|
||||||
|
int duration;
|
||||||
|
String fileName;
|
||||||
|
List<int> shortData;
|
||||||
|
int startTime;
|
||||||
|
|
||||||
|
EKGFileDetailResponseModel(
|
||||||
|
{this.duration, this.fileName, this.shortData, this.startTime});
|
||||||
|
|
||||||
|
EKGFileDetailResponseModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
duration = json['duration'];
|
||||||
|
fileName = json['fileName'];
|
||||||
|
shortData = json['shortData'].cast<int>();
|
||||||
|
startTime = json['startTime'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||||
|
data['duration'] = this.duration;
|
||||||
|
data['fileName'] = this.fileName;
|
||||||
|
data['shortData'] = this.shortData;
|
||||||
|
data['startTime'] = this.startTime;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,110 @@
|
|||||||
|
import 'package:diplomaticquarterapp/models/ble_devices/viatom_devices/ekg_file_detail_response_model.dart';
|
||||||
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
||||||
|
import 'package:fl_chart/fl_chart.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class EKGChartView extends StatefulWidget {
|
||||||
|
EKGFileDetailResponseModel ekgFileDetailResponseModel;
|
||||||
|
|
||||||
|
EKGChartView({@required this.ekgFileDetailResponseModel});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<EKGChartView> createState() => _EKGChartViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EKGChartViewState extends State<EKGChartView> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
print(widget.ekgFileDetailResponseModel.fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
List<int> list = widget.ekgFileDetailResponseModel.shortData;
|
||||||
|
List<List<int>> mainList = chunkIntList(list, 1250);
|
||||||
|
|
||||||
|
return AppScaffold(
|
||||||
|
appBarTitle: "ECG",
|
||||||
|
showNewAppBar: true,
|
||||||
|
isShowDecPage: false,
|
||||||
|
showNewAppBarTitle: true,
|
||||||
|
backgroundColor: Color(0xffF8F8F8),
|
||||||
|
body: ListView.separated(
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: ScrollPhysics(),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.only(right: MediaQuery.of(context).size.width - (MediaQuery.of(context).size.width * (mainList[index].length / 1250))),
|
||||||
|
child: SizedBox(
|
||||||
|
height: 120.0,
|
||||||
|
child: LineChart(
|
||||||
|
LineChartData(
|
||||||
|
lineTouchData: LineTouchData(handleBuiltInTouches: false),
|
||||||
|
gridData: FlGridData(
|
||||||
|
show: true,
|
||||||
|
verticalInterval: 30,
|
||||||
|
horizontalInterval: 30,
|
||||||
|
getDrawingVerticalLine: (value) {
|
||||||
|
return FlLine(
|
||||||
|
color: Colors.red[300],
|
||||||
|
strokeWidth: 0.4,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
getDrawingHorizontalLine: (value) {
|
||||||
|
return FlLine(
|
||||||
|
color: Colors.red[300],
|
||||||
|
strokeWidth: 0.4,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
titlesData: FlTitlesData(show: false),
|
||||||
|
borderData: FlBorderData(
|
||||||
|
show: false,
|
||||||
|
border: Border.all(color: const Color(0xff37434d), width: 1),
|
||||||
|
),
|
||||||
|
minX: 0,
|
||||||
|
maxX: (mainList[index].length.toDouble() - 1),
|
||||||
|
minY: list.reduce((value, element) => value < element ? value : element).toDouble(),
|
||||||
|
maxY: list.reduce((value, element) => value > element ? value : element).toDouble(),
|
||||||
|
lineBarsData: [
|
||||||
|
LineChartBarData(
|
||||||
|
isCurved: false,
|
||||||
|
preventCurveOverShooting: true,
|
||||||
|
barWidth: 0.5,
|
||||||
|
dotData: FlDotData(show: false),
|
||||||
|
spots: getDataList(mainList[index]),
|
||||||
|
colors: [Colors.grey[800]],
|
||||||
|
isStrokeCapRound: true,
|
||||||
|
belowBarData: BarAreaData(show: false),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
itemCount: mainList.length,
|
||||||
|
separatorBuilder: (context, index) => SizedBox(height: 14),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<List<int>> chunkIntList(List<int> list, int chunkSize) {
|
||||||
|
List<List<int>> chunks = [];
|
||||||
|
for (int i = 0; i < list.length; i += chunkSize) {
|
||||||
|
int end = i + chunkSize;
|
||||||
|
chunks.add(list.sublist(i, end > list.length ? list.length : end));
|
||||||
|
}
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FlSpot> getDataList(List<int> list) {
|
||||||
|
List<FlSpot> spotsList = [];
|
||||||
|
for (int i = 0; i < list.length; i++) {
|
||||||
|
spotsList.add(FlSpot(i.toDouble(), list[i].toDouble()));
|
||||||
|
}
|
||||||
|
return spotsList;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue