bluetoothadapter:  Bluetooth Based Client-Server Apps

Sep 16, 2020

bluetoothadapter: Bluetooth Based Client-Server Apps

Facilitating Bluetooth server sockets for Flutter apps using bluetoothadapter plugin.

Author

Aditya Soni
Aditya SoniSoftware Engineer

The Problem

We came across a scenario where we were to communicate with a Raspberry Pi using Bluetooth. For this, we needed to implement a full-duplex type connection with the RPI.

We looked for some quick solutions over the internet, but unfortunately, we found none. There were very few Bluetooth based libraries that were well written and almost none/very few had an implementation for creating Bluetooth server sockets.

That's when we decided to come up with a simple and elegant approach to our problem.

The Solution

bluetoothadapter is a package which enables a Flutter application to communicate with other devices/programs through Bluetooth. It does so using Bluetooth based server sockets, which allows the Flutter app to establish a full-duplex connection with the other Bluetooth based devices which act as its counterpart.

Features provided by bluetoothadapter

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


Check out the code on Github - https://github.com/GeekyAnts/flutter-bluetooth-adapter

Visualization of the process

Client/Server process flow in a Bluetooth server socket
Client/Server process flow in a Bluetooth server socket

How to use ?

We start by adding the following dependency to our pubspec.yaml file:

dependencies:
bluetoothadapter: <latest version>​


There are mainly 4 main steps involved in the process:

  • Initiate the Bluetooth adapter
  • Implement listeners for observing connection status.
  • Implement listeners for receiving messages.
  • Implement methods for sending back the messages to the application counterpart.

Here's a code sample for the same:

//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();
  });
});

// Sending messages 
void sendMessage(String message){
  flutterbluetoothadapter.sendMessage(
                            message ?? "no msg",
                            sendByteByByte: false);
}

For a full example please check out this link : https://github.com/GeekyAnts/flutter-bluetooth-adapter/tree/master/example

I hope that this solution is what you require to enable your apps to communicate through bluetooth for critical functions and this implementation will help you understand how to use bluetoothadapter.

Thanks for reading!

Subscribe to Our Newsletter

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
Why Legacy Systems Make Business Growth More Expensive: Navigate A Smarter Path to Legacy Modernization
Sep 23, 2026

Why Legacy Systems Make Business Growth More Expensive: Navigate A Smarter Path to Legacy Modernization

Learn how legacy systems make business growth more expensive and how edge-first modernization can remove constraints without replacing the existing system.

Insight
SSO, Audit Logs and RBAC: The Enterprise Features AI Prototyping Tools Do Not Cover | Sarika Gautam
Sep 23, 2026

SSO, Audit Logs and RBAC: The Enterprise Features AI Prototyping Tools Do Not Cover | Sarika Gautam

Why AI-generated prototypes fail enterprise review: the context behind SSO, the cost of skipping audit logs, and how role explosion makes RBAC a product of its own.

Insight
Feature Flags as Technical Debt: The Cleanup Nobody Schedules
Sep 21, 2026

Feature Flags as Technical Debt: The Cleanup Nobody Schedules

This blog explains how unmanaged feature flags create technical debt and how teams can detect, manage, and remove them safely.

Insight
Building AI-First Enterprises: Why System Design Matters More Than AI Adoption
Sep 21, 2026

Building AI-First Enterprises: Why System Design Matters More Than AI Adoption

This blog explores how system design, architecture, and validation shape AI-first enterprises, while examining AI’s impact on software engineering and human decision-making.

Insight
The Product Studio in the AI Era: What Actually Changes | Sarika Gautam
Sep 21, 2026

The Product Studio in the AI Era: What Actually Changes | Sarika Gautam

What changes in product development when AI writes the code: the shift to architecture, the token cost of unplanned builds, and why juniors still matter.

Insight
AI and the Future of Digital Customer Experience: Where Technology Meets Human Creativity
Sep 18, 2026

AI and the Future of Digital Customer Experience: Where Technology Meets Human Creativity

A discussion on how AI, human creativity, research, and cross-functional collaboration are shaping the future of digital customer experience.

Insight
Scaling Down Before Scaling Up: Why Bigger Servers Don’t Fix Bad Architecture
Sep 17, 2026

Scaling Down Before Scaling Up: Why Bigger Servers Don’t Fix Bad Architecture

This blog explores how inefficient backend architecture can cause performance issues even under low traffic, covering practical ways to reduce database load, API latency, and resource usage before scaling infrastructure.

The Right Conversation Can

Save You Six Months.

Book a call