-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
打印安卓二维码浓度低,无法使用和连接异常和断开连接异常的问题 #45
Comments
对于判断是否成功连接的代码补充。通过查看源码发现:如果根据PrinterReader中的 readDataImmediately(buffer) 如果返回结果值不为-1似乎就可以判断为已经连接蓝牙打印机设备。
` |
非常感谢,你可以推送下你的修改,我合并进去 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我的蓝牙打印机在打印QRCODE(二维码)中安卓打印的清晰度太低,导致无法正常使用,后来在printContext中把打印浓度的枚举类从7(好像是7)改成了15,之后可以安卓打印二维码就可以非常清晰了。但是现在存在以下问题:
1:无法判断当前蓝牙设备是否已经正常连接,判断结果往往是错的bluetoothPrint.isConnected和bluetoothPrint.state.listen监听的结果汪汪是错的。
2:bluetoothPrint.connect(device)方法中,往往device不是null反而会出现NullException。
3:bluetoothPrint.disconnect()这个方法经常使用时会导致应用直接崩溃掉(闪退)
`import 'package:bluetooth_print/bluetooth_print.dart';
import 'package:bluetooth_print/bluetooth_print_model.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:guards/bean/BlueJurisdiction.dart';
import 'package:guards/utils/interface/BluetoothFactory.dart';
/// @description BluetoothFactoryImpl
/// @author Activation
/// @Date 2021/1/26 11:14
class BluetoothFactoryImpl implements BluetoothFactory {
BluetoothPrint bluetoothPrint = BluetoothPrint.instance;
bool isConnFlag = false;
@OverRide
Future disconnect() async {
await bluetoothPrint.stopScan();
await bluetoothPrint.disconnect();
await bluetoothPrint.destroy();
}
@OverRide
Future checkBluetoothAccess() async {
bool openFlag = await bluetoothPrint.isOn;
}
@OverRide
Future joinBluetooth() async {
EasyLoading.show(status: "连接蓝牙中。。");
try {
await bluetoothPrint.startScan(timeout: Duration(seconds: 4));
Stream<List> tempStream = bluetoothPrint.scanResults;
print(tempStream);
bool tempFlag = false;
//执行自动连接
tempStream.listen((event) async {
for (BluetoothDevice device in event) {
if (device.name.startsWith(r"Printer_")) {
tempFlag = true;
if (tempFlag && device != null) {
// await bluetoothPrint.disconnect();
print("这里是连接的设备信息$device");
await bluetoothPrint.connect(device);
await bluetoothPrint.stopScan();
}
}
}
});
await bluetoothPrint.isConnected.then((value) {
print("这里是对应的当前值是否已经连接的返回值$value");
});
bluetoothPrint.state.listen((state) {
print("这里是正在监听值的变化$state");
switch (state) {
case BluetoothPrint.CONNECTED:
print("蓝牙已经连接了");
isConnFlag = true;
break;
case BluetoothPrint.DISCONNECTED:
isConnFlag = false;
print("蓝牙还没有连接");
break;
default:
break;
}
});
} catch (e) {
print("这里是对应的异常信息");
print("${e.runtimeType}${e.toString()}");
} finally {
EasyLoading.dismiss();
}
}
@OverRide
Future executePrint(List tempLists) async {
print("这里已经执行了$isConnFlag");
if (isConnFlag) {
await bluetoothPrint.printLabel(config, tempLists);
} else {
throw Exception("当前设备未连接,请关闭蓝牙之后再重试");
// await joinBluetooth().then((value) {
// bluetoothPrint.printLabel(config, tempLists);
// });
}
}
@OverRide
Map<String, dynamic> config = {'width': 300, 'height': 220, 'gap': 30};
}
`
然后我希望您能联系我,我可以协助您完善这个组件,因为我也需要使用这个组件,并且希望他可以成熟。
我的打印机型号为:GP-M322
我的QQ:1067252205
还有楼主的群号重新发下吧。。。。。 我也想进群交流讨论
The text was updated successfully, but these errors were encountered: