print ticket

This commit is contained in:
efrilm
2025-11-06 18:59:10 +07:00
parent 873dd7e224
commit 4eece81eb1
4 changed files with 95 additions and 28 deletions
@@ -29,29 +29,47 @@ class _SettingPrinterTicketState extends State<SettingPrinterTicket> {
@override
Widget build(BuildContext context) {
return BlocListener<PrinterFormBloc, PrinterFormState>(
listenWhen: (p, c) =>
p.failureOrDeleteSuccess != c.failureOrDeleteSuccess,
listener: (context, state) {
state.failureOrDeleteSuccess.fold(
() => null,
(either) => either.fold(
(f) => AppFlushbar.showPrinterFailureToast(context, f),
(_) {
if (context.mounted) {
context.read<PrinterLoaderBloc>().add(
const PrinterLoaderEvent.getByCode('ticket'),
);
}
return MultiBlocListener(
listeners: [
BlocListener<PrinterFormBloc, PrinterFormState>(
listenWhen: (p, c) =>
p.failureOrDeleteSuccess != c.failureOrDeleteSuccess,
listener: (context, state) {
state.failureOrDeleteSuccess.fold(
() => null,
(either) => either.fold(
(f) => AppFlushbar.showPrinterFailureToast(context, f),
(_) {
if (context.mounted) {
context.read<PrinterLoaderBloc>().add(
const PrinterLoaderEvent.getByCode('ticket'),
);
}
AppFlushbar.showSuccess(
context,
'Printer ticket berhasil dihapus',
);
},
),
);
},
AppFlushbar.showSuccess(
context,
'Printer ticket berhasil dihapus',
);
},
),
);
},
),
BlocListener<PrinterFormBloc, PrinterFormState>(
listenWhen: (p, c) => p.failureOrPrintTest != c.failureOrPrintTest,
listener: (context, state) {
state.failureOrPrintTest.fold(
() => null,
(either) => either.fold(
(f) => AppFlushbar.showPrinterFailureToast(context, f),
(either) {
AppFlushbar.showSuccess(context, 'Printer test berhasil');
},
),
);
},
),
],
child: Material(
color: AppColor.background,
child: SingleChildScrollView(
@@ -101,10 +119,16 @@ class _SettingPrinterTicketState extends State<SettingPrinterTicket> {
isEdit = true;
});
},
onDelete: () => context.read<PrinterFormBloc>().add(
PrinterFormEvent.deleted(state.printer.id),
),
onTestPrint: () =>
context.read<PrinterFormBloc>().add(
PrinterFormEvent.printTest(
code: 'ticket',
macAccdress: state.printer.address,
),
),
),
(f) => f.maybeMap(
orElse: () => ErrorCard(