printer delete
This commit is contained in:
+88
-60
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../../../application/printer/printer_form/printer_form_bloc.dart';
|
||||
import '../../../../../../../application/printer/printer_loader/printer_loader_bloc.dart';
|
||||
import '../../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../../components/card/error_card.dart';
|
||||
import '../../../../../../components/loader/loader_with_text.dart';
|
||||
import '../../../../../../components/toast/flushbar.dart';
|
||||
import '../../widgets/printer_card.dart';
|
||||
import 'setting_printer_form.dart';
|
||||
|
||||
@@ -27,75 +29,101 @@ class _SettingPrinterBarState extends State<SettingPrinterBar> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
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'),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'bar',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('bar'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
AppFlushbar.showSuccess(context, 'Printer bar berhasil dihapus');
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'bar',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('bar'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Error',
|
||||
message: 'Terjadi Kesalahan',
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'bar',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('bar'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'bar',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('bar'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
onDelete: () {
|
||||
context.read<PrinterFormBloc>().add(
|
||||
PrinterFormEvent.deleted(state.printer.id),
|
||||
);
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Error',
|
||||
message: 'Terjadi Kesalahan',
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
code: 'bar',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('bar'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
+91
-60
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../../../application/printer/printer_form/printer_form_bloc.dart';
|
||||
import '../../../../../../../application/printer/printer_loader/printer_loader_bloc.dart';
|
||||
import '../../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../../components/card/error_card.dart';
|
||||
import '../../../../../../components/loader/loader_with_text.dart';
|
||||
import '../../../../../../components/toast/flushbar.dart';
|
||||
import '../../widgets/printer_card.dart';
|
||||
import 'setting_printer_form.dart';
|
||||
|
||||
@@ -27,75 +29,104 @@ class _SettingPrinterCheckerState extends State<SettingPrinterChecker> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
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('checker'),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'checker',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('checker'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
AppFlushbar.showSuccess(
|
||||
context,
|
||||
'Printer checker berhasil dihapus',
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'checker',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('checker'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Error',
|
||||
message: 'Terjadi Kesalahan',
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'checker',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('checker'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'checker',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('checker'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
onDelete: () {
|
||||
context.read<PrinterFormBloc>().add(
|
||||
PrinterFormEvent.deleted(state.printer.id),
|
||||
);
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Error',
|
||||
message: 'Terjadi Kesalahan',
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
code: 'checker',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('checker'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
+91
-60
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../../../application/printer/printer_form/printer_form_bloc.dart';
|
||||
import '../../../../../../../application/printer/printer_loader/printer_loader_bloc.dart';
|
||||
import '../../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../../components/card/error_card.dart';
|
||||
import '../../../../../../components/loader/loader_with_text.dart';
|
||||
import '../../../../../../components/toast/flushbar.dart';
|
||||
import '../../widgets/printer_card.dart';
|
||||
import 'setting_printer_form.dart';
|
||||
|
||||
@@ -27,75 +29,104 @@ class _SettingPrinterKitchenState extends State<SettingPrinterKitchen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
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('kitchen'),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'kitchen',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('kitchen'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
AppFlushbar.showSuccess(
|
||||
context,
|
||||
'Printer kitchen berhasil dihapus',
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'kitchen',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('kitchen'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Error',
|
||||
message: 'Terjadi Kesalahan',
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'kitchen',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('kitchen'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'kitchen',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('kitchen'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
onDelete: () {
|
||||
context.read<PrinterFormBloc>().add(
|
||||
PrinterFormEvent.deleted(state.printer.id),
|
||||
);
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Error',
|
||||
message: 'Terjadi Kesalahan',
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
code: 'kitchen',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('kitchen'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
+91
-60
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../../../application/printer/printer_form/printer_form_bloc.dart';
|
||||
import '../../../../../../../application/printer/printer_loader/printer_loader_bloc.dart';
|
||||
import '../../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../../components/card/error_card.dart';
|
||||
import '../../../../../../components/loader/loader_with_text.dart';
|
||||
import '../../../../../../components/toast/flushbar.dart';
|
||||
import '../../widgets/printer_card.dart';
|
||||
import 'setting_printer_form.dart';
|
||||
|
||||
@@ -27,75 +29,104 @@ class _SettingPrinterReceiptState extends State<SettingPrinterReceipt> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
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('receipt'),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'receipt',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('receipt'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
AppFlushbar.showSuccess(
|
||||
context,
|
||||
'Printer receipt berhasil dihapus',
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'receipt',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('receipt'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: "Error",
|
||||
message: "Terjadi kesalahan saat memuat printer",
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'receipt',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('receipt'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'receipt',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('receipt'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
onDelete: () {
|
||||
context.read<PrinterFormBloc>().add(
|
||||
PrinterFormEvent.deleted(state.printer.id),
|
||||
);
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: "Error",
|
||||
message: "Terjadi kesalahan saat memuat printer",
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
code: 'receipt',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('receipt'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
+90
-60
@@ -1,10 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../../../application/printer/printer_form/printer_form_bloc.dart';
|
||||
import '../../../../../../../application/printer/printer_loader/printer_loader_bloc.dart';
|
||||
import '../../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../../components/card/error_card.dart';
|
||||
import '../../../../../../components/loader/loader_with_text.dart';
|
||||
import '../../../../../../components/toast/flushbar.dart';
|
||||
import '../../widgets/printer_card.dart';
|
||||
import 'setting_printer_form.dart';
|
||||
|
||||
@@ -27,75 +29,103 @@ class _SettingPrinterTicketState extends State<SettingPrinterTicket> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
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'),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'ticket',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('ticket'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
AppFlushbar.showSuccess(
|
||||
context,
|
||||
'Printer ticket berhasil dihapus',
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Material(
|
||||
color: AppColor.background,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
BlocBuilder<PrinterLoaderBloc, PrinterLoaderState>(
|
||||
builder: (context, state) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'ticket',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('ticket'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Error',
|
||||
message: 'Terjadi Kesalahan',
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
if (state.printer.code == '') {
|
||||
return SettingPrinterForm(
|
||||
code: 'ticket',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('ticket'),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return state.failureOption.fold(
|
||||
() => isEdit
|
||||
? SettingPrinterForm(
|
||||
code: 'ticket',
|
||||
printer: state.printer,
|
||||
onCancel: () {
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('ticket'),
|
||||
);
|
||||
setState(() {
|
||||
isEdit = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: PrinterCard(
|
||||
printer: state.printer,
|
||||
onEdit: () {
|
||||
setState(() {
|
||||
isEdit = true;
|
||||
});
|
||||
},
|
||||
|
||||
onDelete: () => context.read<PrinterFormBloc>().add(
|
||||
PrinterFormEvent.deleted(state.printer.id),
|
||||
),
|
||||
),
|
||||
(f) => f.maybeMap(
|
||||
orElse: () => ErrorCard(
|
||||
title: 'Error',
|
||||
message: 'Terjadi Kesalahan',
|
||||
onTap: () {},
|
||||
),
|
||||
empty: (value) => SettingPrinterForm(
|
||||
code: 'ticket',
|
||||
onSuccess: () {
|
||||
context.read<PrinterLoaderBloc>().add(
|
||||
PrinterLoaderEvent.getByCode('ticket'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user