bluetooth_print
bluetooth_print copied to clipboard
I can't print (Knup 1022)
Is something wrong with my code? I am trying to print using this function and an error is occurring, leave the logcat below.
void connectDevice(BuildContext context,
{void Function(BluetoothPrint) connected}) {
_bluetooth.state.listen((state) {
if (state == BluetoothPrint.CONNECTED) {
_bluetooth.printReceipt(Map(), [
LineText(
type: LineText.TYPE_TEXT,
size: 12,
content: 'Ola mundo',
align: LineText.ALIGN_CENTER,
linefeed: 1)
]);
}
});
showDialog(
context: context,
barrierDismissible: false,
builder: (_) {
return AlertDialog(
title: Text('Encontar dispositivos'),
content: StreamBuilder<bool>(
key: UniqueKey(),
initialData: false,
stream: _bluetooth.isScanning,
builder: (_, status) {
return Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
StreamBuilder<List<BluetoothDevice>>(
key: UniqueKey(),
initialData: [],
stream: _bluetooth.scanResults,
builder: (_, results) {
return results.data.length == 0 && status.data
? Expanded(
child: Center(
child: CircularProgressIndicator(),
),
)
: ListView(
key: UniqueKey(),
shrinkWrap: true,
children: results.data
.map(
(device) => ListTile(
key: UniqueKey(),
enabled: status.data ? false : true,
title: Text('${device.name}'),
subtitle: Text('${device.address}'),
onTap: () {
_bluetooth.connect(device);
},
),
)
.toList(),
);
},
),
FlatButton(
onPressed: () => status.data
? _bluetooth.stopScan()
: _bluetooth.startScan(),
child: Text(status.data
? 'ENCERRAR BUSCA'
: 'BUSCAR DISPOSITIOVOS'),
)
],
);
},
),
);
},
);
}
2020-01-17 16:54:30.657 24773-24925/juniojsv.bem_servir_comanda W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
2020-01-17 16:54:33.617 24773-24773/juniojsv.bem_servir_comanda D/BluetoothPrintPlugin: stateStreamHandler, current action: android.bluetooth.device.action.ACL_CONNECTED
2020-01-17 16:54:33.632 24773-24789/juniojsv.bem_servir_comanda E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(not connect, state not right, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
#2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3 BluetoothPrint.printReceipt (package:bluetooth_print/bluetooth_print.dart:141:14)
#4 AppModel.connectDevice.<anonymous closure> (package:bem_servir_comanda/models/app_model.dart:20:20)
#5 _rootRunUnary (dart:async/zone.dart:1134:38)
#6 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#9 _DelayedData.perform (dart:async/stream_impl.dart:594:14)
#10 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:710:11)
#11 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:670:7)
#12 _rootRun (dart:async/zone.dart:1122:38)
#13 _CustomZone.run (dart:async/zone.dart:1023:19)
#14 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#15 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
#16 _rootRun (dart:async/zone.dart:1126:13)
#17 _CustomZone.run (dart:async/zone.dart:1023:19)
#18 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
#19 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
#20 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
2020-01-17 16:54:33.820 24773-24960/juniojsv.bem_servir_comanda E/DeviceConnFactoryManager: wait read
2020-01-17 16:54:35.573 24773-24960/juniojsv.bem_servir_comanda E/BluetoothPort: read length1
2020-01-17 16:54:35.573 24773-24960/juniojsv.bem_servir_comanda E/DeviceConnFactoryManager: read 1
2020-01-17 16:54:35.575 24773-24960/juniojsv.bem_servir_comanda E/DeviceConnFactoryManager: wait read
@JunioJsv please gei me your device type, and anroid version, i'll have a try
Device modal: tsc alpha-3r bluetooth printer => printing not work
@JunioJsv please gei me your device type, and anroid version, i'll have a try
it is working on xprinter xp-420b?