migrate ns-printer
parent
f29d9edb22
commit
988d6a6c6b
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
|
|
||||||
import 'package:aman_kassa_flutter/core/services/DataService.dart';
|
import 'package:aman_kassa_flutter/core/services/DataService.dart';
|
||||||
|
import 'package:aman_kassa_flutter/core/services/blue_print_service.dart';
|
||||||
|
|
||||||
import '../core/services/DbService.dart';
|
import '../core/services/DbService.dart';
|
||||||
|
|
||||||
|
|
@ -25,6 +26,8 @@ class LocatorInjector {
|
||||||
locator.registerLazySingleton<DialogService>(() => DialogService());
|
locator.registerLazySingleton<DialogService>(() => DialogService());
|
||||||
_log.d('Initializing DbService Service');
|
_log.d('Initializing DbService Service');
|
||||||
locator.registerLazySingleton<DbService>(() => DbService.instance);
|
locator.registerLazySingleton<DbService>(() => DbService.instance);
|
||||||
|
_log.d('Initializing BluePrintService Service');
|
||||||
|
locator.registerLazySingleton<BluePrintService>(() => BluePrintService());
|
||||||
|
|
||||||
|
|
||||||
// depencies
|
// depencies
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:aman_kassa_flutter/core/base/base_service.dart';
|
||||||
|
import 'package:bluetooth_print/bluetooth_print.dart';
|
||||||
|
import 'package:bluetooth_print/bluetooth_print_model.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BluePrintService extends BaseService {
|
||||||
|
BluetoothPrint _bluetooth = BluetoothPrint.instance;
|
||||||
|
BluetoothDevice? _device;
|
||||||
|
|
||||||
|
Future<void> scan() async {
|
||||||
|
await _bluetooth.startScan(timeout: Duration(seconds: 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> stopScan() async {
|
||||||
|
await _bluetooth.stopScan();
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<List<BluetoothDevice>> get scanResult => _bluetooth.scanResults;
|
||||||
|
|
||||||
|
|
||||||
|
Stream<bool> get isScanning => _bluetooth.isScanning;
|
||||||
|
Stream<int> get state => _bluetooth.state;
|
||||||
|
set device(BluetoothDevice device) => _device = device;
|
||||||
|
|
||||||
|
|
||||||
|
Future<bool> connect() async {
|
||||||
|
bool response = false;
|
||||||
|
if (_device == null) {
|
||||||
|
response = false;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
await _bluetooth.connect(_device!);
|
||||||
|
await Future.delayed(Duration(seconds: 2));
|
||||||
|
response = true;
|
||||||
|
} catch (e) {
|
||||||
|
print('Error connect $e');
|
||||||
|
response = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> disconnect() async {
|
||||||
|
bool response = false;
|
||||||
|
try {
|
||||||
|
await _bluetooth.disconnect();
|
||||||
|
response = true;
|
||||||
|
} catch (e) {
|
||||||
|
print('Error $e');
|
||||||
|
response = false;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> printBytes(Uint8List bytes) async {
|
||||||
|
Map<String, dynamic> config = Map();
|
||||||
|
return await _bluetooth.rawBytes(config, bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
|
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/state/setting_state.dart';
|
import 'package:aman_kassa_flutter/redux/state/setting_state.dart';
|
||||||
|
import 'package:bluetooth_print/bluetooth_print_model.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:redux_thunk/redux_thunk.dart';
|
import 'package:redux_thunk/redux_thunk.dart';
|
||||||
import 'package:flutter_bluetooth_basic/src/bluetooth_device.dart';
|
|
||||||
import '../store.dart';
|
import '../store.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
|
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
|
||||||
|
import 'package:bluetooth_print/bluetooth_print_model.dart';
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:flutter_bluetooth_basic/src/bluetooth_device.dart';
|
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class SettingState {
|
class SettingState {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'package:aman_kassa_flutter/core/locator.dart';
|
import 'package:aman_kassa_flutter/core/locator.dart';
|
||||||
import 'package:aman_kassa_flutter/core/models/check_image_modal.dart';
|
import 'package:aman_kassa_flutter/core/models/check_image_modal.dart';
|
||||||
import 'package:aman_kassa_flutter/core/models/dialog_models.dart';
|
import 'package:aman_kassa_flutter/core/models/dialog_models.dart';
|
||||||
import 'package:aman_kassa_flutter/core/route_names.dart';
|
import 'package:aman_kassa_flutter/core/route_names.dart';
|
||||||
|
import 'package:aman_kassa_flutter/core/services/blue_print_service.dart';
|
||||||
import 'package:aman_kassa_flutter/core/services/dialog_service.dart';
|
import 'package:aman_kassa_flutter/core/services/dialog_service.dart';
|
||||||
import 'package:aman_kassa_flutter/core/services/navigator_service.dart';
|
import 'package:aman_kassa_flutter/core/services/navigator_service.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
|
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
|
||||||
|
|
@ -13,11 +15,10 @@ import 'package:aman_kassa_flutter/shared/app_colors.dart';
|
||||||
import 'package:aman_kassa_flutter/shared/ui_helpers.dart';
|
import 'package:aman_kassa_flutter/shared/ui_helpers.dart';
|
||||||
import 'package:aman_kassa_flutter/views/settings/printer/PrinterTest.dart';
|
import 'package:aman_kassa_flutter/views/settings/printer/PrinterTest.dart';
|
||||||
import 'package:aman_kassa_flutter/widgets/fields/busy_button_icon.dart';
|
import 'package:aman_kassa_flutter/widgets/fields/busy_button_icon.dart';
|
||||||
import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
|
import 'package:bluetooth_print/bluetooth_print_model.dart';
|
||||||
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart';
|
|
||||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||||
import 'package:vocsy_esys_flutter_share/vocsy_esys_flutter_share.dart';
|
import 'package:vocsy_esys_flutter_share/vocsy_esys_flutter_share.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
@ -32,11 +33,10 @@ class ImageShowContainer extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ImageShowContainerState extends State<ImageShowContainer> {
|
class _ImageShowContainerState extends State<ImageShowContainer> {
|
||||||
final PrinterBluetoothManager printerManager = PrinterBluetoothManager();
|
final BluePrintService printerManager = locator<BluePrintService>();
|
||||||
final DialogService _dialogService = locator<DialogService>();
|
final DialogService _dialogService = locator<DialogService>();
|
||||||
final BluetoothDevice? printerBtDevice =
|
final BluetoothDevice? printerBtDevice =
|
||||||
Redux.store!.state.settingState!.printerBT;
|
Redux.store!.state.settingState!.printerBT;
|
||||||
final BluetoothManager bluetoothManager = BluetoothManager.instance;
|
|
||||||
|
|
||||||
bool _printing = false;
|
bool _printing = false;
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ class _ImageShowContainerState extends State<ImageShowContainer> {
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
_print();
|
_print();
|
||||||
} else {
|
} else {
|
||||||
bluetoothManager.state.listen((val) {
|
printerManager.state.listen((val) {
|
||||||
print("state = $val");
|
print("state = $val");
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
if (val == 12) {
|
if (val == 12) {
|
||||||
|
|
@ -82,32 +82,32 @@ class _ImageShowContainerState extends State<ImageShowContainer> {
|
||||||
_printing = true;
|
_printing = true;
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
printerManager.selectPrinter(PrinterBluetooth(state.printerBT!));
|
printerManager.device = state.printerBT!;
|
||||||
|
await printerManager.connect();
|
||||||
PaperSize paper = state.printerPaperSize == SettingPrinterPaperM80
|
PaperSize paper = state.printerPaperSize == SettingPrinterPaperM80
|
||||||
? PaperSize.mm80
|
? PaperSize.mm80
|
||||||
: PaperSize.mm58;
|
: PaperSize.mm58;
|
||||||
if (SettingPrinterEncodingImage == state.printerEncoding) {
|
if (SettingPrinterEncodingImage == state.printerEncoding) {
|
||||||
final PosPrintResult res = await printerManager.printTicket(
|
final bool res = await printerManager.printBytes(
|
||||||
await printImageCheck(paper, widget.showModel.data!.base64Data!),
|
Uint8List.fromList(await printImageCheck(paper, widget.showModel.data!.base64Data!)));
|
||||||
chunkSizeBytes: chunkSizeBytes,
|
if (!res) {
|
||||||
queueSleepTimeMs: queueSleepTimeMs);
|
_dialogService.showDialog(description: 'Ошибка при печати');
|
||||||
if (res.value != 1) {
|
|
||||||
_dialogService.showDialog(description: res.msg);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final PosPrintResult res = await printerManager.printTicket(
|
final bool res = await printerManager.printBytes(
|
||||||
await printTextCheck(paper, state.printerEncoding!,
|
Uint8List.fromList(await printTextCheck(paper, state.printerEncoding!,
|
||||||
jsonDecode(widget.showModel.data!.textData!)),
|
jsonDecode(widget.showModel.data!.textData!)))
|
||||||
chunkSizeBytes: chunkSizeBytes,
|
);
|
||||||
queueSleepTimeMs: queueSleepTimeMs);
|
if (!res) {
|
||||||
if (res.value != 1) {
|
_dialogService.showDialog(description: 'Ошибка при печати');
|
||||||
_dialogService.showDialog(description: res.msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
await Future.delayed(Duration(seconds: 7));
|
await Future.delayed(Duration(seconds: 15));
|
||||||
|
await printerManager.disconnect();
|
||||||
setState(() {
|
setState(() {
|
||||||
_printing = false;
|
_printing = false;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,13 @@
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'dart:ui' as ui;
|
|
||||||
|
|
||||||
import 'package:aman_kassa_flutter/core/logger.dart';
|
import 'package:aman_kassa_flutter/core/logger.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart';
|
import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/store.dart';
|
import 'package:aman_kassa_flutter/redux/store.dart';
|
||||||
|
|
||||||
import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
|
|
||||||
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart' hide Image;
|
import 'package:flutter/material.dart' hide Image;
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
|
|
||||||
import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
|
|
||||||
import '../data/settings_envi.dart';
|
import '../data/settings_envi.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,11 @@
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'dart:ui' as ui;
|
|
||||||
|
|
||||||
import 'package:aman_kassa_flutter/core/logger.dart';
|
import 'package:aman_kassa_flutter/core/logger.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart';
|
import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/store.dart';
|
import 'package:aman_kassa_flutter/redux/store.dart';
|
||||||
|
|
||||||
import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
|
|
||||||
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart' hide Image;
|
import 'package:flutter/material.dart' hide Image;
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
|
|
||||||
import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
|
|
||||||
import '../data/settings_envi.dart';
|
import '../data/settings_envi.dart';
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,16 @@
|
||||||
import 'dart:async';
|
import 'package:aman_kassa_flutter/core/locator.dart';
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'dart:ui' as ui;
|
|
||||||
|
|
||||||
import 'package:aman_kassa_flutter/core/logger.dart';
|
import 'package:aman_kassa_flutter/core/logger.dart';
|
||||||
|
import 'package:aman_kassa_flutter/core/services/blue_print_service.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart';
|
import 'package:aman_kassa_flutter/redux/actions/setting_actions.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/store.dart';
|
import 'package:aman_kassa_flutter/redux/store.dart';
|
||||||
|
import 'package:bluetooth_print/bluetooth_print_model.dart';
|
||||||
|
|
||||||
import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
|
|
||||||
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart' hide Image;
|
import 'package:flutter/material.dart' hide Image;
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
|
|
||||||
import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
|
|
||||||
import '../PrinterTest.dart';
|
|
||||||
|
|
||||||
|
|
||||||
class PrinterSelectView extends StatefulWidget {
|
class PrinterSelectView extends StatefulWidget {
|
||||||
PrinterSelectView({Key? key, this.title}) : super(key: key);
|
PrinterSelectView({Key? key, this.title}) : super(key: key);
|
||||||
final String? title;
|
final String? title;
|
||||||
|
|
@ -30,16 +21,14 @@ class PrinterSelectView extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PrinterSelectViewState extends State<PrinterSelectView> {
|
class _PrinterSelectViewState extends State<PrinterSelectView> {
|
||||||
PrinterBluetoothManager printerManager = PrinterBluetoothManager();
|
BluePrintService printerManager = locator<BluePrintService>();
|
||||||
List<PrinterBluetooth> _devices = [];
|
List<BluetoothDevice> _devices = [];
|
||||||
Logger _logger = getLogger('PrinterSelectView');
|
Logger _logger = getLogger('PrinterSelectView');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
printerManager.scanResult.listen((devices) async {
|
||||||
printerManager.scanResults.listen((devices) async {
|
|
||||||
// print('UI: Devices found ${devices.length}');
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_devices = devices;
|
_devices = devices;
|
||||||
});
|
});
|
||||||
|
|
@ -51,15 +40,15 @@ class _PrinterSelectViewState extends State<PrinterSelectView> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_devices = [];
|
_devices = [];
|
||||||
});
|
});
|
||||||
printerManager.startScan(Duration(seconds: 4));
|
printerManager.scan();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _stopScanDevices() {
|
void _stopScanDevices() {
|
||||||
printerManager.stopScan();
|
printerManager.stopScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _selectPrinter(PrinterBluetooth printer, BuildContext context, ) async {
|
void _selectPrinter(BluetoothDevice printer, BuildContext context, ) async {
|
||||||
printerManager.selectPrinter(printer);
|
printerManager.device = printer;
|
||||||
_logger.i(printer.name);
|
_logger.i(printer.name);
|
||||||
_logger.i(printer.address);
|
_logger.i(printer.address);
|
||||||
|
|
||||||
|
|
@ -71,27 +60,6 @@ class _PrinterSelectViewState extends State<PrinterSelectView> {
|
||||||
await Redux.store!.dispatch(selectPrinterFromSetting(device));
|
await Redux.store!.dispatch(selectPrinterFromSetting(device));
|
||||||
Navigator.of(context).pop(false);
|
Navigator.of(context).pop(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _testPrint(PrinterBluetooth printer) async {
|
|
||||||
printerManager.selectPrinter(printer);
|
|
||||||
|
|
||||||
// TODO Don't forget to choose printer's paper
|
|
||||||
const PaperSize paper = PaperSize.mm58;
|
|
||||||
|
|
||||||
// TEST PRINT
|
|
||||||
// final PosPrintResult res =
|
|
||||||
// await printerManager.printTicket(await testTicket(paper), queueSleepTimeMs: 50);
|
|
||||||
|
|
||||||
final PosPrintResult res =
|
|
||||||
await printerManager.printTicket(
|
|
||||||
await testTicketImage(paper),
|
|
||||||
chunkSizeBytes: 1024,
|
|
||||||
queueSleepTimeMs: 50
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
final key = GlobalKey();
|
final key = GlobalKey();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -140,7 +108,7 @@ class _PrinterSelectViewState extends State<PrinterSelectView> {
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
floatingActionButton: StreamBuilder<bool>(
|
floatingActionButton: StreamBuilder<bool>(
|
||||||
stream: printerManager.isScanningStream,
|
stream: printerManager.isScanning,
|
||||||
initialData: false,
|
initialData: false,
|
||||||
builder: (c, snapshot) {
|
builder: (c, snapshot) {
|
||||||
if (snapshot.data != null) {
|
if (snapshot.data != null) {
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ import 'dart:io';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:aman_kassa_flutter/core/models/dialog_models.dart';
|
import 'package:aman_kassa_flutter/core/models/dialog_models.dart';
|
||||||
|
import 'package:aman_kassa_flutter/core/services/blue_print_service.dart';
|
||||||
import 'package:aman_kassa_flutter/widgets/fields/busy_button_icon.dart';
|
import 'package:aman_kassa_flutter/widgets/fields/busy_button_icon.dart';
|
||||||
import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart';
|
|
||||||
import 'package:aman_kassa_flutter/core/locator.dart';
|
import 'package:aman_kassa_flutter/core/locator.dart';
|
||||||
import 'package:aman_kassa_flutter/core/logger.dart';
|
import 'package:aman_kassa_flutter/core/logger.dart';
|
||||||
import 'package:aman_kassa_flutter/core/route_names.dart';
|
import 'package:aman_kassa_flutter/core/route_names.dart';
|
||||||
|
|
@ -12,9 +12,6 @@ import 'package:aman_kassa_flutter/core/services/navigator_service.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
|
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/state/setting_state.dart';
|
import 'package:aman_kassa_flutter/redux/state/setting_state.dart';
|
||||||
import 'package:aman_kassa_flutter/redux/store.dart';
|
import 'package:aman_kassa_flutter/redux/store.dart';
|
||||||
import 'package:aman_kassa_flutter/shared/app_colors.dart';
|
|
||||||
import 'package:aman_kassa_flutter/widgets/fields/aman_icon_button_horizontal.dart';
|
|
||||||
import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
|
|
||||||
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
@ -34,8 +31,7 @@ class SettingPrinterView extends StatefulWidget {
|
||||||
class _SettingPrinterViewState extends State<SettingPrinterView> {
|
class _SettingPrinterViewState extends State<SettingPrinterView> {
|
||||||
NavigatorService _navigatorService = locator<NavigatorService>();
|
NavigatorService _navigatorService = locator<NavigatorService>();
|
||||||
final DialogService _dialogService = locator<DialogService>();
|
final DialogService _dialogService = locator<DialogService>();
|
||||||
final PrinterBluetoothManager printerManager = PrinterBluetoothManager();
|
final BluePrintService printerManager = locator<BluePrintService>();
|
||||||
final BluetoothManager bluetoothManager = BluetoothManager.instance;
|
|
||||||
final Logger log = getLogger('SettingPrinterView');
|
final Logger log = getLogger('SettingPrinterView');
|
||||||
|
|
||||||
bool _printing = false;
|
bool _printing = false;
|
||||||
|
|
@ -54,7 +50,8 @@ class _SettingPrinterViewState extends State<SettingPrinterView> {
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
final SettingState state = Redux.store!.state.settingState!;
|
final SettingState state = Redux.store!.state.settingState!;
|
||||||
printerManager.selectPrinter(PrinterBluetooth(state.printerBT!));
|
printerManager.device = state.printerBT!;
|
||||||
|
await printerManager.connect();
|
||||||
bool isIos = Platform.isIOS;
|
bool isIos = Platform.isIOS;
|
||||||
int chunkSizeBytes = 3096;
|
int chunkSizeBytes = 3096;
|
||||||
int queueSleepTimeMs = 100;
|
int queueSleepTimeMs = 100;
|
||||||
|
|
@ -67,31 +64,29 @@ class _SettingPrinterViewState extends State<SettingPrinterView> {
|
||||||
log.i(chunkSizeBytes);
|
log.i(chunkSizeBytes);
|
||||||
log.i(queueSleepTimeMs);
|
log.i(queueSleepTimeMs);
|
||||||
|
|
||||||
|
|
||||||
// TODO Don't forget to choose printer's paper
|
// TODO Don't forget to choose printer's paper
|
||||||
PaperSize paper = state.printerPaperSize == SettingPrinterPaperM80 ? PaperSize.mm80 : PaperSize.mm58;
|
PaperSize paper = state.printerPaperSize == SettingPrinterPaperM80 ? PaperSize.mm80 : PaperSize.mm58;
|
||||||
if (SettingPrinterEncodingImage == state.printerEncoding) {
|
if (SettingPrinterEncodingImage == state.printerEncoding) {
|
||||||
final PosPrintResult res = await printerManager.printTicket(
|
final bool res = await printerManager.printBytes(
|
||||||
await testTicketImage(paper),
|
Uint8List.fromList(await testTicketImage(paper)
|
||||||
chunkSizeBytes: chunkSizeBytes,
|
));
|
||||||
queueSleepTimeMs: queueSleepTimeMs
|
_dialogService.showDialog(description: 'result is $res');
|
||||||
);
|
|
||||||
_dialogService.showDialog(description: res.msg);
|
|
||||||
} else {
|
} else {
|
||||||
final PosPrintResult res = await printerManager.printTicket(
|
final bool res = await printerManager.printBytes(
|
||||||
await printTextCheck(paper, state.printerEncoding!, exampleJson['check_text']),
|
Uint8List.fromList(await printTextCheck(paper, state.printerEncoding!, exampleJson['check_text']))
|
||||||
chunkSizeBytes: chunkSizeBytes,
|
|
||||||
queueSleepTimeMs: queueSleepTimeMs
|
|
||||||
);
|
);
|
||||||
_dialogService.showDialog(description: res.msg);
|
_dialogService.showDialog(description: 'result is $res');
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('ERROR');
|
print('ERROR');
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//7 sec safe disconnect
|
//7 sec safe disconnect
|
||||||
await Future.delayed(Duration(seconds: 7));
|
await Future.delayed(Duration(seconds: 15));
|
||||||
|
await printerManager.disconnect();
|
||||||
setState(() {
|
setState(() {
|
||||||
_printing = false;
|
_printing = false;
|
||||||
});
|
});
|
||||||
|
|
@ -194,7 +189,7 @@ class _SettingPrinterViewState extends State<SettingPrinterView> {
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
_testPrint();
|
_testPrint();
|
||||||
} else {
|
} else {
|
||||||
bluetoothManager.state.listen((val) {
|
printerManager.state.listen((val) {
|
||||||
print("state = $val");
|
print("state = $val");
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
if (val == 12) {
|
if (val == 12) {
|
||||||
|
|
|
||||||
23
pubspec.lock
23
pubspec.lock
|
|
@ -29,6 +29,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.2.0"
|
version: "4.2.0"
|
||||||
|
bluetooth_print:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: "../bluetooth_print"
|
||||||
|
relative: true
|
||||||
|
source: path
|
||||||
|
version: "3.0.1"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -113,13 +120,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.3"
|
version: "2.0.3"
|
||||||
esc_pos_bluetooth:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: esc_pos_bluetooth
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "0.4.1"
|
|
||||||
esc_pos_utils:
|
esc_pos_utils:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -160,13 +160,6 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
flutter_bluetooth_basic:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: flutter_bluetooth_basic
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "0.1.7"
|
|
||||||
flutter_lock_screen:
|
flutter_lock_screen:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -498,7 +491,7 @@ packages:
|
||||||
name: rxdart
|
name: rxdart
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.26.0"
|
version: "0.27.3"
|
||||||
shared_preferences:
|
shared_preferences:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,12 @@ dependencies:
|
||||||
shared_preferences: ^2.0.12
|
shared_preferences: ^2.0.12
|
||||||
flutter_lock_screen: ^2.0.1
|
flutter_lock_screen: ^2.0.1
|
||||||
local_auth: ^1.1.10
|
local_auth: ^1.1.10
|
||||||
esc_pos_bluetooth: ^0.4.1
|
#esc_pos_bluetooth: ^0.4.1
|
||||||
esc_pos_utils: ^1.1.0 # no edit for esc_pos_bluetooth: ^0.2.8
|
esc_pos_utils: ^1.1.0
|
||||||
charset_converter: ^2.0.0
|
charset_converter: ^2.0.0
|
||||||
permission_handler: ^8.3.0
|
permission_handler: ^8.3.0
|
||||||
|
bluetooth_print:
|
||||||
|
path: ../bluetooth_print
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue