Fluetooth - Flutter library for sending bytes to Bluetooth devices on Android/iOS

Related tags

Bluetooth fluetooth
Overview

A Flutter library for sending bytes to Bluetooth devices. Available on Android and iOS.

Android Setup

This library is only compatible for Android SDK 21+, so we need this in android/app/build.gradle

Android {
  defaultConfig {
     minSdkVersion 21

iOS Setup

This library needs Bluetooth permissions on iOS, so we need this in ios/Runner/Info.plist

...
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Need BLE permission for connecting to BLE devices</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Need BLE permission for retrieving BLE devices info</string>
...

Examples

We'll need esc_pos_gen for this example.

First prepare a bill to be printed.

...
final List<PosComponent> components = <PosComponent>[
    const PosText.center('My Store'),
    const PosSeparator(),
    PosListComponent.builder(
    count: 20,
    builder: (int i) {
        return PosListComponent(
        <PosComponent>[
            PosRow.leftRightText(
            leftText: 'Product $i',
            leftTextStyles: const PosStyles.defaults(),
            rightText: 'USD $i',
            ),
            PosRow.leftRightText(
            leftText: '1 x USD $i',
            leftTextStyles: const PosStyles.defaults(
                fontType: PosFontType.fontB,
            ),
            rightText: 'USD $i',
            rightTextStyles: const PosStyles.defaults(
                align: PosAlign.right,
                fontType: PosFontType.fontB,
            ),
            ),
        ],
        );
    },
    ),
    const PosSeparator(),
    PosBarcode.code128('{A12345'.split('')),
    const PosSeparator(),
    const PosFeed(1),
    const PosCut(),
];

final Paper paper = Paper(
    generator: generator,
    components: components,
);
...

Retrieve available bluetooth devices.

final List<FluetoothDevice> devices = await Fluetooth().getAvailableDevices();

Connect to a printer.

...
final FluetoothDevice printer = devices.first;
await Fluetooth().connect(printer.id);

Prints the bill to the printer

...
await Fluetooth().sendBytes(paper.bytes);
...
You might also like...
Bluetooth mapping in Swift
Bluetooth mapping in Swift

Bluetonium is part of the E-sites iOS Suite. Bluetonium is a Swift Library that makes it easy to communicate with Bluetooth devices. Features 🎲 Servi

Bluetooth mesh messaging SDK for apps

Berkanan SDK Berkanan SDK enables Bluetooth mesh messaging between nearby apps. It's the framework used by Berkanan Messenger (Product Hunt, TechCrunc

MiniVendingMachine - SwiftUI demo Apple Watch app to open a mini vending machine via bluetooth

Mini Vending Machine Use Apple Watch to open vending machine cells. Note: This a

A very simple library to discover and retrieve data from nearby devices (even if the peer app works at background).
A very simple library to discover and retrieve data from nearby devices (even if the peer app works at background).

Discovery: A simple library to discover and retrieve data from nearby devices. Discovery is a very simple but useful library for discovering nearby de

The official Swift Library for Vital API, HealthKit and Devices

vital-ios The official Swift Library for Vital API, HealthKit and Devices Install We currently support SPM. Documentation Please refer to the official

BluetoothKit Easily communicate between iOS devices using BLE.

BluetoothKit Easily communicate between iOS devices using BLE. Background Apple mostly did a great job with the CoreBluetooth API, but because it enca

A simple framework that brings Apple devices together - like a family
A simple framework that brings Apple devices together - like a family

Apple Family A simple framework that brings Apple devices together - like a family. It will automatically use bluetooth, wifi, or USB to connect and c

📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework

CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework, making it possible to subscribe to perform bluetooth operations while subscribing to a publisher of the results of those operations, instead of relying on implementing delegates and manually filtering for the results you need.

Comments
  • It works on android but not on ios

    It works on android but not on ios

    I'm using this plugin to print receipts on a thermal printer. On Android it works correctly. But not on iOS. The printer is detected and connected, but it gives an error when printing. I tested the sample code and it also fails to print.

    [VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: PlatformException(FLUETOOTH_ERROR, The device does not support receiving bytes!, null, null)
    #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
    #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
    <asynchronous suspension>
    #2      _MyAppState._print (package:fluetooth_example/main.dart:142:5)
    <asynchronous suspension>
    
    flutter doctor -v
    [✓] Flutter (Channel stable, 3.0.5, on macOS 12.5 21G72 darwin-x64, locale en-US)
        • Flutter version 3.0.5 at /Users/muriloventuroso/Downloads/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f1875d570e (9 days ago), 2022-07-13 11:24:16 -0700
        • Engine revision e85ea0e79c
        • Dart version 2.17.6
        • DevTools version 2.12.2
    
    [✗] Android toolchain - develop for Android devices
        ✗ Unable to locate Android SDK.
          Install Android Studio from: https://developer.android.com/studio/index.html
          On first launch it will assist you in installing the Android SDK components.
          (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
          If the Android SDK has been installed to a custom location, please use
          `flutter config --android-sdk` to update to that location.
    
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.11.3
    
    [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
        ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
    
    [!] Android Studio (not installed)
        • Android Studio not found; download from https://developer.android.com/studio/index.html
          (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
    
    [✓] VS Code (version 1.69.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension can be installed from:
          🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
    
    [✓] Connected device (2 available)
        • iPhone (mobile) • 00008030-001C211411E8802E • ios        • iOS 15.5 19F77
        • macOS (desktop) • macos                     • darwin-x64 • macOS 12.5 21G72 darwin-x64
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 2 categories.
    
    opened by muriloventuroso 2
Releases(0.0.2)
  • 0.0.2(Jan 2, 2022)

    What's Changed

    • 💉fix(android): fix methods by @iandis in https://github.com/iandis/fluetooth/pull/4
    • Docs/fix docs by @iandis in https://github.com/iandis/fluetooth/pull/5
    • 🍭chore(example): update esc_pos_gen by @iandis in https://github.com/iandis/fluetooth/pull/6
    • 🍭chore(version): bump 0.0.2 by @iandis in https://github.com/iandis/fluetooth/pull/7

    Full Changelog: https://github.com/iandis/fluetooth/compare/0.0.1...0.0.2

    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Jan 1, 2022)

    What's Changed

    • 🚀Refactor(Android): New non-blocking thread by @iandis in https://github.com/iandis/fluetooth/pull/1
    • 🚀 New Feature: iOS support by @iandis in https://github.com/iandis/fluetooth/pull/2
    • Update README, prepare to release by @iandis in https://github.com/iandis/fluetooth/pull/3

    New Contributors

    • @iandis made their first contribution in https://github.com/iandis/fluetooth/pull/1

    Full Changelog: https://github.com/iandis/fluetooth/commits/0.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
Iandi Santulus
a senior cs student who loves building apps using Flutter
Iandi Santulus
RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant.

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Polidea 1.3k Jan 6, 2023
Build your own 'AirTags' 🏷 today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.

OpenHaystack is a framework for tracking personal Bluetooth devices via Apple's massive Find My network.

Secure Mobile Networking Lab 5.8k Jan 9, 2023
The Bluetooth LE library for iOS and Mac. 100% Swift.

iOS-BLE-Library An in-development Bluetooth Low Energy Library by Nordic Semiconductor to interact with the , which is not complicated, but requires w

Nordic Semiconductor 6 Dec 19, 2022
Simple, block-based, lightweight library over CoreBluetooth. Will clean up your Core Bluetooth related code.

LGBluetooth Simple, block-based, lightweight library over CoreBluetooth. Steps to start using Drag and Drop it into your project Import "LGBluetooth.h

null 170 Sep 19, 2022
iOS Bluetooth LE framework

Features A futures interface replacing protocol implementations. Timeout for Peripheral connection, Service scan, Service + Characteristic discovery a

Troy Stribling 696 Dec 25, 2022
The easiest way to use Bluetooth (BLE )in ios,even bady can use.

The easiest way to use Bluetooth (BLE )in ios,even bady can use.

刘彦玮 4.6k Dec 27, 2022
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.

ExtendaBLE Introduction ExtendaBLE provides a very flexible syntax for defining centrals and peripherals with ease. Following a blocks based builder a

Anton 94 Nov 29, 2022
Bluejay is a simple Swift framework for building reliable Bluetooth LE apps.

Bluejay is a simple Swift framework for building reliable Bluetooth LE apps. Bluejay's primary goals are: Simplify talking to a single Bluetooth LE pe

Steamclock Software 1k Dec 13, 2022
Omnipod Bluetooth PumpManager For Loop

OmniBLE Omnipod Bluetooth PumpManager For Loop Status This module is at the very beginning stages of development and does not even compile yet. DO NOT

Randall Knutson 20 Apr 21, 2022
Diabetes: test the FreeStyle Libre glucose sensor as a Bluetooth Low Energy device, even directly from an Apple Watch.

Since the FreeStyle Libre 2 / 3 glucose sensors are Bluetooth Low Energy devices, I am trying to leverage their capabilities to implement something ne

Guido Soranzio 6 Jan 2, 2023