bluetooth_print 0.1.0
bluetooth_print: ^0.1.0 copied to clipboard
A new flutter plugin project connect to bluetooth thermal printer (Gprinter).
Introduction #
BluetoothPrint is a bluetooth plugin for Flutter, a new mobile SDK to help developers build bluetooth thermal printer apps for both iOS and Android.(for example, Gprinter pt-380 eg.)
Features #
ios features maybe finished before this month end(eg. 2019/12/30)
Android | iOS | Description | |
---|---|---|---|
select devices | ✅ | scan for Bluetooth Low Energy devices and select. | |
connect | ✅ | Establishes a connection to the device. | |
disconnect | ✅ | Cancels an active or pending connection to the device. | |
print test message | ✅ | print device test message. | |
print text | ✅ | print custom text, support layout. | |
print image | ✅ | print image. | |
print qrcode | ✅ | print qrcode,support change size. | |
display connect status | ✅ | Stream of state changes for the Bluetooth Device. |
Usage #
To use this plugin :
- add the dependency to your pubspec.yaml file.
dependencies:
flutter:
sdk: flutter
bluetooth_print:
- init a BluetoothPrint instance
import 'package:bluetooth_print/bluetooth_print.dart';
import 'package:bluetooth_print/bluetooth_print_model.dart';
BluetoothPrint bluetoothPrint = BluetoothPrint.instance;
getDevices #
List<BluetoothDevice> list = await bluetoothPrint.getBondedDevices();
connect #
await bluetoothPrint.connect(_device);
disconnect #
await bluetoothPrint.disconnect();
listen state #
bluetoothPrint.state.listen((state) {
print('cur device status: $state');
switch (state) {
case BluetoothPrint.CONNECTED:
setState(() {
_connected = true;
});
break;
case BluetoothPrint.DISCONNECTED:
setState(() {
_connected = false;
});
break;
default:
break;
}
});