bixolon_btprinter 0.1.2 copy "bixolon_btprinter: ^0.1.2" to clipboard
bixolon_btprinter: ^0.1.2 copied to clipboard

discontinued
PlatformAndroidiOS

This Flutter plugin allows you to connect to a Bixolon printer via Bluetooth and send print commands. The files in the libs folder belong to Bixolon.

bixolon_btprinter #

※It's not an officially supported plugin.

This plugin enables receipt printing on Bixolon Bluetooth printers. It has been tested with the Bixolon SPP-R310 printer and supports Bixolon's Bluetooth mobile printers. Additionally, it only supports the Korean character set for printing.

Getting Started #

To use btPrinter in your Flutter project, add it to your pubspec.yaml:

dependencies:
  bixolon_btprinter: ^0.1.2 # Replace with the latest version

Usage #

1. Requesting Bluetooth Permissions

Future<void> requestBluetoothPermissions() async {
  final _btprinterPlugin = Btprinter();
  String? result;
  try {
    result = await _btprinterPlugin.getBtPermission();
  } on PlatformException catch (e) {
    result = 'Error: ${e.message}';
  }
  print(result); // Prints "success" if permissions are granted
}

2. Retrieving Paired Devices

Future<void> getPairedDevices() async {
  final _btprinterPlugin = Btprinter();
  List<String?> devices = [];
  try {
    List<Object?> result = await _btprinterPlugin.getPairedDevices();
    devices = result.cast<String>().where((device) => device.startsWith('SPP')).toList();
  } on PlatformException catch (e) {
    print('Error: ${e.message}');
  }
  print(devices); // Prints the list of paired devices
}

3. Printing Text

Future<void> print(String device) async {
  final _btprinterPlugin = Btprinter();

  List<String> deviceInfo = device!.split('(');
  String logicalName = deviceInfo[0].split("_")[0].trim();
  String address = deviceInfo[1].replaceAll(')', '').trim();

  List<Map<String, dynamic>> textRequests = [
    {
      'text': 'Print Title Test\n',
      'textAlignment': Btprinter.ALIGNMENT_CENTER,
      'textAttribute': Btprinter.ATTRIBUTE_BOLD,
      'textSize': 2,
    },
    {
      'text': 'Print Content Test\n\n',
      'textAlignment': Btprinter.ALIGNMENT_LEFT,
      'textAttribute': Btprinter.ATTRIBUTE_NORMAL,
      'textSize': 1,
    },
  ];

  String? result;
  try {
    result = await _btprinterPlugin.printText(textRequests, logicalName, address);
  } on PlatformException catch (e) {
    result = 'Error: ${e.message}';
  }
  print(result); // Prints "success" if printing is successful
}

4. Printing Barcode

Future<void> print(String device) async {
  final _btprinterPlugin = Btprinter();

  List<String> deviceInfo = device!.split('(');
  String logicalName = deviceInfo[0].split("_")[0].trim();
  String address = deviceInfo[1].replaceAll(')', '').trim();

  List<Map<String, dynamic>> barcodeRequests = [
    {
      'data': '123456789012\n',
      'symbology': Btprinter.BARCODE_TYPE_ITF, //Optional, default value
      'width': 3, // Optional, default value
      'height': 100, // Optional, default value
      'alignment': Btprinter.ALIGNMENT_LEFT, //Optional, default value
      'hri': Btprinter.BARCODE_HRI_BELOW, //Optional, default value
    },
  ];

  String? result;
  try {
    result = await _btprinterPlugin.printBarcode(barcodeRequests, logicalName, address);
  } on PlatformException catch (e) {
    result = 'Error: ${e.message}';
  }
  print(result); // Prints "success" if printing is successful
}
0
likes
140
pub points
11%
popularity

Publisher

unverified uploader

This Flutter plugin allows you to connect to a Bixolon printer via Bluetooth and send print commands. The files in the libs folder belong to Bixolon.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on bixolon_btprinter