Git Product home page Git Product logo

flutter-bluetooth-adapter's Introduction

bluetoothadapter

A Flutter plugin to expose the features of Bluetooth Adapter for Android only.

Objective

The primary purpose of this project was to communicate between flutter and Rasburry Pie using Bluetooth.

Main Features

  • Setting up a UUID from user end.
  • Checking Bluetooth connection status and giving alerts if its off or not right.
  • Getting list of paired devices.
  • Get a particular paired device info.
  • Start Bluetooth server.
  • Start Bluetooth client.
  • Start Bluetooth client.
  • Send message to a connected device.
  • Stream for listening to received messages.
  • Stream for listening to connection status (CONNECTED, CONNECTING, CONNECTION FAILED, LISTENING, DISCONNECTED).

Getting Started

For a full example please check /example folder. Here are only the most important parts of the code to illustrate how to use the library.

//Initiatinng the bluetooth adapter
Bluetoothadapter flutterbluetoothadapter = Bluetoothadapter();

//Listening to the connection status listener
String _connectionStatus = "NONE";
StreamSubscription _btConnectionStatusListener =flutterbluetoothadapter.connectionStatus().listen((dynamic status) {
  setState(() {
    _connectionStatus = status.toString();
  });
});

//Listening to the recieved messages
String _recievedMessage;
StreamSubscription _btReceivedMessageListener = flutterbluetoothadapter.receiveMessages().listen((dynamic newMessage) {
  setState(() {
    _recievedMessage = newMessage.toString();
  });
});

Getting paired devices

List<BtDevice> devices = await flutterbluetoothadapter.getDevices();

Getting paired device

await flutterbluetoothadapter.getDevice(deviceAddress);

Starting BT server

await flutterbluetoothadapter.startServer();

Starting BT client

flutterbluetoothadapter.startClient(devices.indexOf(element), true);

Sending message

flutterbluetoothadapter.sendMessage(messageString);

Check BT connection

await flutterbluetoothadapter.checkBluetooth(); //returns bool

Set UUID

flutterbluetoothadapter.initBlutoothConnection(uuid);

flutter-bluetooth-adapter's People

Contributors

soni-aditya avatar adityageekyants avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.