bluetooth_manager 0.0.10 copy "bluetooth_manager: ^0.0.10" to clipboard
bluetooth_manager: ^0.0.10 copied to clipboard

outdated

A simple plugin to manage Bluetooth, turning on and off ang geting Bluetooth state.

example/lib/main.dart

import 'package:bluetooth_manager/models/bluetooth_models.dart';
import 'package:flutter/material.dart';

import 'package:bluetooth_manager/bluetooth_manager.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> {
  late BluetoothState _bluetoothState = BluetoothState.uknow;

  @override
  void initState() {
    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('Bluetooth State: $_bluetoothState\n'),
              ElevatedButton(
                onPressed: () async {
                  /// Get bluetooth state
                  /// and set info [BluetoothState] in local _bluetoothState
                  await BluetoothManager.getBluetoothState
                      .then((value) async => {
                            setState(() {
                              _bluetoothState = value!;
                            }),
                          });
                },
                child: const Text('Get bluetooth State'),
              ),
              ElevatedButton(
                onPressed: () async {
                  /// valid bluetooth state
                  if (_bluetoothState == BluetoothState.on) {
                    /// if bluetooth state is on disable
                    /// and get [ActionResponse]
                    await BluetoothManager.disableBluetooth().then(
                      (value) => {
                        ///...
                        print(value),
                      },
                    );
                  } else {
                    /// if bluetooth state is off enable
                    /// /// and get [ActionResponse]
                    await BluetoothManager.enableBluetooth().then(
                      (value) => {
                        ///...
                        print(value),
                      },
                    );
                  }
                },
                child: const Text('Turn on/off'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
8
likes
0
pub points
81%
popularity

Publisher

unverified uploader

A simple plugin to manage Bluetooth, turning on and off ang geting Bluetooth state.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on bluetooth_manager