Skip to content

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

License

Notifications You must be signed in to change notification settings

iandis/fluetooth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

eb2abcf · Feb 7, 2023

History

38 Commits
Feb 7, 2023
Jan 2, 2022
Jan 5, 2023
Jan 17, 2023
Dec 26, 2021
Dec 24, 2021
Dec 24, 2021
Feb 7, 2023
Jan 1, 2022
Jan 2, 2022
Dec 24, 2021
Feb 7, 2023

Repository files navigation

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);
...

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published