2025-10-23 22:16:53 +07:00
|
|
|
import 'package:flutter/material.dart';
|
2025-10-24 02:02:21 +07:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2025-10-23 22:16:53 +07:00
|
|
|
|
2025-10-24 02:02:21 +07:00
|
|
|
import '../application/auth/auth_bloc.dart';
|
2025-11-10 17:23:26 +07:00
|
|
|
import '../application/auth/logout/logout_bloc.dart';
|
2025-10-24 20:06:42 +07:00
|
|
|
import '../application/category/category_loader/category_loader_bloc.dart';
|
2025-10-25 03:03:44 +07:00
|
|
|
import '../application/checkout/checkout_form/checkout_form_bloc.dart';
|
2025-10-27 15:27:21 +07:00
|
|
|
import '../application/customer/customer_loader/customer_loader_bloc.dart';
|
|
|
|
|
import '../application/order/order_form/order_form_bloc.dart';
|
2025-10-27 21:55:19 +07:00
|
|
|
import '../application/order/order_loader/order_loader_bloc.dart';
|
2025-10-24 14:28:04 +07:00
|
|
|
import '../application/outlet/outlet_loader/outlet_loader_bloc.dart';
|
2025-10-27 14:24:29 +07:00
|
|
|
import '../application/payment_method/payment_method_loader/payment_method_loader_bloc.dart';
|
2025-11-04 22:13:15 +07:00
|
|
|
import '../application/printer/bluetooth/bluetooth_connect/bluetooth_connect_bloc.dart';
|
2025-11-04 14:58:51 +07:00
|
|
|
import '../application/printer/bluetooth/bluetooth_loader/bluetooth_loader_bloc.dart';
|
2025-11-07 16:29:26 +07:00
|
|
|
import '../application/printer/print_struck/print_struck_bloc.dart';
|
2025-11-04 22:13:15 +07:00
|
|
|
import '../application/printer/printer_form/printer_form_bloc.dart';
|
|
|
|
|
import '../application/printer/printer_loader/printer_loader_bloc.dart';
|
2025-10-25 00:13:43 +07:00
|
|
|
import '../application/product/product_loader/product_loader_bloc.dart';
|
2025-11-10 16:56:12 +07:00
|
|
|
import '../application/sync/sync_setting/sync_setting_bloc.dart';
|
2025-10-26 18:47:51 +07:00
|
|
|
import '../application/table/table_form/table_form_bloc.dart';
|
|
|
|
|
import '../application/table/table_loader/table_loader_bloc.dart';
|
2025-10-31 14:33:02 +07:00
|
|
|
import '../application/void/void_form/void_form_bloc.dart';
|
2025-10-23 22:16:53 +07:00
|
|
|
import '../common/theme/theme.dart';
|
|
|
|
|
import '../common/constant/app_constant.dart';
|
|
|
|
|
import '../injection.dart';
|
2026-09-02 20:44:14 +07:00
|
|
|
import 'components/dialog/dialog.dart';
|
2025-10-23 22:16:53 +07:00
|
|
|
import 'router/app_router.dart';
|
|
|
|
|
import 'router/app_router_observer.dart';
|
|
|
|
|
|
|
|
|
|
class AppWidget extends StatefulWidget {
|
|
|
|
|
const AppWidget({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<AppWidget> createState() => _AppWidgetState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AppWidgetState extends State<AppWidget> {
|
|
|
|
|
final _appRouter = getIt<AppRouter>();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-10-24 14:28:04 +07:00
|
|
|
return MultiBlocProvider(
|
|
|
|
|
providers: [
|
|
|
|
|
BlocProvider(create: (context) => getIt<AuthBloc>()),
|
|
|
|
|
BlocProvider(create: (context) => getIt<OutletLoaderBloc>()),
|
2025-10-24 20:06:42 +07:00
|
|
|
BlocProvider(create: (context) => getIt<CategoryLoaderBloc>()),
|
2025-10-25 00:13:43 +07:00
|
|
|
BlocProvider(create: (context) => getIt<ProductLoaderBloc>()),
|
2025-10-25 03:03:44 +07:00
|
|
|
BlocProvider(create: (context) => getIt<CheckoutFormBloc>()),
|
2025-10-26 18:47:51 +07:00
|
|
|
BlocProvider(create: (context) => getIt<TableLoaderBloc>()),
|
|
|
|
|
BlocProvider(create: (context) => getIt<TableFormBloc>()),
|
2025-10-27 14:24:29 +07:00
|
|
|
BlocProvider(create: (context) => getIt<PaymentMethodLoaderBloc>()),
|
2025-10-27 15:27:21 +07:00
|
|
|
BlocProvider(create: (context) => getIt<OrderFormBloc>()),
|
2025-10-27 21:55:19 +07:00
|
|
|
BlocProvider(create: (context) => getIt<OrderLoaderBloc>()),
|
2025-10-27 15:27:21 +07:00
|
|
|
BlocProvider(create: (context) => getIt<CustomerLoaderBloc>()),
|
2025-10-31 14:33:02 +07:00
|
|
|
BlocProvider(create: (context) => getIt<VoidFormBloc>()),
|
2025-11-04 14:58:51 +07:00
|
|
|
BlocProvider(create: (context) => getIt<BluetoothLoaderBloc>()),
|
2025-11-04 22:13:15 +07:00
|
|
|
BlocProvider(create: (context) => getIt<BluetoothConnectBloc>()),
|
|
|
|
|
BlocProvider(create: (context) => getIt<PrinterFormBloc>()),
|
|
|
|
|
BlocProvider(create: (context) => getIt<PrinterLoaderBloc>()),
|
2025-11-07 16:29:26 +07:00
|
|
|
BlocProvider(create: (context) => getIt<PrintStruckBloc>()),
|
2025-11-10 16:56:12 +07:00
|
|
|
BlocProvider(create: (context) => getIt<SyncSettingBloc>()),
|
2025-11-10 17:23:26 +07:00
|
|
|
BlocProvider(create: (context) => getIt<LogoutBloc>()),
|
2025-10-24 14:28:04 +07:00
|
|
|
],
|
2025-10-24 02:02:21 +07:00
|
|
|
child: MaterialApp.router(
|
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
|
title: AppConstant.appName,
|
|
|
|
|
theme: ThemeApp.theme,
|
|
|
|
|
routerConfig: _appRouter.config(
|
|
|
|
|
navigatorObservers: () => <NavigatorObserver>[AppRouteObserver()],
|
|
|
|
|
),
|
2026-09-02 20:44:14 +07:00
|
|
|
// Satu listener untuk seluruh aplikasi: cetak bisa dipicu dari banyak
|
|
|
|
|
// halaman, dan `PrintStruckBloc` hidup di atas router jadi prosesnya
|
|
|
|
|
// tetap jalan walau kasir sudah pindah halaman.
|
|
|
|
|
builder: (context, child) => BlocListener<PrintStruckBloc, PrintStruckState>(
|
|
|
|
|
listenWhen: (previous, current) => previous.jobId != current.jobId,
|
|
|
|
|
listener: (_, __) {
|
|
|
|
|
// Dialog harus dibuka dari context di bawah Navigator, sementara
|
|
|
|
|
// builder ini berada di atasnya.
|
|
|
|
|
final navigatorContext = _appRouter.navigatorKey.currentContext;
|
|
|
|
|
if (navigatorContext == null) return;
|
|
|
|
|
showPrintProgressDialog(navigatorContext);
|
|
|
|
|
},
|
|
|
|
|
child: child ?? const SizedBox.shrink(),
|
|
|
|
|
),
|
2025-10-23 22:16:53 +07:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|