131 lines
5.0 KiB
Dart
131 lines
5.0 KiB
Dart
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:aman_kassa_flutter/core/locator.dart';
|
|
import 'package:aman_kassa_flutter/core/route_names.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/redux/constants/setting_const.dart';
|
|
import 'package:aman_kassa_flutter/redux/state/setting_state.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:flutter/material.dart';
|
|
import 'package:aman_kassa_flutter/views/settings/printer/PrinterTest.dart';
|
|
import 'package:flutter_redux/flutter_redux.dart';
|
|
|
|
import 'component/setting_item.dart';
|
|
import './printer/data/settings_envi.dart';
|
|
import './printer/example/check_test.dart';
|
|
|
|
class SettingPrinterView extends StatefulWidget {
|
|
@override
|
|
_SettingPrinterViewState createState() => _SettingPrinterViewState();
|
|
}
|
|
|
|
class _SettingPrinterViewState extends State<SettingPrinterView> {
|
|
NavigatorService _navigatorService = locator<NavigatorService>();
|
|
final DialogService _dialogService = locator<DialogService>();
|
|
PrinterBluetoothManager printerManager = PrinterBluetoothManager();
|
|
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
|
|
void _testPrint() async {
|
|
final SettingState state = Redux.store.state.settingState;
|
|
printerManager.selectPrinter(PrinterBluetooth(state.printerBT));
|
|
bool isIos = Platform.isIOS;
|
|
int chunkSizeBytes = 3096;
|
|
int queueSleepTimeMs = 50;
|
|
|
|
if(isIos) {
|
|
chunkSizeBytes = 75;
|
|
queueSleepTimeMs = 10;
|
|
}
|
|
// TODO Don't forget to choose printer's paper
|
|
PaperSize paper = state.printerPaperSize == SettingPrinterPaperM80 ? PaperSize.mm80 : PaperSize.mm58;
|
|
if(SettingPrinterEncodingImage == state.printerEncoding) {
|
|
final PosPrintResult res = await printerManager.printTicket(
|
|
await testTicketImage(paper),
|
|
chunkSizeBytes: chunkSizeBytes,
|
|
queueSleepTimeMs: queueSleepTimeMs
|
|
);
|
|
_dialogService.showDialog(description: res.msg);
|
|
} else {
|
|
final PosPrintResult res = await printerManager.printTicket(
|
|
await printTextCheck(paper, state.printerEncoding, exampleJson['check_text']),
|
|
chunkSizeBytes: chunkSizeBytes,
|
|
queueSleepTimeMs: queueSleepTimeMs
|
|
);
|
|
_dialogService.showDialog(description: res.msg);
|
|
}
|
|
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('Настройка принтера'),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
child: StoreConnector<AppState, SettingState>(
|
|
converter: (store) => store.state.settingState,
|
|
builder: (context, vm) {
|
|
return Column(
|
|
children: [
|
|
SettingItem(
|
|
title: 'Принтер',
|
|
name: vm.printerBT?.name,
|
|
value: vm.printerBT != null
|
|
? 'BT: ${vm.printerBT.address} '
|
|
: 'не выбран',
|
|
onTap: () {
|
|
_navigatorService.push(SettingsPrinterBTRoute);
|
|
}),
|
|
SettingItem(
|
|
title: 'Кодировка',
|
|
name: vm.printerEncoding != null ? encoding[vm.printerEncoding] : null ,
|
|
onTap: () {
|
|
_navigatorService.push(SettingsPrinterEncodingRoute);
|
|
}),
|
|
SettingItem(
|
|
title: 'Ширина ленты',
|
|
name: vm.printerPaperSize != null ? paperSize[vm.printerPaperSize] : null ,
|
|
onTap: () {
|
|
_navigatorService.push(SettingsPrinterPaperRoute);
|
|
}),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(bottom: 24.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
AmanIconButtonHorizontal(
|
|
icon: Icons.local_printshop_outlined,
|
|
title: 'Напечатать тестовую страницу',
|
|
activeColor: primaryColor,
|
|
selected: vm.printerBT != null,
|
|
onPressed: () {
|
|
_testPrint();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
}
|