ios version - 1
parent
95aeb07fc8
commit
005c00071d
|
|
@ -114,6 +114,8 @@ class BluePrintService extends BaseService {
|
||||||
} else if (isIos) {
|
} else if (isIos) {
|
||||||
await _bluetoothDeviceIOS?.disconnect();
|
await _bluetoothDeviceIOS?.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print('disconnected');
|
||||||
response = true;
|
response = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error $e');
|
print('Error $e');
|
||||||
|
|
@ -124,16 +126,30 @@ class BluePrintService extends BaseService {
|
||||||
|
|
||||||
Future<bool> printBytes(Uint8List bytes,
|
Future<bool> printBytes(Uint8List bytes,
|
||||||
{int chunkSizeBytes = 20, int queueSleepTimeMs = 20}) async {
|
{int chunkSizeBytes = 20, int queueSleepTimeMs = 20}) async {
|
||||||
if (isAndroid) {
|
Map<String, dynamic> config = Map();
|
||||||
await _printAndroid(bytes, chunkSizeBytes, queueSleepTimeMs);
|
final len = bytes.length;
|
||||||
} else if (isIos) {
|
List<List<int>> chunks = [];
|
||||||
await _printIos(bytes);
|
for (var i = 0; i < len; i += chunkSizeBytes) {
|
||||||
|
var end = (i + chunkSizeBytes < len) ? i + chunkSizeBytes : len;
|
||||||
|
chunks.add(bytes.sublist(i, end));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < chunks.length; i += 1) {
|
||||||
|
if (isAndroid) {
|
||||||
|
await _printAndroid(chunks[i], config);
|
||||||
|
} else if (isIos) {
|
||||||
|
await _printIos(Uint8List.fromList(chunks[i]), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Future.delayed(Duration(milliseconds: queueSleepTimeMs));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _printIos(Uint8List bytes) async {
|
Future<void> _printIos(Uint8List bytes,Map<String, dynamic> config) async {
|
||||||
final List<flutter_blue.BluetoothService> bluetoothServices =
|
final List<flutter_blue.BluetoothService> bluetoothServices =
|
||||||
await _bluetoothDeviceIOS?.discoverServices() ??
|
await _bluetoothDeviceIOS?.discoverServices() ??
|
||||||
<flutter_blue.BluetoothService>[];
|
<flutter_blue.BluetoothService>[];
|
||||||
|
|
@ -149,18 +165,9 @@ class BluePrintService extends BaseService {
|
||||||
await characteristic.write(bytes, withoutResponse: true);
|
await characteristic.write(bytes, withoutResponse: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _printAndroid(Uint8List bytes, int chunkSizeBytes, int queueSleepTimeMs) async {
|
Future<void> _printAndroid(List<int> chunk ,Map<String, dynamic> config) async {
|
||||||
Map<String, dynamic> config = Map();
|
|
||||||
final len = bytes.length;
|
|
||||||
List<List<int>> chunks = [];
|
|
||||||
for (var i = 0; i < len; i += chunkSizeBytes) {
|
|
||||||
var end = (i + chunkSizeBytes < len) ? i + chunkSizeBytes : len;
|
|
||||||
chunks.add(bytes.sublist(i, end));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < chunks.length; i += 1) {
|
|
||||||
await _bluetoothAndr.rawBytes(config, chunks[i]);
|
await _bluetoothAndr.rawBytes(config, chunk);
|
||||||
await Future.delayed(Duration(milliseconds: queueSleepTimeMs));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,17 @@ class _ImageShowContainerState extends State<ImageShowContainer> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
disconnect();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void disconnect() async {
|
||||||
|
await printerManager.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
void _print() async {
|
void _print() async {
|
||||||
final SettingState state = Redux.store!.state.settingState!;
|
final SettingState state = Redux.store!.state.settingState!;
|
||||||
if (state.printerBT == null) {
|
if (state.printerBT == null) {
|
||||||
|
|
@ -107,7 +118,7 @@ class _ImageShowContainerState extends State<ImageShowContainer> {
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
await Future.delayed(Duration(seconds: 15));
|
await Future.delayed(Duration(seconds: 15));
|
||||||
await printerManager.disconnect();
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_printing = false;
|
_printing = false;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,15 @@ class _SettingPrinterViewState extends State<SettingPrinterView> {
|
||||||
super.initState();
|
super.initState();
|
||||||
_permission();
|
_permission();
|
||||||
}
|
}
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
disconnect();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect() async {
|
||||||
|
await printerManager.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
void _testPrint() async {
|
void _testPrint() async {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
@ -49,12 +58,11 @@ class _SettingPrinterViewState extends State<SettingPrinterView> {
|
||||||
try {
|
try {
|
||||||
final SettingState state = Redux.store!.state.settingState!;
|
final SettingState state = Redux.store!.state.settingState!;
|
||||||
printerManager.device = state.printerBT!;
|
printerManager.device = state.printerBT!;
|
||||||
bool isConnected = await printerManager.connect();
|
|
||||||
if(isConnected == false) {
|
await disconnect();
|
||||||
await Future.delayed(Duration(seconds: 3));
|
await Future.delayed(Duration(seconds: 1));
|
||||||
await printerManager.disconnect();
|
|
||||||
return;
|
await printerManager.connect();
|
||||||
}
|
|
||||||
await Future.delayed(Duration(seconds: 3));
|
await Future.delayed(Duration(seconds: 3));
|
||||||
bool isIos = Platform.isIOS;
|
bool isIos = Platform.isIOS;
|
||||||
int chunkSizeBytes = 3096;
|
int chunkSizeBytes = 3096;
|
||||||
|
|
@ -77,14 +85,14 @@ class _SettingPrinterViewState extends State<SettingPrinterView> {
|
||||||
Uint8List.fromList(await testTicketImage(paper)),
|
Uint8List.fromList(await testTicketImage(paper)),
|
||||||
chunkSizeBytes: chunkSizeBytes,
|
chunkSizeBytes: chunkSizeBytes,
|
||||||
queueSleepTimeMs: queueSleepTimeMs);
|
queueSleepTimeMs: queueSleepTimeMs);
|
||||||
_dialogService.showDialog(description: 'result is $res');
|
//_dialogService.showDialog(description: 'result is $res');
|
||||||
} else {
|
} else {
|
||||||
final bool res = await printerManager.printBytes(
|
final bool res = await printerManager.printBytes(
|
||||||
Uint8List.fromList(await printTextCheck(
|
Uint8List.fromList(await printTextCheck(
|
||||||
paper, state.printerEncoding!, exampleJson['check_text'])),
|
paper, state.printerEncoding!, exampleJson['check_text'])),
|
||||||
chunkSizeBytes: chunkSizeBytes,
|
chunkSizeBytes: chunkSizeBytes,
|
||||||
queueSleepTimeMs: queueSleepTimeMs);
|
queueSleepTimeMs: queueSleepTimeMs);
|
||||||
_dialogService.showDialog(description: 'result is $res');
|
//_dialogService.showDialog(description: 'result is $res');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ERROR');
|
print('ERROR');
|
||||||
|
|
@ -92,8 +100,7 @@ class _SettingPrinterViewState extends State<SettingPrinterView> {
|
||||||
}
|
}
|
||||||
//10 sec safe disconnect
|
//10 sec safe disconnect
|
||||||
await Future.delayed(Duration(seconds: 14));
|
await Future.delayed(Duration(seconds: 14));
|
||||||
await printerManager.disconnect();
|
|
||||||
await Future.delayed(Duration(seconds: 3));
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_printing = false;
|
_printing = false;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue