Using Bluetooth plugin in Flutter (flutter_bluetooth_serial)

Overview

Flutter Bluetooth

Codemagic build status

NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a lot of functionality.

IMPORTANT NOTE [January 1, 2021]:

A much optimized and production release version of this app is available, called Connect (supports both Android and iOS devices).

Learn more about it here.

This flutter app will help you to connect to Bluetooth Devices (like, HC-05). You can send messages to the bluetooth module and perform various operations. By default, the app has only on and off functionality for any paired bluetooth devices, but you can add as many functionality as you want.

Initially, you will have to give location permission to the app. As for discovering as well as for connecting to the paired devices, location permission is required as Bluetooth transmission shares some location data.

Add this dependency in pubspec.yaml:

dependencies:
  flutter_bluetooth_serial: ^0.2.2

How to run the app

You should have flutter installed and up running properly to use this application. To check if there is any problem, use the command:

flutter doctor

Now, navigate to the project folder and run this command:

flutter run

If you get any error like this :

Then navigate to your project folder (like, flutter_bluetooth) after opening the project folder follow these steps: android -> app -> src -> main -> AndroidManifest.xml

Now, add these two lines of code :

<manifest ......
          
    <!-- this line -->
    xmlns:tools="http://schemas.android.com/tools">

    <!-- and this line -->
    <uses-sdk tools:overrideLibrary="io.github.edufolly.flutterbluetoothserial"/>
    ...
</manifest>

Screenshots

License

Copyright (c) 2019 Souvik Biswas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • read failed, socket might closed or timeout, read ret: -1

    read failed, socket might closed or timeout, read ret: -1

    Error occurred while connecting to a paired device.

    W/BluetoothAdapter(28901): getBluetoothService() called with no BluetoothManagerCallback
    E/FlutterBluePlugin(28901): read failed, socket might closed or timeout, read ret: -1
    E/FlutterBluePlugin(28901): java.io.IOException: read failed, socket might closed or timeout, read ret: -1
    E/FlutterBluePlugin(28901): 	at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:741)
    E/FlutterBluePlugin(28901): 	at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:753)
    E/FlutterBluePlugin(28901): 	at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:375)
    E/FlutterBluePlugin(28901): 	at io.github.edufolly.flutterbluetoothserial.FlutterBluetoothSerialPlugin.lambda$connect$0(FlutterBluetoothSerialPlugin.java:235)
    E/FlutterBluePlugin(28901): 	at io.github.edufolly.flutterbluetoothserial.-$$Lambda$FlutterBluetoothSerialPlugin$52C5RUgoP_r70sgAnP8ZXC1Ysz0.run(lambda)
    E/FlutterBluePlugin(28901): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
    E/FlutterBluePlugin(28901): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    E/FlutterBluePlugin(28901): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    E/FlutterBluePlugin(28901): 	at java.lang.Thread.run(Thread.java:760)
    

    Flutter Doctor

    [✓] Flutter (Channel stable, v1.2.1, on Linux, locale en_GB.UTF-8)
        • Flutter version 1.2.1 at /home/chandu/Flutter
        • Framework revision 8661d8aecd (3 weeks ago), 2019-02-14 19:19:53 -0800
        • Engine revision 3757390fa4
        • Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
        • Android SDK at /home/chandu/Android/Sdk
        • Android NDK location not configured (optional; useful for native profiling support)
        • Platform android-28, build-tools 28.0.3
        • ANDROID_SDK_ROOT = /home/chandu/Android/Sdk
        • Java binary at: /opt/android-studio/jre/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
        • All Android licenses accepted.
    
    [✓] Android Studio (version 3.3)
        • Android Studio at /opt/android-studio
        • Flutter plugin version 33.3.1
        • Dart plugin version 182.5215
        • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    
    [✓] VS Code (version 1.31.1)
        • VS Code at /usr/share/code
        • Flutter extension version 2.24.0
    
    [✓] Connected device (1 available)
        • Redmi Note 4 • 192.168.0.100:5555 • android-arm64 • Android 7.0 (API 24)
    
    • No issues found!
    
    opened by ctrleffive 4
  • Bluetooth -> BLE

    Bluetooth -> BLE

    Hallo... It's first time I've found Arduino's source without library... That's what I need for some incompatible processor. But... About Flutter BLE and ht-10 (or other processor)? ArduinoBLE.h doesn't work with incompatible... Can you help? PLEASE PLEASE

    @}-,-'----- Gianfranco

    opened by GianfryPeres 3
  • ❓ : How can I get the strength of nearby bluetooth signals

    ❓ : How can I get the strength of nearby bluetooth signals

    In my project I need to get the strength of Bluetooth signals in the vicinity, is it possible using this package? If it's already present please provide some pointers to it.

    Regards Joe

    opened by joe733 0
  • Sending Variable From the buttons

    Sending Variable From the buttons

    Hey i was trying to make some changes to your functions and trying to implement it to send variable data to my arduino. Can you please help with that?

    opened by ameysatwe 0
  • Flutter app problem

    Flutter app problem

    hello

    i have issue that very important

    Thank you very much for answering even a part of this question

    How to enable the ability to send data via Bluetooth Mobile to device in the app I created

    i create app with flutter

    device is a smart door in a house and also i want to Connect with flutter experts and use their experience.

    And I thought this is a good reason.

    opened by mehdi-tofani 0
  • FlutterProblem

    FlutterProblem

    hello

    i have issue that very important

    Thank you very much for answering even a part of this question

    How to enable the ability to send data via Bluetooth Mobile to device in the app I created

    i create app with flutter

    device is a smart door in a house

    and i want to control that door with my app

    and also i want to Connect with flutter experts and use their experience.

    And I thought this is a good reason.

    opened by mehdi-tofani 1
  • Bluetooth disconnects when changing the page.

    Bluetooth disconnects when changing the page.

    Friends, the example is working normally, but when entering another page the bluetooth is disconnected. When I return to the configuration page, I need to configure it again. Can anyone help me with this problem?

    I am using version 0.2.2 of the serial bluetooth flutter. I tried to set it to false in the isDisconnecting property, but it didn't work!

    @override void dispose() { // Avoid memory leak and disconnect if (isConnected) { isDisconnecting = false; connection.dispose(); connection = null; }

    super.dispose();
    

    }

    I appreciate any comments!

    opened by ftecnologiasistemas 0
