healthrian_ble_support_for_wearecg12 1.0.34 copy "healthrian_ble_support_for_wearecg12: ^1.0.34" to clipboard
healthrian_ble_support_for_wearecg12: ^1.0.34 copied to clipboard

unlisted

Healthrian BLE support library for WearECG12

example/README.md

Example #

![coverage][coverage_badge] [![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link] [![License: MIT][license_badge]][license_link]

Generated by the [Very Good CLI][very_good_cli_link] 🤖

Example for Healthrian BLE support library for WearECG12

Example code #

lib/ble/view/ble_page.dart

import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:healthrian_ble_support_for_wearecg12/'
    'healthrian_ble_support_for_wearecg12.dart';

class BlePage extends StatelessWidget {
  const BlePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      /// express a received packet which contains ecg signal
      body: Observer(
        key: UniqueKey(),
        builder: (context) {
          return StreamBuilder(
            stream: BLEManager().streams.rawStream,
            builder: (context, snapshot) {
              if (!snapshot.hasData) {
                return const Center(
                  child: Text('No Stream'),
                );
              }
              return Center(
                child: Text(
                  snapshot.data.toString(),
                ),
              );
            },
          );
        },
      ),

      /// control panel
      floatingActionButton: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          FloatingActionButton(
            onPressed: () {
              BLEManager().connectDevice();
            },
            child: const Icon(Icons.bluetooth),
          ),
          FloatingActionButton(
            onPressed: () {
              BLEManager().disconnectDevice();
            },
            child: const Icon(Icons.bluetooth_disabled),
          ),
          FloatingActionButton(
            onPressed: () async {
              await BLEManager().registerCharacteristics();
              await BLEManager().startMeasurementEcg();
            },
            child: const Icon(Icons.play_arrow),
          ),
          FloatingActionButton(
            onPressed: () {
              BLEManager().pauseMeasurementEcg();
            },
            child: const Icon(Icons.pause),
          ),
          FloatingActionButton(
            onPressed: () {
              BLEManager().stopMeasurementEcg();
            },
            child: const Icon(Icons.stop),
          ),
        ],
      ),
    );
  }
}

lib/bootstrap.dart or lib/main.dart

import 'package:healthrian_ble_support_for_wearecg12/'
    'healthrian_ble_support_for_wearecg12.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  BLEManager();

  runApp(const BLEApp());
}

Change the minSdkVersion for Android #

flutter_blue_plus is compatible only from version 19 of Android SDK so you should change this in android/app/build.gradle:

Android {
  defaultConfig {
     minSdkVersion: 19

Add permissions for Bluetooth #

We need to add the permission to use Bluetooth and access location:

Android

In the android/app/src/main/AndroidManifest.xml let’s add:

	 <uses-permission android:name="android.permission.BLUETOOTH" />  
	 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />  
	 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>  
 <application

IOS

In the ios/Runner/Info.plist let’s add:

	<dict>  
	    <key>NSBluetoothAlwaysUsageDescription</key>  
	    <string>Need BLE permission</string>  
	    <key>NSBluetoothPeripheralUsageDescription</key>  
	    <string>Need BLE permission</string>  
	    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>  
	    <string>Need Location permission</string>  
	    <key>NSLocationAlwaysUsageDescription</key>  
	    <string>Need Location permission</string>  
	    <key>NSLocationWhenInUseUsageDescription</key>  
	    <string>Need Location permission</string>

edit pubspec.yaml file #

Add dependencies of both BLE support and visualization support libraries. pubspec.yaml

dependencies:
  healthrian_ble_support_for_wearcardiot: ^1.0.4

  healthrian_visualization_support: ^1.0.8+1

And then run a pub get in the terminal.

flutter pub get

from scratch via very good cli #

very_good.bat create example --desc "Example for Healthrian BLE support library for WearECG12" --org "com.healthrian.library.ble.example"