print bar

This commit is contained in:
efrilm
2025-11-06 18:48:28 +07:00
parent 3e6dce93fb
commit 873dd7e224
3 changed files with 114 additions and 19 deletions
@@ -29,26 +29,47 @@ class _SettingPrinterBarState extends State<SettingPrinterBar> {
@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('bar'),
);
}
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('bar'),
);
}
AppFlushbar.showSuccess(context, 'Printer bar berhasil dihapus');
},
),
);
},
AppFlushbar.showSuccess(
context,
'Printer bar 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(
@@ -103,6 +124,14 @@ class _SettingPrinterBarState extends State<SettingPrinterBar> {
PrinterFormEvent.deleted(state.printer.id),
);
},
onTestPrint: () {
context.read<PrinterFormBloc>().add(
PrinterFormEvent.printTest(
code: 'bar',
macAccdress: state.printer.address,
),
);
},
),
(f) => f.maybeMap(
orElse: () => ErrorCard(