bluetooth_print_plugin

Creator: coderz1093

Last updated:

0 purchases

bluetooth_print_plugin Image
bluetooth_print_plugin Images

Languages

Categories

Add to Cart

Description:

bluetooth print plugin

Introduction #
BluetoothPrintPlugin 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.)
Underway(please suggest) #
[ ] print x,y positions
[ ] set paper size
[ ] more print examples
verison #
0.1.0(flutter 3.x)
Features #




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



Usage #
dart)
To use this plugin : #

add the dependency to your pubspec.yaml file.

dependencies:
flutter:
sdk: flutter
flutter_bluetooth_print_plugin:
copied to clipboard
Add permissions for Bluetooth #
We need to add the permission to use Bluetooth and access location:
Android
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
copied to clipboard
IOS
In the ios/Runner/Info.plist let’s add:
<dict>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Need BLE permission</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Need BLE permission</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
copied to clipboard
For location permissions on iOS see more at: https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services
init a BluetoothPrint instance #
import 'package:flutter_bluetooth_print_plugin/flutter_bluetooth_print.dart';
import 'package:flutter_bluetooth_print_plugin/model/bluetooth_model.dart';


FlutterBluetoothPrint bluetoothPrint = FlutterBluetoothPrint.instance;
copied to clipboard
scan #
// begin scan
bluetoothPrint.startScan(timeout: Duration(seconds: 4));

// get devices
StreamBuilder<List<BluetoothDevice>>(
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(),
),
),
copied to clipboard
connect #
await bluetoothPrint.connect(_device);
copied to clipboard
disconnect #
await bluetoothPrint.disconnect();
copied to clipboard
listen state #
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;
}
});
copied to clipboard
A new flutter plugin project.
print (esc command, receipt mode) #
Map<String, dynamic> config = Map();
List<LineText> 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");
List<int> 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);
copied to clipboard
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) #
Map<String, dynamic> config = Map();
config['width'] = 40; // 标签宽度,单位mm
config['height'] = 70; // 标签高度,单位mm
config['gap'] = 2; // 标签间隔,单位mm

// x、y坐标位置,单位dpi,1mm=8dpi
List<LineText> 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'));

List<LineText> list1 = List();
ByteData data = await rootBundle.load("assets/images/guide3.png");
List<int> 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);
copied to clipboard
Troubleshooting #
ios import third party library
[Please Read link: https://stackoverflow.com/questions/19189463/cocoapods-podspec-issue)
*.podspec add:
# .a filename must begin with lib, eg. 'libXXX.a'
s.vendored_libraries = '**/*.a'
copied to clipboard
error:'State restoration of CBCentralManager is only allowed for applications that have specified the "bluetooth-central" background mode'
info.plist add:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Allow App use bluetooth?</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Allow App use bluetooth?</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
copied to clipboard
FAQ Support #
Thanks For #

bluetooth_print

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.