bluetooth_state_manager 0.0.1 copy "bluetooth_state_manager: ^0.0.1" to clipboard
bluetooth_state_manager: ^0.0.1 copied to clipboard

Bluetooth State Manager for Flutter.

example/lib/main.dart

import 'package:bluetooth_state_manager_example/bluetooth_manager.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final bluetoothManager = BluetoothManager();
  bool? isBleEnable;
  late Stream<bool> bluetoothManagerSubs;
  @override
  void initState() {
    bluetoothManagerSubs = bluetoothManager.listenBleState();
    if (isBleEnable == null) {
      bluetoothManager.onBle();
    }
    bluetoothManagerSubs.listen((event) {
      setState(() {
        isBleEnable = event;
      });
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('BLE STATUS: $isBleEnable\n'),
              ElevatedButton(onPressed: () => bluetoothManager.onBle(), child: const Text("On")),
              ElevatedButton(onPressed: () => bluetoothManager.offBle(), child: const Text("Off"))
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
130
pub points
50%
popularity

Publisher

unverified uploader

Bluetooth State Manager for Flutter.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on bluetooth_state_manager