- Saved searches
- Use saved searches to filter your results more quickly
- License
- thon-ju/bluetooth_print
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- How to setup a Bluetooth thermal printer?
- How to connect Thermal Bluetooth Printer to iOS devices
- 1 Answer 1
- Saved searches
- Use saved searches to filter your results more quickly
- License
- kakzaki/blue_thermal_printer
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
a flutter plugin connect to bluetooth thermal printer support both Android and IOS (eg. Gprinter pt-380、gp-1324、gp-2120)
License
thon-ju/bluetooth_print
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
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-280、pt-380、gp-1324、gp-2120 eg.)
[ ] print x,y positions
[ ] set paper size
[ ] more print examples
4.0.0(flutter 3.x)
3.0.0(flutter 2.x)
2.0.0(flutter 1.12)
1.2.0(flutter 1.9)
Android | iOS | Description | |
---|---|---|---|
scan | ✅ | ✅ | Starts a scan for Bluetooth Low Energy devices. |
connect | ✅ | ✅ | Establishes a connection to the device. |
disconnect | ✅ | ✅ | Cancels an active or pending connection to the device. |
state | ✅ | ✅ | Stream of state changes for the Bluetooth 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. |
print barcode | ✅ | ✅ | print barcode |
dependencies: flutter: sdk: flutter bluetooth_print:
Add permissions for Bluetooth
We need to add the permission to use Bluetooth and access location:
In the android/app/src/main/AndroidManifest.xml let’s add:
uses-permission android:name="android.permission.BLUETOOTH" /> uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> application
In the ios/Runner/Info.plist let’s add:
dict> key>NSBluetoothAlwaysUsageDescription string>Need BLE permission/string> key>NSBluetoothPeripheralUsageDescription string>Need BLE permission/string> key>NSLocationAlwaysAndWhenInUseUsageDescription string>Need Location permission/string> key>NSLocationAlwaysUsageDescription string>Need Location permission/string> key>NSLocationWhenInUseUsageDescription string>Need Location permission/string>
init a BluetoothPrint instance
import 'package:bluetooth_print/bluetooth_print.dart'; import 'package:bluetooth_print/bluetooth_print_model.dart'; BluetoothPrint bluetoothPrint = BluetoothPrint.instance;
// begin scan bluetoothPrint.startScan(timeout: Duration(seconds: 4)); // get devices StreamBuilderListBluetoothDevice>>( stream: bluetoothPrint.scanResults, initialData: [], builder: (c, snapshot) => Column( children: snapshot.data.map((d) => ListTile( title: Text(d.name??''), subtitle: Text(d.address), onTap: () async < setState(() < _device = d; >); >, trailing: _device!=null && _device.address == d.address?Icon( Icons.check, color: Colors.green, ):null, )).toList(), ), ),
await bluetoothPrint.connect(_device);
await bluetoothPrint.disconnect();
bluetoothPrint.state.listen((state) < print('cur device status: $state'); # bluetooth_print switch (state) < case BluetoothPrint.CONNECTED: setState(() < _connected = true; >); break; case BluetoothPrint.DISCONNECTED: setState(() < _connected = false; >); break; default: break; > >);
A new flutter plugin project.
print (esc command, receipt mode)
MapString, dynamic> config = Map(); ListLineText> list = List(); list.add(LineText(type: LineText.TYPE_TEXT, content: 'A Title', weight: 1, align: LineText.ALIGN_CENTER,linefeed: 1)); list.add(LineText(type: LineText.TYPE_TEXT, content: 'this is conent left', weight: 0, align: LineText.ALIGN_LEFT,linefeed: 1)); list.add(LineText(type: LineText.TYPE_TEXT, content: 'this is conent right', align: LineText.ALIGN_RIGHT,linefeed: 1)); list.add(LineText(linefeed: 1)); list.add(LineText(type: LineText.TYPE_BARCODE, content: 'A12312112', size:10, align: LineText.ALIGN_CENTER, linefeed: 1)); list.add(LineText(linefeed: 1)); list.add(LineText(type: LineText.TYPE_QRCODE, content: 'qrcode i', size:10, align: LineText.ALIGN_CENTER, linefeed: 1)); list.add(LineText(linefeed: 1)); ## Getting Started ByteData data = await rootBundle.load("assets/images/guide3.png"); Listint> imageBytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); String base64Image = base64Encode(imageBytes); list.add(LineText(type: LineText.TYPE_IMAGE, content: base64Image, align: LineText.ALIGN_CENTER, linefeed: 1)); This project is a starting point for a Flutter [plug-in package](https://flutter.dev/developing-packages/), a specialized package that includes platform-specific implementation code for Android and/or iOS. await bluetoothPrint.printReceipt(config, list);
For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
print (tsc command, label mode)
MapString, dynamic> config = Map(); config['width'] = 40; // 标签宽度,单位mm config['height'] = 70; // 标签高度,单位mm config['gap'] = 2; // 标签间隔,单位mm // x、y坐标位置,单位dpi,1mm=8dpi ListLineText> list = List(); list.add(LineText(type: LineText.TYPE_TEXT, x:10, y:10, content: 'A Title')); list.add(LineText(type: LineText.TYPE_TEXT, x:10, y:40, content: 'this is content')); list.add(LineText(type: LineText.TYPE_QRCODE, x:10, y:70, content: 'qrcode i\n')); list.add(LineText(type: LineText.TYPE_BARCODE, x:10, y:190, content: 'qrcode i\n')); ListLineText> list1 = List(); ByteData data = await rootBundle.load("assets/images/guide3.png"); Listint> imageBytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes); String base64Image = base64Encode(imageBytes); list1.add(LineText(type: LineText.TYPE_IMAGE, x:10, y:10, content: base64Image,)); await bluetoothPrint.printLabel(config, list); await bluetoothPrint.printLabel(config, list1);
ios import third party library
# .a filename must begin with lib, eg. 'libXXX.a' s.vendored_libraries = '**/*.a'
error:’State restoration of CBCentralManager is only allowed for applications that have specified the «bluetooth-central» background mode’
NSBluetoothAlwaysUsageDescription Allow App use bluetooth? NSBluetoothPeripheralUsageDescription Allow App use bluetooth? UIBackgroundModes bluetooth-central bluetooth-peripheral
you can join this QQ group, feedback your problem
About
a flutter plugin connect to bluetooth thermal printer support both Android and IOS (eg. Gprinter pt-380、gp-1324、gp-2120)
How to setup a Bluetooth thermal printer?
You can print receipts and orders using a Bluetooth thermal printer connected to your smartphone or tablet.
This tutorial does NOT cover usb, wifi or ethernet cable thermal printers.
Currently bluetooth print is only supported on Android devices. The Waiterio app for iPhone and iPads does not support bluetooth printing yet.
First of all you are going to need to pair your smartphone or tablet to the bluetooth thermal printer.
- Turn on your bluetooth thermal printer
- Open the Settings app on your smartphone or tablet
- Click on Bluetooth
- Turn ON the bluetooth
- Your smartphone/tablet will scan for nearby bluetooth devices
- Click on the name of your bluetooth thermal printer to start the Pairing
- Your bluetooth thermal printer should now be listed under Paired devices
The Waiterio app is going to need the MAC address of your bluetooth thermal printer. The MAC address of a bluetooth device should be in this format: 01:23:89:ab:cd:ef. On Android you can find the MAC address of your bluetooth device by installing the Bluetooth Address Finder app
C) Enter the MAC address in Waiterio
Once you know the MAC address of your bluetooth thermal printer you will need to enter it inside the Waiterio app.
- Open the Waiterio app and login
- Scroll right until you reach the PRINTING tab
- Click on one of existing printers or click on ADD PRINTER
- Click on the connection field and choose bluetooth
- Enter the MAC address in the MAC field in the following format 01:23:89:ab:cd:ef
- Click on Print Sample to print a test
How to connect Thermal Bluetooth Printer to iOS devices
I have this Thermal Bluetooth Printer Impress+. I am making a custom application which should print bills. I have written code to connect it to iPhone but it never shows up in the search. It never reaches didDiscoverPeripheral. I don’t know whats wrong. Below is my code for searching bluetooth devices. Please help. Any help will be highly appreciated.
import UIKit import CoreBluetooth class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDelegate < var centralManager: CBCentralManager! var peripheral: CBPeripheral! var writeCharacteristic: CBCharacteristic! var service: CBService! var characteristic: CBCharacteristic! var bluetoothAvailable = false let message = "1" @IBOutlet weak var labelDeviceName: UILabel! override func viewDidLoad() < super.viewDidLoad() centralManager = CBCentralManager(delegate: self, queue: nil) >func centralManagerDidUpdateState(_ central: CBCentralManager) < print("Checking state") switch (central.state) < case .poweredOff: print("CoreBluetooth BLE hardware is powered off") case .poweredOn: print("CoreBluetooth BLE hardware is powered on and ready") bluetoothAvailable = true; case .resetting: print("CoreBluetooth BLE hardware is resetting") case .unauthorized: print("CoreBluetooth BLE state is unauthorized") case .unknown: print("CoreBluetooth BLE state is unknown"); case .unsupported: print("CoreBluetooth BLE hardware is unsupported on this platform"); >if bluetoothAvailable == true < discoverDevices() >> private func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) < // Stop scanning self.centralManager.stopScan() print("Stopped Scanning") peripheral.discoverServices([CBUUID(string: "2220")]) print("CONNECTED!!") print("Device Name:",peripheral.name!) self.labelDeviceName.text = peripheral.name >func discoverDevices() < print("Discovering devices") centralManager.scanForPeripherals(withServices: nil, options: nil) >>
1 Answer 1
Short story: A bluetooth thermal printer can work with iOS only if it uses the Bluetooth 4.0 LE version or if the manufacturer registered in the Mfi Program.
Bluetooth LE 4.0 devices aren’t listed in the Settings => Bluetooth on iOS anyway.
If your bluetooth thermal printer has Bluetooth 4.0 LE you can adapt the official Apple sample code using Objective C sample code or in Swift sample code
Long story: iOS and macOS SDKs supports Bluetooth 4.0 LE devices with the Core Bluetooth framework and other Bluetooth versions devices with the External Accessory framework. The External Accessory framework requires that the manufacturer of the bluetooth thermal printer is registered in the Mfi Program. Only the major manufacturers like Epson, Star Micronics, Zebra, Bixolon are registered with Mfi Program.
If you buy a cheap bluetooth thermal printer online from a minor manufacturer it will only work with iOS if it uses Bluetooth 4.0 LE since it uses the Core Bluetooth framework which does not require any registration to the Mfi Program.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Working with thermal printer via bluetooth (Flutter)
License
kakzaki/blue_thermal_printer
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
A new Flutter plugin for connecting to thermal printer via bluetooth (Android Only), this plugin is still under development Note: Migrate your project to AndroidX
Add this to your package’s pubspec.yaml file:
dependencies: blue_thermal_printer: ^any
You can install packages from the command line:
Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:blue_thermal_printer/blue_thermal_printer.dart';
For detail demonstration please look at example folder
Note: make sure to upgrade your project to compileSdkVersion 31 or above
If you like my content, please consider buying me a coffee. Thank you for your support!
bagi yang dari Indonesia bisa lewat saweria berikut
About
Working with thermal printer via bluetooth (Flutter)