ppg 0.1.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

ppg #

A Flutter plugin to access the PPG sensor.

This plugin is a modification of sensors. I have tested it to read the PPG sensor in WearOS with both a Fossil Sport and a Fossil Gen 5. This plugin only supports Android. I don't know if it is even possible to read the raw PPG data from Apple WatchOS yet, but it would be super cool if someone could add that functionality. Both of the WearOS watches I tested with had a sensor of type com.google.wear.sensor.ppg. This plugin will detect a PPG sensor if its type contains ppg

Update: I used this plugin to make a simple heart monitoring app link

Usage #

This plugin exposes Streams of PPGEvents and HREvents

Example #

import 'package:ppg/ppg.dart';

ppgEvents.listen((PPGEvent event) {
  print(event);
});
// [PPGEvent (x: [0.0, 0.0], t: 0.0)]

hrEvents.listen((HREvent event) {
  print(event);
});
// [HREvent (x: 0.0, t: 0.0)]

Also see the example subdirectory for an example application that uses PPG data.

0.1.9 #

  • Added accuracy field to PPGEvent and HREvent

0.1.5 #

  • Added HREvent stream

0.1.3 #

  • Only streams events if a PPG sensor is detected

0.1.2 #

  • Set wakeUp to true in sensorManager.getDefaultSensor, increased minSdkVersion to 21

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:scoped_model/scoped_model.dart';
import 'app_state.dart';

void main() {
  final AppState state = AppState();

  final MaterialApp app = MaterialApp(
    title: 'PPG Example',
    debugShowCheckedModeBanner: false,
    home: ScopedModel<AppState>(model: state, child: PPGExample()),
  );

  runApp(app);

  state.initPPG();

  handlePermissionResponse(Map<PermissionGroup, PermissionStatus> status) {
    if (status[PermissionGroup.sensors] == PermissionStatus.granted) {
      state.initHR();
    }
  }

  handlePermissionStatus(PermissionStatus status) => status ==
          PermissionStatus.granted
      ? state.initHR()
      : PermissionHandler()
          .requestPermissions(<PermissionGroup>[PermissionGroup.sensors]).then(
              handlePermissionResponse);

  PermissionHandler()
      .checkPermissionStatus(PermissionGroup.sensors)
      .then(handlePermissionStatus);
}

class PPGExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final AppState state = ScopedModel.of<AppState>(
      context,
      rebuildOnChange: true,
    );

    final String ppgTxt = !state.ppgDetected
        ? 'PPG not detected'
        : 'Channel 1: ${state.ppgData[0]}\n'
            'Channel 2: ${state.ppgData[1]}\n'
            'timestamp: ${state.ppgTimestamp.round()}\n'
            'accuracy: ${state.ppgAccuracy}';

    final String hrTxt = !state.hrPermission
        ? 'Permission not granted'
        : !state.hrDetected
            ? 'Reading...'
            : '${state.hrData.round()} bpm\n'
                'timestamp: ${state.hrTimestamp.round()}\n'
                'accuracy: ${state.hrAccuracy}';

    final String txt = 'PPG\n$ppgTxt\n\nHeart Rate\n$hrTxt';

    return Scaffold(
      backgroundColor: Colors.black,
      body: Container(
        alignment: Alignment.centerLeft,
        padding: EdgeInsets.only(left: MediaQuery.of(context).size.width / 6),
        child: Text(
          txt,
          style: TextStyle(color: Colors.white),
          textAlign: TextAlign.left,
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ppg: ^0.1.9

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ppg/ppg.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
22
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:ppg/ppg.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:ppg/ppg.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:ppg/ppg.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:ppg/ppg.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • ppg that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

13 out of 13 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test