Heart Rate
A Flutter package to measure heart rate using the phone's camera and flash, supporting both Android and iOS.
⚠️ Disclaimer
This package is not a medical device and is not intended for medical diagnosis, treatment, or prevention of any disease.
Heart rate measurements provided by this package are for informational and educational purposes only and may not be accurate.
Do not rely on this package for medical decisions.
Features
- Real-time heart rate (BPM) measurement.
- Uses the phone's camera and flash/torch for detection.
- Simple
HeartRateDialogwidget for easy integration. - Cross-platform support for Android and iOS.
Getting Started
Add this to your package's pubspec.yaml file:
dependencies:
heart_rate: ^0.0.1 # Replace with the latest version
Then, run flutter pub get.
Platform Specific Setup
Android
Add the following permissions to your android/app/src/main/AndroidManifest.xml file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
iOS
Add the following key to your ios/Runner/Info.plist file:
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to measure your heart rate.</string>
Usage
Import the package:
import 'package:heart_rate/heart_rate.dart';
Use the HeartRateDialog widget in your app. It provides a callback with the measured BPM.
class HeartRateExample extends StatefulWidget {
const HeartRateExample({super.key});
@override
State<HeartRateExample> createState() => _HeartRateExampleState();
}
class _HeartRateExampleState extends State<HeartRateExample> {
int _bpm = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Heart Rate Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Your heart rate is:'),
Text(
'$_bpm BPM',
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 20),
HeartRateDialog(
onBPM: (bpm) {
setState(() {
_bpm = bpm;
});
},
),
],
),
),
);
}
}
For a complete example, see the /example directory.
Created by
Harshvardhan Mahavadiya
GitHub
Additional Information
- To file issues, please use the issue tracker.
- Contributions are welcome! Please feel free to submit a pull request.