fluetooth 0.0.6 copy "fluetooth: ^0.0.6" to clipboard
fluetooth: ^0.0.6 copied to clipboard

Flutter library for sending bytes to Bluetooth devices.

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);
...
4
likes
100
pub points
50%
popularity

Publisher

unverified uploader

Flutter library for sending bytes to Bluetooth devices.

Repository
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, permission_handler

More

Packages that depend on fluetooth