From 051b64e3a616746a68e14af1c06437522a26306b Mon Sep 17 00:00:00 2001 From: efrilm Date: Sun, 3 Aug 2025 14:39:15 +0700 Subject: [PATCH] feat: sync order --- lib/core/constants/variables.dart | 1 + lib/core/utils/transaction_sales_invoice.dart | 19 +- .../datasources/order_remote_datasource.dart | 46 +- .../response/order_remote_datasource.dart | 113 --- .../models/response/order_response_model.dart | 220 +++++ lib/main.dart | 4 + .../home/pages/dashboard_page.dart | 17 +- .../home/widgets/home_right_title.dart | 4 +- .../transaction_report_bloc.dart | 6 +- .../transaction_report_bloc.freezed.dart | 44 +- .../transaction_report_state.dart | 4 +- .../widgets/transaction_report_widget.dart | 163 ++-- .../blocs/order_loader/order_loader_bloc.dart | 27 + .../order_loader_bloc.freezed.dart | 863 ++++++++++++++++++ .../order_loader/order_loader_event.dart | 6 + .../order_loader/order_loader_state.dart | 10 + lib/presentation/sales/pages/sales_page.dart | 93 +- .../sales/widgets/sales_card.dart | 25 +- .../sales/widgets/sales_detail.dart | 15 +- .../sales/widgets/sales_list_order.dart | 17 +- .../widgets/sales_order_information.dart | 15 +- .../sales/widgets/sales_payment.dart | 14 +- .../sales/widgets/sales_right_title.dart | 6 +- .../sales/widgets/sales_title.dart | 16 +- .../setting/pages/settings_page.dart | 7 +- 25 files changed, 1422 insertions(+), 333 deletions(-) delete mode 100644 lib/data/models/response/order_remote_datasource.dart create mode 100644 lib/data/models/response/order_response_model.dart create mode 100644 lib/presentation/sales/blocs/order_loader/order_loader_bloc.dart create mode 100644 lib/presentation/sales/blocs/order_loader/order_loader_bloc.freezed.dart create mode 100644 lib/presentation/sales/blocs/order_loader/order_loader_event.dart create mode 100644 lib/presentation/sales/blocs/order_loader/order_loader_state.dart diff --git a/lib/core/constants/variables.dart b/lib/core/constants/variables.dart index b9ffc2b..b5b9b83 100644 --- a/lib/core/constants/variables.dart +++ b/lib/core/constants/variables.dart @@ -3,4 +3,5 @@ class Variables { static const String apiVersion = 'v1'; // static const String baseUrl = 'http://192.168.1.202:8000'; static const String baseUrl = 'https://enaklo-pos-be.altru.id'; + static const int defaultLimit = 10; } diff --git a/lib/core/utils/transaction_sales_invoice.dart b/lib/core/utils/transaction_sales_invoice.dart index 44a684f..3e31f6e 100644 --- a/lib/core/utils/transaction_sales_invoice.dart +++ b/lib/core/utils/transaction_sales_invoice.dart @@ -5,7 +5,7 @@ import 'package:enaklo_pos/core/extensions/int_ext.dart'; import 'package:flutter/services.dart'; import 'package:enaklo_pos/core/utils/helper_pdf_service.dart'; -import 'package:enaklo_pos/data/models/response/order_remote_datasource.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:pdf/widgets.dart'; import 'package:pdf/pdf.dart'; import 'package:pdf/widgets.dart' as pw; @@ -13,7 +13,7 @@ import 'package:pdf/widgets.dart' as pw; class TransactionSalesInvoice { static late Font ttf; static Future generate( - List itemOrders, String searchDateFormatted) async { + List itemOrders, String searchDateFormatted) async { final pdf = Document(); // var data = await rootBundle.load("assets/fonts/noto-sans.ttf"); // ttf = Font.ttf(data); @@ -70,7 +70,7 @@ class TransactionSalesInvoice { ), ]); - static Widget buildInvoice(List itemOrders) { + static Widget buildInvoice(List itemOrders) { final headers = [ 'Total', 'Sub Total', @@ -81,12 +81,13 @@ class TransactionSalesInvoice { ]; final data = itemOrders.map((item) { return [ - item.total!.currencyFormatRp, - item.subTotal!.currencyFormatRp, - item.tax!.currencyFormatRp, - int.parse(item.discountAmount!.replaceAll('.00', '')).currencyFormatRp, - item.serviceCharge!.currencyFormatRp, - item.transactionTime!.toFormattedDate2(), + item.totalAmount!.currencyFormatRp, + item.subtotal!.currencyFormatRp, + item.taxAmount!.currencyFormatRp, + int.parse(item.discountAmount!.toString().replaceAll('.00', '')) + .currencyFormatRp, + 0, + item.createdAt!.toFormattedDate2(), ]; }).toList(); diff --git a/lib/data/datasources/order_remote_datasource.dart b/lib/data/datasources/order_remote_datasource.dart index b083b0a..d05426f 100644 --- a/lib/data/datasources/order_remote_datasource.dart +++ b/lib/data/datasources/order_remote_datasource.dart @@ -6,7 +6,7 @@ import 'package:dio/dio.dart'; import 'package:enaklo_pos/core/constants/variables.dart'; import 'package:enaklo_pos/core/network/dio_client.dart'; import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart'; -import 'package:enaklo_pos/data/models/response/order_remote_datasource.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:enaklo_pos/data/models/response/payment_method_response_model.dart'; import 'package:enaklo_pos/data/models/response/summary_response_model.dart'; import 'package:enaklo_pos/presentation/home/models/order_model.dart'; @@ -223,4 +223,48 @@ class OrderRemoteDatasource { return const Left('Terjadi kesalahan tak terduga'); } } + + Future> getOrder( + {int page = 1, + int limit = Variables.defaultLimit, + String status = 'completed'}) async { + try { + final authData = await AuthLocalDataSource().getAuthData(); + final response = await dio.get( + '${Variables.baseUrl}/api/v1/orders', + queryParameters: { + 'page': page, + 'limit': limit, + 'status': status, + 'outlet_id': authData.user?.outletId, + }, + options: Options( + headers: { + 'Authorization': 'Bearer ${authData.token}', + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + ), + ); + + log("📥 HTTP Status Code: ${response.statusCode}"); + log("📥 Response Body: ${response.data}"); + + if (response.statusCode == 200) { + log("✅ getOrderByRangeDate API call successful"); + return Right(OrderResponseModel.fromMap(response.data)); + } else { + log("❌ getOrderByRangeDate API call failed - Status: ${response.statusCode}"); + return const Left("Failed Load Data"); + } + } on DioException catch (e) { + final errorMessage = 'Something went wrong'; + log("💥 Dio error: ${e.message}"); + log("💥 Dio response: ${e.response?.data}"); + return Left(errorMessage); + } catch (e) { + log("💥 Unexpected error: $e"); + return Left("Unexpected Error: $e"); + } + } } diff --git a/lib/data/models/response/order_remote_datasource.dart b/lib/data/models/response/order_remote_datasource.dart deleted file mode 100644 index 411da5d..0000000 --- a/lib/data/models/response/order_remote_datasource.dart +++ /dev/null @@ -1,113 +0,0 @@ -import 'dart:convert'; - -class OrderResponseModel { - String? status; - List? data; - - OrderResponseModel({ - this.status, - this.data, - }); - - factory OrderResponseModel.fromJson(String str) => - OrderResponseModel.fromMap(json.decode(str)); - - String toJson() => json.encode(toMap()); - - factory OrderResponseModel.fromMap(Map json) => - OrderResponseModel( - status: json["status"], - data: json["data"] == null - ? [] - : List.from( - json["data"]!.map((x) => ItemOrder.fromMap(x))), - ); - - Map toMap() => { - "status": status, - "data": - data == null ? [] : List.from(data!.map((x) => x.toMap())), - }; -} - -class ItemOrder { - int? id; - int? paymentAmount; - int? subTotal; - int? tax; - int? discount; - String? discountAmount; - int? serviceCharge; - int? total; - String? paymentMethod; - int? totalItem; - int? idKasir; - String? namaKasir; - DateTime? transactionTime; - DateTime? createdAt; - DateTime? updatedAt; - - ItemOrder({ - this.id, - this.paymentAmount, - this.subTotal, - this.tax, - this.discount, - this.discountAmount, - this.serviceCharge, - this.total, - this.paymentMethod, - this.totalItem, - this.idKasir, - this.namaKasir, - this.transactionTime, - this.createdAt, - this.updatedAt, - }); - - factory ItemOrder.fromJson(String str) => ItemOrder.fromMap(json.decode(str)); - - String toJson() => json.encode(toMap()); - - factory ItemOrder.fromMap(Map json) => ItemOrder( - id: json["id"], - paymentAmount: json["payment_amount"], - subTotal: json["sub_total"], - tax: json["tax"], - discount: json["discount"], - discountAmount: json["discount_amount"], - serviceCharge: json["service_charge"], - total: json["total"], - paymentMethod: json["payment_method"]!, - totalItem: json["total_item"], - idKasir: json["id_kasir"], - namaKasir: json["nama_kasir"], - transactionTime: json["transaction_time"] == null - ? null - : DateTime.parse(json["transaction_time"]), - createdAt: json["created_at"] == null - ? null - : DateTime.parse(json["created_at"]), - updatedAt: json["updated_at"] == null - ? null - : DateTime.parse(json["updated_at"]), - ); - - Map toMap() => { - "id": id, - "payment_amount": paymentAmount, - "sub_total": subTotal, - "tax": tax, - "discount": discount, - "discount_amount": discountAmount, - "service_charge": serviceCharge, - "total": total, - "payment_method": paymentMethod, - "total_item": totalItem, - "id_kasir": idKasir, - "nama_kasir": namaKasir, - "transaction_time": transactionTime?.toIso8601String(), - "created_at": createdAt?.toIso8601String(), - "updated_at": updatedAt?.toIso8601String(), - }; -} diff --git a/lib/data/models/response/order_response_model.dart b/lib/data/models/response/order_response_model.dart new file mode 100644 index 0000000..71ada5d --- /dev/null +++ b/lib/data/models/response/order_response_model.dart @@ -0,0 +1,220 @@ +import 'dart:convert'; + +class OrderResponseModel { + final bool? success; + final OrderData? data; + final dynamic errors; + + OrderResponseModel({ + this.success, + this.data, + this.errors, + }); + + factory OrderResponseModel.fromJson(String str) => + OrderResponseModel.fromMap(json.decode(str)); + + String toJson() => json.encode(toMap()); + + factory OrderResponseModel.fromMap(Map json) => + OrderResponseModel( + success: json["success"], + data: json["data"] == null ? null : OrderData.fromMap(json["data"]), + errors: json["errors"], + ); + + Map toMap() => { + "success": success, + "data": data?.toMap(), + "errors": errors, + }; +} + +class OrderData { + final List? orders; + final int? totalCount; + final int? page; + final int? limit; + final int? totalPages; + + OrderData({ + this.orders, + this.totalCount, + this.page, + this.limit, + this.totalPages, + }); + + factory OrderData.fromMap(Map json) => OrderData( + orders: json["orders"] == null + ? [] + : List.from(json["orders"].map((x) => Order.fromMap(x))), + totalCount: json["total_count"], + page: json["page"], + limit: json["limit"], + totalPages: json["total_pages"], + ); + + Map toMap() => { + "orders": orders == null + ? [] + : List.from(orders!.map((x) => x.toMap())), + "total_count": totalCount, + "page": page, + "limit": limit, + "total_pages": totalPages, + }; +} + +class Order { + final String? id; + final String? orderNumber; + final String? outletId; + final String? userId; + final String? tableNumber; + final String? orderType; + final String? status; + final int? subtotal; + final int? taxAmount; + final int? discountAmount; + final int? totalAmount; + final String? notes; + final Map? metadata; + final DateTime? createdAt; + final DateTime? updatedAt; + final List? orderItems; + + Order({ + this.id, + this.orderNumber, + this.outletId, + this.userId, + this.tableNumber, + this.orderType, + this.status, + this.subtotal, + this.taxAmount, + this.discountAmount, + this.totalAmount, + this.notes, + this.metadata, + this.createdAt, + this.updatedAt, + this.orderItems, + }); + + factory Order.fromMap(Map json) => Order( + id: json["id"], + orderNumber: json["order_number"], + outletId: json["outlet_id"], + userId: json["user_id"], + tableNumber: json["table_number"], + orderType: json["order_type"], + status: json["status"], + subtotal: json["subtotal"], + taxAmount: json["tax_amount"], + discountAmount: json["discount_amount"], + totalAmount: json["total_amount"], + notes: json["notes"], + metadata: json["metadata"] ?? {}, + createdAt: json["created_at"] == null + ? null + : DateTime.parse(json["created_at"]), + updatedAt: json["updated_at"] == null + ? null + : DateTime.parse(json["updated_at"]), + orderItems: json["order_items"] == null + ? [] + : List.from( + json["order_items"].map((x) => OrderItem.fromMap(x))), + ); + + Map toMap() => { + "id": id, + "order_number": orderNumber, + "outlet_id": outletId, + "user_id": userId, + "table_number": tableNumber, + "order_type": orderType, + "status": status, + "subtotal": subtotal, + "tax_amount": taxAmount, + "discount_amount": discountAmount, + "total_amount": totalAmount, + "notes": notes, + "metadata": metadata, + "created_at": createdAt?.toIso8601String(), + "updated_at": updatedAt?.toIso8601String(), + "order_items": orderItems == null + ? [] + : List.from(orderItems!.map((x) => x.toMap())), + }; +} + +class OrderItem { + final String? id; + final String? orderId; + final String? productId; + final String? productName; + final String? productVariantId; + final int? quantity; + final int? unitPrice; + final int? totalPrice; + final List? modifiers; + final String? notes; + final String? status; + final DateTime? createdAt; + final DateTime? updatedAt; + + OrderItem({ + this.id, + this.orderId, + this.productId, + this.productName, + this.productVariantId, + this.quantity, + this.unitPrice, + this.totalPrice, + this.modifiers, + this.notes, + this.status, + this.createdAt, + this.updatedAt, + }); + + factory OrderItem.fromMap(Map json) => OrderItem( + id: json["id"], + orderId: json["order_id"], + productId: json["product_id"], + productName: json["product_name"], + productVariantId: json["product_variant_id"], + quantity: json["quantity"], + unitPrice: json["unit_price"], + totalPrice: json["total_price"], + modifiers: json["modifiers"] ?? [], + notes: json["notes"], + status: json["status"], + createdAt: json["created_at"] == null + ? null + : DateTime.parse(json["created_at"]), + updatedAt: json["updated_at"] == null + ? null + : DateTime.parse(json["updated_at"]), + ); + + Map toMap() => { + "id": id, + "order_id": orderId, + "product_id": productId, + "product_name": productName, + "product_variant_id": productVariantId, + "quantity": quantity, + "unit_price": unitPrice, + "total_price": totalPrice, + "modifiers": modifiers, + "notes": notes, + "status": status, + "created_at": createdAt?.toIso8601String(), + "updated_at": updatedAt?.toIso8601String(), + }; +} diff --git a/lib/main.dart b/lib/main.dart index 98330b8..37c3f1f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:enaklo_pos/data/datasources/outlet_remote_data_source.dart'; import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/outlet_loader/outlet_loader_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/product_loader/product_loader_bloc.dart'; +import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart'; import 'package:flutter/material.dart'; import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart'; import 'package:enaklo_pos/data/datasources/auth_remote_datasource.dart'; @@ -227,6 +228,9 @@ class _MyAppState extends State { BlocProvider( create: (context) => OrderFormBloc(OrderRemoteDatasource()), ), + BlocProvider( + create: (context) => OrderLoaderBloc(OrderRemoteDatasource()), + ), BlocProvider( create: (context) => OutletLoaderBloc(OutletRemoteDataSource()), ), diff --git a/lib/presentation/home/pages/dashboard_page.dart b/lib/presentation/home/pages/dashboard_page.dart index 78c6ee5..29cb86b 100644 --- a/lib/presentation/home/pages/dashboard_page.dart +++ b/lib/presentation/home/pages/dashboard_page.dart @@ -46,6 +46,8 @@ class _DashboardPageState extends State { setState(() {}); } + late StreamSubscription> _connectivitySubscription; + @override void initState() { super.initState(); @@ -63,24 +65,19 @@ class _DashboardPageState extends State { const SettingsPage(), ]; // ignore: unused_local_variable - StreamSubscription> subscription = Connectivity() + _connectivitySubscription = Connectivity() .onConnectivityChanged .listen((List connectivityResult) { - // Received changes in available connectivity types! + if (!mounted) return; // <-- Tambahkan ini! if (connectivityResult.contains(ConnectivityResult.mobile)) { - // Mobile network available. context .read() .add(const OnlineCheckerEvent.check(true)); } else if (connectivityResult.contains(ConnectivityResult.wifi)) { - // Wi-fi is available. context .read() .add(const OnlineCheckerEvent.check(true)); - // Note for Android: - // When both mobile and Wi-Fi are turned on system will return Wi-Fi only as active network type } else { - // Neither mobile network nor Wi-fi available. context .read() .add(const OnlineCheckerEvent.check(false)); @@ -88,6 +85,12 @@ class _DashboardPageState extends State { }); } + @override + void dispose() { + _connectivitySubscription.cancel(); // <-- Cancel subscription di dispose + super.dispose(); + } + @override Widget build(BuildContext context) { return SafeArea( diff --git a/lib/presentation/home/widgets/home_right_title.dart b/lib/presentation/home/widgets/home_right_title.dart index c3fce85..86f622a 100644 --- a/lib/presentation/home/widgets/home_right_title.dart +++ b/lib/presentation/home/widgets/home_right_title.dart @@ -37,7 +37,9 @@ class HomeRightTitle extends StatelessWidget { width: 180.0, height: 40, elevation: 0, - onPressed: () => context.push(SalesPage()), + onPressed: () => context.push(SalesPage( + status: 'pending', + )), mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, icon: Icon( diff --git a/lib/presentation/report/blocs/transaction_report/transaction_report_bloc.dart b/lib/presentation/report/blocs/transaction_report/transaction_report_bloc.dart index 900ef15..26f28d9 100644 --- a/lib/presentation/report/blocs/transaction_report/transaction_report_bloc.dart +++ b/lib/presentation/report/blocs/transaction_report/transaction_report_bloc.dart @@ -1,7 +1,6 @@ - +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart'; -import 'package:enaklo_pos/data/models/response/order_remote_datasource.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'transaction_report_event.dart'; @@ -19,7 +18,8 @@ class TransactionReportBloc event.endDate, ); - result.fold((l) => emit(_Error(l)), (r) => emit(_Loaded(r.data!))); + result.fold( + (l) => emit(_Error(l)), (r) => emit(_Loaded(r.data!.orders!))); }); } } diff --git a/lib/presentation/report/blocs/transaction_report/transaction_report_bloc.freezed.dart b/lib/presentation/report/blocs/transaction_report/transaction_report_bloc.freezed.dart index 08db8b8..f2878d4 100644 --- a/lib/presentation/report/blocs/transaction_report/transaction_report_bloc.freezed.dart +++ b/lib/presentation/report/blocs/transaction_report/transaction_report_bloc.freezed.dart @@ -342,7 +342,7 @@ mixin _$TransactionReportState { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) error, - required TResult Function(List transactionReport) loaded, + required TResult Function(List transactionReport) loaded, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -350,7 +350,7 @@ mixin _$TransactionReportState { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? error, - TResult? Function(List transactionReport)? loaded, + TResult? Function(List transactionReport)? loaded, }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -358,7 +358,7 @@ mixin _$TransactionReportState { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? error, - TResult Function(List transactionReport)? loaded, + TResult Function(List transactionReport)? loaded, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -455,7 +455,7 @@ class _$InitialImpl implements _Initial { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) error, - required TResult Function(List transactionReport) loaded, + required TResult Function(List transactionReport) loaded, }) { return initial(); } @@ -466,7 +466,7 @@ class _$InitialImpl implements _Initial { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? error, - TResult? Function(List transactionReport)? loaded, + TResult? Function(List transactionReport)? loaded, }) { return initial?.call(); } @@ -477,7 +477,7 @@ class _$InitialImpl implements _Initial { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? error, - TResult Function(List transactionReport)? loaded, + TResult Function(List transactionReport)? loaded, required TResult orElse(), }) { if (initial != null) { @@ -572,7 +572,7 @@ class _$LoadingImpl implements _Loading { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) error, - required TResult Function(List transactionReport) loaded, + required TResult Function(List transactionReport) loaded, }) { return loading(); } @@ -583,7 +583,7 @@ class _$LoadingImpl implements _Loading { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? error, - TResult? Function(List transactionReport)? loaded, + TResult? Function(List transactionReport)? loaded, }) { return loading?.call(); } @@ -594,7 +594,7 @@ class _$LoadingImpl implements _Loading { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? error, - TResult Function(List transactionReport)? loaded, + TResult Function(List transactionReport)? loaded, required TResult orElse(), }) { if (loading != null) { @@ -716,7 +716,7 @@ class _$ErrorImpl implements _Error { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) error, - required TResult Function(List transactionReport) loaded, + required TResult Function(List transactionReport) loaded, }) { return error(message); } @@ -727,7 +727,7 @@ class _$ErrorImpl implements _Error { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? error, - TResult? Function(List transactionReport)? loaded, + TResult? Function(List transactionReport)? loaded, }) { return error?.call(message); } @@ -738,7 +738,7 @@ class _$ErrorImpl implements _Error { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? error, - TResult Function(List transactionReport)? loaded, + TResult Function(List transactionReport)? loaded, required TResult orElse(), }) { if (error != null) { @@ -803,7 +803,7 @@ abstract class _$$LoadedImplCopyWith<$Res> { _$LoadedImpl value, $Res Function(_$LoadedImpl) then) = __$$LoadedImplCopyWithImpl<$Res>; @useResult - $Res call({List transactionReport}); + $Res call({List transactionReport}); } /// @nodoc @@ -825,7 +825,7 @@ class __$$LoadedImplCopyWithImpl<$Res> null == transactionReport ? _value._transactionReport : transactionReport // ignore: cast_nullable_to_non_nullable - as List, + as List, )); } } @@ -833,12 +833,12 @@ class __$$LoadedImplCopyWithImpl<$Res> /// @nodoc class _$LoadedImpl implements _Loaded { - const _$LoadedImpl(final List transactionReport) + const _$LoadedImpl(final List transactionReport) : _transactionReport = transactionReport; - final List _transactionReport; + final List _transactionReport; @override - List get transactionReport { + List get transactionReport { if (_transactionReport is EqualUnmodifiableListView) return _transactionReport; // ignore: implicit_dynamic_type @@ -877,7 +877,7 @@ class _$LoadedImpl implements _Loaded { required TResult Function() initial, required TResult Function() loading, required TResult Function(String message) error, - required TResult Function(List transactionReport) loaded, + required TResult Function(List transactionReport) loaded, }) { return loaded(transactionReport); } @@ -888,7 +888,7 @@ class _$LoadedImpl implements _Loaded { TResult? Function()? initial, TResult? Function()? loading, TResult? Function(String message)? error, - TResult? Function(List transactionReport)? loaded, + TResult? Function(List transactionReport)? loaded, }) { return loaded?.call(transactionReport); } @@ -899,7 +899,7 @@ class _$LoadedImpl implements _Loaded { TResult Function()? initial, TResult Function()? loading, TResult Function(String message)? error, - TResult Function(List transactionReport)? loaded, + TResult Function(List transactionReport)? loaded, required TResult orElse(), }) { if (loaded != null) { @@ -947,9 +947,9 @@ class _$LoadedImpl implements _Loaded { } abstract class _Loaded implements TransactionReportState { - const factory _Loaded(final List transactionReport) = _$LoadedImpl; + const factory _Loaded(final List transactionReport) = _$LoadedImpl; - List get transactionReport; + List get transactionReport; /// Create a copy of TransactionReportState /// with the given fields replaced by the non-null parameter values. diff --git a/lib/presentation/report/blocs/transaction_report/transaction_report_state.dart b/lib/presentation/report/blocs/transaction_report/transaction_report_state.dart index 7f8f81d..fc870a5 100644 --- a/lib/presentation/report/blocs/transaction_report/transaction_report_state.dart +++ b/lib/presentation/report/blocs/transaction_report/transaction_report_state.dart @@ -5,6 +5,6 @@ class TransactionReportState with _$TransactionReportState { const factory TransactionReportState.initial() = _Initial; const factory TransactionReportState.loading() = _Loading; const factory TransactionReportState.error(String message) = _Error; - const factory TransactionReportState.loaded( - List transactionReport) = _Loaded; + const factory TransactionReportState.loaded(List transactionReport) = + _Loaded; } diff --git a/lib/presentation/report/widgets/transaction_report_widget.dart b/lib/presentation/report/widgets/transaction_report_widget.dart index ffab5f7..46add37 100644 --- a/lib/presentation/report/widgets/transaction_report_widget.dart +++ b/lib/presentation/report/widgets/transaction_report_widget.dart @@ -2,20 +2,19 @@ import 'dart:developer'; import 'package:enaklo_pos/core/components/spaces.dart'; import 'package:enaklo_pos/core/constants/colors.dart'; -import 'package:enaklo_pos/core/extensions/date_time_ext.dart'; import 'package:enaklo_pos/core/extensions/int_ext.dart'; import 'package:enaklo_pos/core/utils/helper_pdf_service.dart'; import 'package:enaklo_pos/presentation/report/widgets/report_page_title.dart'; import 'package:flutter/material.dart'; import 'package:enaklo_pos/core/utils/permession_handler.dart'; import 'package:enaklo_pos/core/utils/transaction_sales_invoice.dart'; -import 'package:enaklo_pos/data/models/response/order_remote_datasource.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:horizontal_data_table/horizontal_data_table.dart'; class TransactionReportWidget extends StatelessWidget { final String title; final String searchDateFormatted; - final List transactionReport; + final List transactionReport; final List? headerWidgets; const TransactionReportWidget({ super.key, @@ -91,86 +90,88 @@ class TransactionReportWidget extends StatelessWidget { alignment: Alignment.centerLeft, child: Center( child: Text( - transactionReport[index].total!.currencyFormatRp, + transactionReport[index] + .totalAmount! + .currencyFormatRp, )), ), - Container( - width: 120, - height: 52, - padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), - alignment: Alignment.centerLeft, - child: Center( - child: Text( - transactionReport[index].subTotal!.currencyFormatRp, - )), - ), - Container( - width: 100, - height: 52, - padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), - alignment: Alignment.centerLeft, - child: Center( - child: Text( - transactionReport[index].tax!.currencyFormatRp, - )), - ), - Container( - width: 100, - height: 52, - padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), - alignment: Alignment.centerLeft, - child: Center( - child: Text( - int.parse(transactionReport[index] - .discountAmount! - .replaceAll('.00', '')) - .currencyFormatRp, - ), - ), - ), - Container( - width: 100, - height: 52, - padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), - alignment: Alignment.centerLeft, - child: Center( - child: Text( - transactionReport[index] - .serviceCharge! - .currencyFormatRp, - ), - ), - ), - Container( - width: 100, - height: 52, - padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), - alignment: Alignment.centerLeft, - child: Center( - child: Text( - transactionReport[index].totalItem.toString()), - ), - ), - Container( - width: 150, - height: 52, - padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), - alignment: Alignment.centerLeft, - child: Center( - child: Text(transactionReport[index].namaKasir!), - ), - ), - Container( - width: 230, - height: 52, - padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), - alignment: Alignment.centerLeft, - child: Center( - child: Text(transactionReport[index] - .transactionTime! - .toFormattedDate()), - ), - ), + // Container( + // width: 120, + // height: 52, + // padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), + // alignment: Alignment.centerLeft, + // child: Center( + // child: Text( + // transactionReport[index].subTotal!.currencyFormatRp, + // )), + // ), + // Container( + // width: 100, + // height: 52, + // padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), + // alignment: Alignment.centerLeft, + // child: Center( + // child: Text( + // transactionReport[index].tax!.currencyFormatRp, + // )), + // ), + // Container( + // width: 100, + // height: 52, + // padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), + // alignment: Alignment.centerLeft, + // child: Center( + // child: Text( + // int.parse(transactionReport[index] + // .discountAmount! + // .replaceAll('.00', '')) + // .currencyFormatRp, + // ), + // ), + // ), + // Container( + // width: 100, + // height: 52, + // padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), + // alignment: Alignment.centerLeft, + // child: Center( + // child: Text( + // transactionReport[index] + // .serviceCharge! + // .currencyFormatRp, + // ), + // ), + // ), + // Container( + // width: 100, + // height: 52, + // padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), + // alignment: Alignment.centerLeft, + // child: Center( + // child: Text( + // transactionReport[index].totalItem.toString()), + // ), + // ), + // Container( + // width: 150, + // height: 52, + // padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), + // alignment: Alignment.centerLeft, + // child: Center( + // child: Text(transactionReport[index].namaKasir!), + // ), + // ), + // Container( + // width: 230, + // height: 52, + // padding: const EdgeInsets.fromLTRB(5, 0, 0, 0), + // alignment: Alignment.centerLeft, + // child: Center( + // child: Text(transactionReport[index] + // .transactionTime! + // .toFormattedDate()), + // ), + // ), ], ); }, diff --git a/lib/presentation/sales/blocs/order_loader/order_loader_bloc.dart b/lib/presentation/sales/blocs/order_loader/order_loader_bloc.dart new file mode 100644 index 0000000..08701c0 --- /dev/null +++ b/lib/presentation/sales/blocs/order_loader/order_loader_bloc.dart @@ -0,0 +1,27 @@ +import 'package:bloc/bloc.dart'; +import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'order_loader_event.dart'; +part 'order_loader_state.dart'; +part 'order_loader_bloc.freezed.dart'; + +class OrderLoaderBloc extends Bloc { + final OrderRemoteDatasource _orderRemoteDatasource; + OrderLoaderBloc(this._orderRemoteDatasource) + : super(OrderLoaderState.initial()) { + on<_GetByStatus>((event, emit) async { + emit(const _Loading()); + final result = + await _orderRemoteDatasource.getOrder(status: event.status); + result.fold( + (l) => emit(_Error(l)), + (r) => emit(_Loaded( + r.data?.orders ?? [], + r.data?.totalCount ?? 0, + )), + ); + }); + } +} diff --git a/lib/presentation/sales/blocs/order_loader/order_loader_bloc.freezed.dart b/lib/presentation/sales/blocs/order_loader/order_loader_bloc.freezed.dart new file mode 100644 index 0000000..927ee79 --- /dev/null +++ b/lib/presentation/sales/blocs/order_loader/order_loader_bloc.freezed.dart @@ -0,0 +1,863 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'order_loader_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +/// @nodoc +mixin _$OrderLoaderEvent { + String get status => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult when({ + required TResult Function(String status) getByStatus, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String status)? getByStatus, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String status)? getByStatus, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_GetByStatus value) getByStatus, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_GetByStatus value)? getByStatus, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_GetByStatus value)? getByStatus, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + /// Create a copy of OrderLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $OrderLoaderEventCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $OrderLoaderEventCopyWith<$Res> { + factory $OrderLoaderEventCopyWith( + OrderLoaderEvent value, $Res Function(OrderLoaderEvent) then) = + _$OrderLoaderEventCopyWithImpl<$Res, OrderLoaderEvent>; + @useResult + $Res call({String status}); +} + +/// @nodoc +class _$OrderLoaderEventCopyWithImpl<$Res, $Val extends OrderLoaderEvent> + implements $OrderLoaderEventCopyWith<$Res> { + _$OrderLoaderEventCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of OrderLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? status = null, + }) { + return _then(_value.copyWith( + status: null == status + ? _value.status + : status // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$GetByStatusImplCopyWith<$Res> + implements $OrderLoaderEventCopyWith<$Res> { + factory _$$GetByStatusImplCopyWith( + _$GetByStatusImpl value, $Res Function(_$GetByStatusImpl) then) = + __$$GetByStatusImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String status}); +} + +/// @nodoc +class __$$GetByStatusImplCopyWithImpl<$Res> + extends _$OrderLoaderEventCopyWithImpl<$Res, _$GetByStatusImpl> + implements _$$GetByStatusImplCopyWith<$Res> { + __$$GetByStatusImplCopyWithImpl( + _$GetByStatusImpl _value, $Res Function(_$GetByStatusImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? status = null, + }) { + return _then(_$GetByStatusImpl( + null == status + ? _value.status + : status // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$GetByStatusImpl implements _GetByStatus { + const _$GetByStatusImpl(this.status); + + @override + final String status; + + @override + String toString() { + return 'OrderLoaderEvent.getByStatus(status: $status)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$GetByStatusImpl && + (identical(other.status, status) || other.status == status)); + } + + @override + int get hashCode => Object.hash(runtimeType, status); + + /// Create a copy of OrderLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$GetByStatusImplCopyWith<_$GetByStatusImpl> get copyWith => + __$$GetByStatusImplCopyWithImpl<_$GetByStatusImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String status) getByStatus, + }) { + return getByStatus(status); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String status)? getByStatus, + }) { + return getByStatus?.call(status); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String status)? getByStatus, + required TResult orElse(), + }) { + if (getByStatus != null) { + return getByStatus(status); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_GetByStatus value) getByStatus, + }) { + return getByStatus(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_GetByStatus value)? getByStatus, + }) { + return getByStatus?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_GetByStatus value)? getByStatus, + required TResult orElse(), + }) { + if (getByStatus != null) { + return getByStatus(this); + } + return orElse(); + } +} + +abstract class _GetByStatus implements OrderLoaderEvent { + const factory _GetByStatus(final String status) = _$GetByStatusImpl; + + @override + String get status; + + /// Create a copy of OrderLoaderEvent + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$GetByStatusImplCopyWith<_$GetByStatusImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +mixin _$OrderLoaderState { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loading, + required TResult Function(List orders, int totalOrder) loaded, + required TResult Function(String message) error, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function()? loading, + TResult? Function(List orders, int totalOrder)? loaded, + TResult? Function(String message)? error, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loading, + TResult Function(List orders, int totalOrder)? loaded, + TResult Function(String message)? error, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, + required TResult Function(_Error value) error, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, + TResult? Function(_Error value)? error, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, + TResult Function(_Error value)? error, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $OrderLoaderStateCopyWith<$Res> { + factory $OrderLoaderStateCopyWith( + OrderLoaderState value, $Res Function(OrderLoaderState) then) = + _$OrderLoaderStateCopyWithImpl<$Res, OrderLoaderState>; +} + +/// @nodoc +class _$OrderLoaderStateCopyWithImpl<$Res, $Val extends OrderLoaderState> + implements $OrderLoaderStateCopyWith<$Res> { + _$OrderLoaderStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc +abstract class _$$InitialImplCopyWith<$Res> { + factory _$$InitialImplCopyWith( + _$InitialImpl value, $Res Function(_$InitialImpl) then) = + __$$InitialImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$InitialImplCopyWithImpl<$Res> + extends _$OrderLoaderStateCopyWithImpl<$Res, _$InitialImpl> + implements _$$InitialImplCopyWith<$Res> { + __$$InitialImplCopyWithImpl( + _$InitialImpl _value, $Res Function(_$InitialImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$InitialImpl implements _Initial { + const _$InitialImpl(); + + @override + String toString() { + return 'OrderLoaderState.initial()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$InitialImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loading, + required TResult Function(List orders, int totalOrder) loaded, + required TResult Function(String message) error, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function()? loading, + TResult? Function(List orders, int totalOrder)? loaded, + TResult? Function(String message)? error, + }) { + return initial?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loading, + TResult Function(List orders, int totalOrder)? loaded, + TResult Function(String message)? error, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, + required TResult Function(_Error value) error, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, + TResult? Function(_Error value)? error, + }) { + return initial?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, + TResult Function(_Error value)? error, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class _Initial implements OrderLoaderState { + const factory _Initial() = _$InitialImpl; +} + +/// @nodoc +abstract class _$$LoadingImplCopyWith<$Res> { + factory _$$LoadingImplCopyWith( + _$LoadingImpl value, $Res Function(_$LoadingImpl) then) = + __$$LoadingImplCopyWithImpl<$Res>; +} + +/// @nodoc +class __$$LoadingImplCopyWithImpl<$Res> + extends _$OrderLoaderStateCopyWithImpl<$Res, _$LoadingImpl> + implements _$$LoadingImplCopyWith<$Res> { + __$$LoadingImplCopyWithImpl( + _$LoadingImpl _value, $Res Function(_$LoadingImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. +} + +/// @nodoc + +class _$LoadingImpl implements _Loading { + const _$LoadingImpl(); + + @override + String toString() { + return 'OrderLoaderState.loading()'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is _$LoadingImpl); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loading, + required TResult Function(List orders, int totalOrder) loaded, + required TResult Function(String message) error, + }) { + return loading(); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function()? loading, + TResult? Function(List orders, int totalOrder)? loaded, + TResult? Function(String message)? error, + }) { + return loading?.call(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loading, + TResult Function(List orders, int totalOrder)? loaded, + TResult Function(String message)? error, + required TResult orElse(), + }) { + if (loading != null) { + return loading(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, + required TResult Function(_Error value) error, + }) { + return loading(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, + TResult? Function(_Error value)? error, + }) { + return loading?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, + TResult Function(_Error value)? error, + required TResult orElse(), + }) { + if (loading != null) { + return loading(this); + } + return orElse(); + } +} + +abstract class _Loading implements OrderLoaderState { + const factory _Loading() = _$LoadingImpl; +} + +/// @nodoc +abstract class _$$LoadedImplCopyWith<$Res> { + factory _$$LoadedImplCopyWith( + _$LoadedImpl value, $Res Function(_$LoadedImpl) then) = + __$$LoadedImplCopyWithImpl<$Res>; + @useResult + $Res call({List orders, int totalOrder}); +} + +/// @nodoc +class __$$LoadedImplCopyWithImpl<$Res> + extends _$OrderLoaderStateCopyWithImpl<$Res, _$LoadedImpl> + implements _$$LoadedImplCopyWith<$Res> { + __$$LoadedImplCopyWithImpl( + _$LoadedImpl _value, $Res Function(_$LoadedImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? orders = null, + Object? totalOrder = null, + }) { + return _then(_$LoadedImpl( + null == orders + ? _value._orders + : orders // ignore: cast_nullable_to_non_nullable + as List, + null == totalOrder + ? _value.totalOrder + : totalOrder // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc + +class _$LoadedImpl implements _Loaded { + const _$LoadedImpl(final List orders, this.totalOrder) + : _orders = orders; + + final List _orders; + @override + List get orders { + if (_orders is EqualUnmodifiableListView) return _orders; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_orders); + } + + @override + final int totalOrder; + + @override + String toString() { + return 'OrderLoaderState.loaded(orders: $orders, totalOrder: $totalOrder)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$LoadedImpl && + const DeepCollectionEquality().equals(other._orders, _orders) && + (identical(other.totalOrder, totalOrder) || + other.totalOrder == totalOrder)); + } + + @override + int get hashCode => Object.hash( + runtimeType, const DeepCollectionEquality().hash(_orders), totalOrder); + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$LoadedImplCopyWith<_$LoadedImpl> get copyWith => + __$$LoadedImplCopyWithImpl<_$LoadedImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loading, + required TResult Function(List orders, int totalOrder) loaded, + required TResult Function(String message) error, + }) { + return loaded(orders, totalOrder); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function()? loading, + TResult? Function(List orders, int totalOrder)? loaded, + TResult? Function(String message)? error, + }) { + return loaded?.call(orders, totalOrder); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loading, + TResult Function(List orders, int totalOrder)? loaded, + TResult Function(String message)? error, + required TResult orElse(), + }) { + if (loaded != null) { + return loaded(orders, totalOrder); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, + required TResult Function(_Error value) error, + }) { + return loaded(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, + TResult? Function(_Error value)? error, + }) { + return loaded?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, + TResult Function(_Error value)? error, + required TResult orElse(), + }) { + if (loaded != null) { + return loaded(this); + } + return orElse(); + } +} + +abstract class _Loaded implements OrderLoaderState { + const factory _Loaded(final List orders, final int totalOrder) = + _$LoadedImpl; + + List get orders; + int get totalOrder; + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$LoadedImplCopyWith<_$LoadedImpl> get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class _$$ErrorImplCopyWith<$Res> { + factory _$$ErrorImplCopyWith( + _$ErrorImpl value, $Res Function(_$ErrorImpl) then) = + __$$ErrorImplCopyWithImpl<$Res>; + @useResult + $Res call({String message}); +} + +/// @nodoc +class __$$ErrorImplCopyWithImpl<$Res> + extends _$OrderLoaderStateCopyWithImpl<$Res, _$ErrorImpl> + implements _$$ErrorImplCopyWith<$Res> { + __$$ErrorImplCopyWithImpl( + _$ErrorImpl _value, $Res Function(_$ErrorImpl) _then) + : super(_value, _then); + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? message = null, + }) { + return _then(_$ErrorImpl( + null == message + ? _value.message + : message // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$ErrorImpl implements _Error { + const _$ErrorImpl(this.message); + + @override + final String message; + + @override + String toString() { + return 'OrderLoaderState.error(message: $message)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ErrorImpl && + (identical(other.message, message) || other.message == message)); + } + + @override + int get hashCode => Object.hash(runtimeType, message); + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ErrorImplCopyWith<_$ErrorImpl> get copyWith => + __$$ErrorImplCopyWithImpl<_$ErrorImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function() loading, + required TResult Function(List orders, int totalOrder) loaded, + required TResult Function(String message) error, + }) { + return error(message); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function()? initial, + TResult? Function()? loading, + TResult? Function(List orders, int totalOrder)? loaded, + TResult? Function(String message)? error, + }) { + return error?.call(message); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function()? loading, + TResult Function(List orders, int totalOrder)? loaded, + TResult Function(String message)? error, + required TResult orElse(), + }) { + if (error != null) { + return error(message); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Initial value) initial, + required TResult Function(_Loading value) loading, + required TResult Function(_Loaded value) loaded, + required TResult Function(_Error value) error, + }) { + return error(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Initial value)? initial, + TResult? Function(_Loading value)? loading, + TResult? Function(_Loaded value)? loaded, + TResult? Function(_Error value)? error, + }) { + return error?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Initial value)? initial, + TResult Function(_Loading value)? loading, + TResult Function(_Loaded value)? loaded, + TResult Function(_Error value)? error, + required TResult orElse(), + }) { + if (error != null) { + return error(this); + } + return orElse(); + } +} + +abstract class _Error implements OrderLoaderState { + const factory _Error(final String message) = _$ErrorImpl; + + String get message; + + /// Create a copy of OrderLoaderState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ErrorImplCopyWith<_$ErrorImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/presentation/sales/blocs/order_loader/order_loader_event.dart b/lib/presentation/sales/blocs/order_loader/order_loader_event.dart new file mode 100644 index 0000000..b100df1 --- /dev/null +++ b/lib/presentation/sales/blocs/order_loader/order_loader_event.dart @@ -0,0 +1,6 @@ +part of 'order_loader_bloc.dart'; + +@freezed +class OrderLoaderEvent with _$OrderLoaderEvent { + const factory OrderLoaderEvent.getByStatus(String status) = _GetByStatus; +} diff --git a/lib/presentation/sales/blocs/order_loader/order_loader_state.dart b/lib/presentation/sales/blocs/order_loader/order_loader_state.dart new file mode 100644 index 0000000..64445d7 --- /dev/null +++ b/lib/presentation/sales/blocs/order_loader/order_loader_state.dart @@ -0,0 +1,10 @@ +part of 'order_loader_bloc.dart'; + +@freezed +class OrderLoaderState with _$OrderLoaderState { + const factory OrderLoaderState.initial() = _Initial; + const factory OrderLoaderState.loading() = _Loading; + const factory OrderLoaderState.loaded(List orders, int totalOrder) = + _Loaded; + const factory OrderLoaderState.error(String message) = _Error; +} diff --git a/lib/presentation/sales/pages/sales_page.dart b/lib/presentation/sales/pages/sales_page.dart index b2d97d6..89d0732 100644 --- a/lib/presentation/sales/pages/sales_page.dart +++ b/lib/presentation/sales/pages/sales_page.dart @@ -1,7 +1,9 @@ import 'package:enaklo_pos/core/components/buttons.dart'; import 'package:enaklo_pos/core/components/spaces.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:enaklo_pos/presentation/home/models/order_model.dart'; import 'package:enaklo_pos/presentation/sales/blocs/day_sales/day_sales_bloc.dart'; +import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart'; import 'package:enaklo_pos/presentation/sales/widgets/sales_detail.dart'; import 'package:enaklo_pos/presentation/sales/widgets/sales_list_order.dart'; import 'package:enaklo_pos/presentation/sales/widgets/sales_order_information.dart'; @@ -15,7 +17,8 @@ import '../widgets/sales_card.dart'; import '../widgets/sales_title.dart'; class SalesPage extends StatefulWidget { - const SalesPage({super.key}); + final String status; + const SalesPage({super.key, required this.status}); @override State createState() => _SalesPageState(); @@ -24,7 +27,7 @@ class SalesPage extends StatefulWidget { class _SalesPageState extends State { DateTime startDate = DateTime.now(); DateTime endDate = DateTime.now(); - OrderModel? orderDetail; + Order? orderDetail; int _total = 0; String searchQuery = ''; @@ -32,18 +35,18 @@ class _SalesPageState extends State { @override void initState() { context - .read() - .add(DaySalesEvent.getRangeDateSales(startDate, endDate)); + .read() + .add(OrderLoaderEvent.getByStatus(widget.status)); super.initState(); } - List _filterOrders(List orders) { + List _filterOrders(List orders) { if (searchQuery.isEmpty) { return orders; } return orders.where((order) { - final customerName = order.customerName.toLowerCase(); + final customerName = order.orderNumber?.toLowerCase() ?? ""; final queryLower = searchQuery.toLowerCase(); return customerName.contains(queryLower); }).toList(); @@ -63,6 +66,9 @@ class _SalesPageState extends State { child: Column( children: [ SalesTitle( + title: widget.status == 'pending' + ? "Pending Pesanan" + : "Daftar Pesanan", startDate: startDate, endDate: endDate, total: _total, @@ -83,13 +89,26 @@ class _SalesPageState extends State { }, ), Expanded( - child: BlocBuilder( + child: BlocBuilder( builder: (context, state) { return state.maybeWhen( orElse: () => const Center( child: CircularProgressIndicator(), ), - loaded: (orders) { + loading: () => const Center( + child: CircularProgressIndicator(), + ), + error: (message) => Center( + child: Text( + message, + style: TextStyle( + fontSize: 16.0, + fontWeight: FontWeight.bold, + ), + ), + ), + loaded: (orders, totalOrder) { + _total = totalOrder; final filtered = _filterOrders(orders); if (filtered.isEmpty) { return Center( @@ -102,13 +121,6 @@ class _SalesPageState extends State { ), ); } else { - WidgetsBinding.instance - .addPostFrameCallback((_) { - setState(() { - _total = filtered.length; - }); - }); - return SingleChildScrollView( child: Column( children: List.generate( @@ -162,32 +174,35 @@ class _SalesPageState extends State { ), ], ), - Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - children: [ - Row( - children: [ - Expanded( - child: SalesOrderInformation( - order: orderDetail, + Expanded( + child: SingleChildScrollView( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: SalesOrderInformation( + order: orderDetail, + ), ), - ), - SpaceWidth(16), - Expanded( - child: SalesDetail( - order: orderDetail, + SpaceWidth(16), + Expanded( + child: SalesDetail( + order: orderDetail, + ), ), - ), - ], - ), - SalesListOrder( - order: orderDetail, - ), - SalesPayment( - order: orderDetail, - ), - ], + ], + ), + SalesListOrder( + order: orderDetail, + ), + SalesPayment( + order: orderDetail, + ), + ], + ), ), ) ], diff --git a/lib/presentation/sales/widgets/sales_card.dart b/lib/presentation/sales/widgets/sales_card.dart index 70dc6fb..e8ec632 100644 --- a/lib/presentation/sales/widgets/sales_card.dart +++ b/lib/presentation/sales/widgets/sales_card.dart @@ -1,11 +1,11 @@ import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/core/extensions/date_time_ext.dart'; import 'package:enaklo_pos/core/extensions/int_ext.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:flutter/material.dart'; class SalesCard extends StatelessWidget { - final OrderModel order; + final Order order; final bool isActive; const SalesCard({ @@ -29,6 +29,17 @@ class SalesCard extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ + Align( + alignment: Alignment.centerRight, + child: Text( + '${order.orderNumber}', + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + ), + ), + ), + const SizedBox(height: 12), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, @@ -44,9 +55,9 @@ class SalesCard extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - order.customerName == "" + order.metadata?['customer_name'] == "" ? "Anonim" - : order.customerName, + : order.metadata?['customer_name'], style: const TextStyle( fontSize: 16, fontWeight: FontWeight.w600, @@ -74,7 +85,7 @@ class SalesCard extends StatelessWidget { borderRadius: BorderRadius.circular(16), ), child: Text( - order.status.toUpperCase(), + (order.status ?? "").toUpperCase(), style: TextStyle( color: Colors.green, fontWeight: FontWeight.w600, @@ -90,7 +101,7 @@ class SalesCard extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - order.total.currencyFormatRpV2, + (order.totalAmount ?? 0).currencyFormatRpV2, style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, @@ -98,7 +109,7 @@ class SalesCard extends StatelessWidget { ), ), Text( - DateTime.parse(order.transactionTime).toFormattedDate2(), + (order.createdAt ?? DateTime.now()).toFormattedDate3(), style: TextStyle( color: AppColors.black, ), diff --git a/lib/presentation/sales/widgets/sales_detail.dart b/lib/presentation/sales/widgets/sales_detail.dart index 77549de..92afb86 100644 --- a/lib/presentation/sales/widgets/sales_detail.dart +++ b/lib/presentation/sales/widgets/sales_detail.dart @@ -1,10 +1,10 @@ import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/core/extensions/date_time_ext.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:flutter/material.dart'; class SalesDetail extends StatelessWidget { - final OrderModel? order; + final Order? order; const SalesDetail({super.key, this.order}); @override @@ -28,20 +28,15 @@ class SalesDetail extends StatelessWidget { ), _item( title: 'Pelanggan', - value: order?.customerName ?? "-", + value: order?.metadata?['customer_name'] ?? "-", ), _item( title: 'Waktu', - value: - DateTime.parse(order?.transactionTime ?? "").toFormattedDate3(), + value: (order?.createdAt ?? DateTime.now()).toFormattedDate3(), ), _item( title: 'Status', - value: order?.paymentStatus ?? "-", - ), - _item( - title: 'Jenis Order', - value: order?.paymentMethod ?? "-", + value: order?.status ?? "-", ), ], ), diff --git a/lib/presentation/sales/widgets/sales_list_order.dart b/lib/presentation/sales/widgets/sales_list_order.dart index 4c01460..a604df0 100644 --- a/lib/presentation/sales/widgets/sales_list_order.dart +++ b/lib/presentation/sales/widgets/sales_list_order.dart @@ -1,10 +1,9 @@ import 'package:enaklo_pos/core/constants/colors.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; -import 'package:enaklo_pos/presentation/home/models/product_quantity.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:flutter/material.dart'; class SalesListOrder extends StatelessWidget { - final OrderModel? order; + final Order? order; const SalesListOrder({super.key, this.order}); @override @@ -37,8 +36,8 @@ class SalesListOrder extends StatelessWidget { ), Column( children: List.generate( - order?.orderItems.length ?? 0, - (index) => _item(order!.orderItems[index]), + order?.orderItems?.length ?? 0, + (index) => _item(order!.orderItems![index]), ).toList(), ), ], @@ -46,7 +45,7 @@ class SalesListOrder extends StatelessWidget { ); } - Padding _item(ProductQuantity product) { + Padding _item(OrderItem product) { return Padding( padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16) .copyWith(bottom: 0), @@ -56,13 +55,13 @@ class SalesListOrder extends StatelessWidget { Column( children: [ Text( - product.product.name ?? '', + product.productName ?? '', style: const TextStyle( fontSize: 14, ), ), Text( - (product.product.price ?? 0) as String, + (product.unitPrice ?? 0).toString(), style: const TextStyle( fontSize: 14, ), @@ -76,7 +75,7 @@ class SalesListOrder extends StatelessWidget { ), ), Text( - (product.product.price ?? 0) as String, + (product.totalPrice ?? 0).toString(), style: const TextStyle( fontSize: 14, ), diff --git a/lib/presentation/sales/widgets/sales_order_information.dart b/lib/presentation/sales/widgets/sales_order_information.dart index 88ccece..6ad054b 100644 --- a/lib/presentation/sales/widgets/sales_order_information.dart +++ b/lib/presentation/sales/widgets/sales_order_information.dart @@ -1,10 +1,10 @@ import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/core/extensions/date_time_ext.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:flutter/material.dart'; class SalesOrderInformation extends StatelessWidget { - final OrderModel? order; + final Order? order; const SalesOrderInformation({super.key, this.order}); @override @@ -28,20 +28,19 @@ class SalesOrderInformation extends StatelessWidget { ), _item( title: 'No. Order', - value: "${order?.id}", + value: "${order?.orderNumber}", ), _item( title: 'Tanggal', - value: - DateTime.parse(order?.transactionTime ?? "").toFormattedDate3(), + value: (order?.createdAt ?? DateTime.now()).toFormattedDate2(), ), _item( - title: 'Kasir', - value: order?.namaKasir ?? "-", + title: 'No. Meja', + value: order?.tableNumber ?? "-", ), _item( title: 'Jenis Order', - value: order?.orderType.value ?? "-", + value: order?.orderType ?? "-", ), ], ), diff --git a/lib/presentation/sales/widgets/sales_payment.dart b/lib/presentation/sales/widgets/sales_payment.dart index 5998841..8ef811a 100644 --- a/lib/presentation/sales/widgets/sales_payment.dart +++ b/lib/presentation/sales/widgets/sales_payment.dart @@ -2,11 +2,11 @@ import 'package:enaklo_pos/core/components/dashed_divider.dart'; import 'package:enaklo_pos/core/components/spaces.dart'; import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/core/extensions/int_ext.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:flutter/material.dart'; class SalesPayment extends StatelessWidget { - final OrderModel? order; + final Order? order; const SalesPayment({super.key, this.order}); @override @@ -34,14 +34,14 @@ class SalesPayment extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - 'Subtotal ${order?.totalItem} Produk', + 'Subtotal ${order?.orderItems?.length} Produk', style: const TextStyle( fontSize: 16, fontWeight: FontWeight.w600, ), ), Text( - (order?.subTotal)?.currencyFormatRp ?? "0", + (order?.subtotal)?.currencyFormatRp ?? "0", style: const TextStyle( fontSize: 16, fontWeight: FontWeight.w600, @@ -54,13 +54,13 @@ class SalesPayment extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - 'Pajak (11%)', + 'Pajak', style: const TextStyle( fontSize: 16, ), ), Text( - (order?.tax)?.currencyFormatRp ?? "0", + (order?.taxAmount)?.currencyFormatRp ?? "0", style: const TextStyle( fontSize: 16, ), @@ -83,7 +83,7 @@ class SalesPayment extends StatelessWidget { ), ), Text( - (order?.total)?.currencyFormatRp ?? "0", + (order?.totalAmount)?.currencyFormatRp ?? "0", style: const TextStyle( color: AppColors.primary, fontSize: 18, diff --git a/lib/presentation/sales/widgets/sales_right_title.dart b/lib/presentation/sales/widgets/sales_right_title.dart index 2d56531..19ecd9a 100644 --- a/lib/presentation/sales/widgets/sales_right_title.dart +++ b/lib/presentation/sales/widgets/sales_right_title.dart @@ -1,10 +1,10 @@ import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; +import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:flutter/material.dart'; class SalesRightTitle extends StatelessWidget { - final OrderModel? order; + final Order? order; final List? actionWidget; const SalesRightTitle({super.key, this.order, this.actionWidget}); @@ -27,7 +27,7 @@ class SalesRightTitle extends StatelessWidget { children: [ Expanded( child: Text( - "Detail Pesanan #${order?.id}", + "Detail Pesanan #${order?.orderNumber}", style: TextStyle( color: AppColors.black, fontSize: 20, diff --git a/lib/presentation/sales/widgets/sales_title.dart b/lib/presentation/sales/widgets/sales_title.dart index 83b699c..ded8efe 100644 --- a/lib/presentation/sales/widgets/sales_title.dart +++ b/lib/presentation/sales/widgets/sales_title.dart @@ -6,6 +6,7 @@ import 'package:enaklo_pos/presentation/sales/dialog/filter_dialog.dart'; import 'package:flutter/material.dart'; class SalesTitle extends StatelessWidget { + final String title; final DateTime startDate; final DateTime endDate; final int total; @@ -18,7 +19,8 @@ class SalesTitle extends StatelessWidget { required this.endDate, required this.onChanged, required this.total, - required this.onDateRangeChanged}); + required this.onDateRangeChanged, + required this.title}); @override Widget build(BuildContext context) { @@ -39,18 +41,14 @@ class SalesTitle extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - GestureDetector( - onTap: () => context.pop(), - child: Icon( - Icons.arrow_back, - color: AppColors.primary, - size: 24, - ), + IconButton( + onPressed: () => context.pop(), + icon: Icon(Icons.arrow_back, color: AppColors.black), ), SpaceWidth(16), Expanded( child: Text( - "Daftar Pesanan", + title, style: TextStyle( color: AppColors.black, fontSize: 20, diff --git a/lib/presentation/setting/pages/settings_page.dart b/lib/presentation/setting/pages/settings_page.dart index 589e721..6c5833b 100644 --- a/lib/presentation/setting/pages/settings_page.dart +++ b/lib/presentation/setting/pages/settings_page.dart @@ -122,7 +122,8 @@ class _SettingsPageState extends State { title: 'Riwayat Transaksi', subtitle: 'Lihat riwayat transaksi', icon: Icons.receipt_long_outlined, - onTap: () => indexValue(2), + onTap: () => + context.push(SalesPage(status: 'completed')), ), SettingTile( index: 3, @@ -168,7 +169,9 @@ class _SettingsPageState extends State { children: [ role != null && role! != 'admin' ? SizedBox() : ProductPage(), DiscountPage(), - SalesPage(), + SalesPage( + status: 'completed', + ), TaxPage(), SyncDataPage(), ProductPage(),