ble_keeper 0.1.0-beta.1 copy "ble_keeper: ^0.1.0-beta.1" to clipboard
ble_keeper: ^0.1.0-beta.1 copied to clipboard

Keeps a BLE peripheral connected in the background, after the app is killed and after a reboot, on Android and iOS, and reports when the OS blocks it.

example/lib/main.dart

import 'package:ble_keeper/ble_keeper.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'src/device_controller.dart';
import 'src/home_page.dart';

/// Runs in a background isolate when the OS restarted the app without UI.
/// Keep it short; on iOS the app has only a few seconds per Bluetooth event.
@pragma('vm:entry-point')
void backgroundHandler(KeeperEvent event) {
  // KeeperEvent.toString() contains the raw device ID; console output can
  // end up in crash-reporter breadcrumbs, so only log the type, in debug.
  if (kDebugMode) debugPrint('ble_keeper background: ${event.runtimeType}');
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Register on every start: callback handles change when the app is updated.
  await BleKeeper.instance.registerBackgroundHandler(backgroundHandler);
  runApp(ExampleApp(controller: DeviceController(BleKeeper.instance)));
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key, required this.controller});

  final DeviceController controller;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ble_keeper example',
      theme: ThemeData(
        colorSchemeSeed: Colors.indigo,
        brightness: Brightness.light,
      ),
      home: HomePage(controller: controller),
    );
  }
}
0
likes
0
points
80
downloads

Publisher

unverified uploader

Weekly Downloads

Keeps a BLE peripheral connected in the background, after the app is killed and after a reboot, on Android and iOS, and reports when the OS blocks it.

Repository (GitHub)
View/report issues

Topics

#bluetooth #ble #background #iot

License

unknown (license)

Dependencies

flutter, meta, plugin_platform_interface

More

Packages that depend on ble_keeper

Packages that implement ble_keeper