Owner
Souvik Biswas
Android, iOS & Flutter Developer | C++, Java and Dart Programmer | Technical Writer @Medium & @codemagic-ci-cd | @udacity Secure and Private AI '19 Scholar
Souvik Biswas
A project to get data from a fitbit device using bluetooth

Flutter 2 Boilerplate (version 1.3.0) A boilerplate project created in flutter. Boilerplate supports both web and mobile. VSCode is recommended in thi

Vajira Att 0 Dec 16, 2021
FlutterBleLib - A library for all your Bluetooth Low Energy needs in Flutter.

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

null 4 Jun 10, 2022
Bluetooth Low Energy library for Flutter with support for simulating peripherals

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

intent 509 Jan 3, 2023
A Flutter Template to communicate with an esp32 over bluetooth

Flutter Esp32 Bluetooth Template Changes in android/ [1 if you take the code to an other project, 2 still nessesarely]: Change minSdkVersion from 16 t

0x4d/Martin Loretz 23 Dec 20, 2022
null 5 Nov 21, 2022
This flutter app will help you to connect to Bluetooth Devices (like, HC-05)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Riyad Al-Ali 1 Jun 5, 2022
Flutter basic implementation for Classical Bluetooth (only RFCOMM for now)

flutter_bluetooth_serial Flutter basic implementation for Classical Bluetooth (only RFCOMM for now). Features The first goal of this project, started

null 1 Nov 7, 2022
I have created app to connect printer with bluetooth. And I already fix library bugs

flutter_bluetooth_printer A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to ge

Bounphone KOSADA 1 May 11, 2022
EI Blue - Edge Impulse Data Capture Over Bluetooth

EI Blue - Edge Impulse Data Capture Over Bluetooth Purpose of this project is to enable embedded engineers to collect data from bluetooth enabled micr

Mithun Das 4 Dec 21, 2022
Flutter beacons plugin for Android and iOS.

Beacons Flutter plugin to work with beacons. Supports Android API 16+ and iOS 8+. Features: Automatic permission management Ranging Monitoring (includ

Loup 76 Jan 6, 2023
Flutter NFC reader plugin for iOS and Android

Flutter NFC Reader & Writer A new flutter plugin to help developers looking to use internal hardware inside iOS or Android devices for reading and wri

Matteo Crippa 321 Dec 30, 2022
A Flutter plugin for turning your device into a beacon.

Beacon Broadcast plugin for Flutter A Flutter plugin for turning your device into a beacon. Usage To use this plugin, add beacon_broadcast as a depend

Paulina Szklarska 75 Dec 14, 2022
Flutter plugin for accessing the NFC features on Android and iOS.

nfc_manager Flutter plugin for accessing the NFC features on Android and iOS. Note: This plugin depends on NFCTagReaderSession (requires iOS 13.0 or l

null 126 Jan 1, 2023
Ready for Building Production-Ready Healthcare/ Doctor Consult Android and iOS app UI using Flutter.

Production-Ready Doctor Consultant App - Flutter UI Watch it on YouTube Packages we are using: flutter_svg: link Complete Source code (Patreon) In thi

Abu Anwar 211 Jan 1, 2023
Flutter library that handles BLE operations for multiple devices.

Flutter reactive BLE library Flutter library that handles BLE operations for multiple devices. Usage The reactive BLE lib supports the following: BLE

Philips Hue 473 Jan 4, 2023
ESC/POS (thermal, receipt) printing for Flutter & Dart (Android/iOS)

esc_pos_bluetooth The library allows to print receipts using a Bluetooth printer. For WiFi/Ethernet printers, use esc_pos_printer library. TODO (PRs a

Andrey 175 Jan 6, 2023
Flutter blue plus - Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS

Introduction FlutterBluePlus is a bluetooth plugin for Flutter, a new app SDK to

null 141 Dec 22, 2022
Bluetooth plugin for Flutter

Introduction FlutterBlue is a bluetooth plugin for Flutter, a new app SDK to help developers build modern multi-platform apps. Alpha version This libr

Paul DeMarco 2.2k Jan 5, 2023
A Flutter library allows to print receipts using a Bluetooth printer

esc_pos_bluetooth The library allows to print receipts using a Bluetooth printer. For WiFi/Ethernet printers, use esc_pos_printer library. TODO (PRs a

null 3 Dec 20, 2021
A project to get data from a fitbit device using bluetooth

Flutter 2 Boilerplate (version 1.3.0) A boilerplate project created in flutter. Boilerplate supports both web and mobile. VSCode is recommended in thi

Vajira Att 0 Dec 16, 2021