ecg_paper

Scrollable ECG “paper” widget for Flutter. Renders a clinical-style grid at 25 mm/s and 10 mm/mV. Feed mV samples and sample rate and it draws a 30s (configurable) trace you can horizontally scroll. 中文说明:见 README_ZH.md preview

Features

  • Clinical layout: 25 mm/s, 10 mm/mV (configurable)
  • Auto-detect units (assumes V → converts to mV)
  • Decimation for performance (min/max bucket) — keeps shape on large signals
  • Optional fixed Y range (fixedYRangeMv) or auto-fit
  • Smooth path rendering with grid & second ticks
  • Stateless API + easy theming via EcgStyle

Quick start

import 'package:ecg_paper/ecg_paper.dart';

final fs = 512.0; // Hz
final samplesMv = getSamplesInMilliVolt();

EcgScrollableWidget(
  samples: samplesMv,
  sampleRateHz: fs,
  durationSeconds: 10, // default 30
  style: const EcgStyle(height: 220),
  enableDecimation: true, // on by default
  autoDetectUnits: true,  // on by default
);

If your raw data is in Volt

Either multiply by 1000 before passing in, or leave as-is and keep autoDetectUnits: true (default).

Parameters

  • samples (List: ECG samples (mV recommended)
  • sampleRateHz (double)
  • durationSeconds (double): time window (default 30)
  • style (EcgStyle): speed, gain, grid, stroke, colors…
    • fixedYRangeMv (double?): set to e.g. 2.0 to lock ±2 mV; null = auto-fit
  • autoDetectUnits (bool): if true, convert V→mV when magnitude suggests Volt
  • enableDecimation (bool): enable min/max bucket decimation for performance
  • maxPoints (int?): hard cap after decimation (optional)
  • scrollToEndOnBuild (bool): auto scroll right on first build

Export a PNG (example app)

Run the example and tap Save PNG to export the current widget as a PNG under app documents. To make a GIF, record screen or export multiple PNGs and use ffmpeg:

ffmpeg -framerate 12 -i frame_%03d.png -vf "palettegen" palette.png
ffmpeg -framerate 12 -i frame_%03d.png -i palette.png -lavfi "paletteuse" ecg.gif

Tips

  • For extremely long buffers, decimation avoids building giant paths. You can also pre-trim to the desired window.
  • To lock Y range (clinical review), set fixedYRangeMv: 2.0 (±2 mV).

License

MIT

Libraries

ecg_paper