Compare commits
20
Commits
44402140fb
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
457ed38827 | ||
|
|
d34487d883 | ||
|
|
f4cdfcb96f | ||
|
|
0bccec8a1e | ||
|
|
86d2196a04 | ||
|
|
aa25de8da7 | ||
|
|
96387c08f4 | ||
|
|
e585cf4292 | ||
|
|
290360674f | ||
|
|
1fbacae1f4 | ||
|
|
613b216c04 | ||
|
|
455a6afd70 | ||
|
|
2813011fac | ||
|
|
83af323a2f | ||
|
|
cef1f79032 | ||
|
|
59a8d7f661 | ||
|
|
a58d1040af | ||
|
|
72a464b4c0 | ||
|
|
5b980d237f | ||
|
|
c12d6525fa |
@@ -47,7 +47,7 @@ android {
|
||||
applicationId "com.appscale.pos"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||
minSdkVersion 23
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
targetSdkVersion 35
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
|
||||
@@ -23,7 +23,7 @@ class DatabaseHelper {
|
||||
|
||||
return await openDatabase(
|
||||
path,
|
||||
version: 2, // Updated version for printer table
|
||||
version: 3, // Updated version for categories table
|
||||
onCreate: _onCreate,
|
||||
onUpgrade: _onUpgrade,
|
||||
);
|
||||
@@ -66,7 +66,22 @@ class DatabaseHelper {
|
||||
)
|
||||
''');
|
||||
|
||||
// Printer table - NEW
|
||||
// Categories table - NEW
|
||||
await db.execute('''
|
||||
CREATE TABLE categories (
|
||||
id TEXT PRIMARY KEY,
|
||||
organization_id TEXT,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT,
|
||||
business_type TEXT,
|
||||
metadata TEXT,
|
||||
is_active INTEGER DEFAULT 1,
|
||||
created_at TEXT,
|
||||
updated_at TEXT
|
||||
)
|
||||
''');
|
||||
|
||||
// Printer table
|
||||
await db.execute('''
|
||||
CREATE TABLE printers (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -85,6 +100,11 @@ class DatabaseHelper {
|
||||
'CREATE INDEX idx_products_category_id ON products(category_id)');
|
||||
await db.execute('CREATE INDEX idx_products_name ON products(name)');
|
||||
await db.execute('CREATE INDEX idx_products_sku ON products(sku)');
|
||||
await db.execute('CREATE INDEX idx_categories_name ON categories(name)');
|
||||
await db.execute(
|
||||
'CREATE INDEX idx_categories_organization_id ON categories(organization_id)');
|
||||
await db.execute(
|
||||
'CREATE INDEX idx_categories_is_active ON categories(is_active)');
|
||||
await db.execute('CREATE INDEX idx_printers_code ON printers(code)');
|
||||
await db.execute('CREATE INDEX idx_printers_type ON printers(type)');
|
||||
}
|
||||
@@ -105,10 +125,32 @@ class DatabaseHelper {
|
||||
)
|
||||
''');
|
||||
|
||||
// Add indexes for printer table
|
||||
await db.execute('CREATE INDEX idx_printers_code ON printers(code)');
|
||||
await db.execute('CREATE INDEX idx_printers_type ON printers(type)');
|
||||
}
|
||||
|
||||
if (oldVersion < 3) {
|
||||
// Add categories table in version 3
|
||||
await db.execute('''
|
||||
CREATE TABLE categories (
|
||||
id TEXT PRIMARY KEY,
|
||||
organization_id TEXT,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT,
|
||||
business_type TEXT,
|
||||
metadata TEXT,
|
||||
is_active INTEGER DEFAULT 1,
|
||||
created_at TEXT,
|
||||
updated_at TEXT
|
||||
)
|
||||
''');
|
||||
|
||||
await db.execute('CREATE INDEX idx_categories_name ON categories(name)');
|
||||
await db.execute(
|
||||
'CREATE INDEX idx_categories_organization_id ON categories(organization_id)');
|
||||
await db.execute(
|
||||
'CREATE INDEX idx_categories_is_active ON categories(is_active)');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> close() async {
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'package:enaklo_pos/core/extensions/string_ext.dart';
|
||||
import 'package:enaklo_pos/core/utils/printer_service.dart';
|
||||
import 'package:enaklo_pos/data/dataoutputs/print_dataoutputs.dart';
|
||||
import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet/outlet_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
|
||||
@@ -31,10 +31,10 @@ Future<void> onPrint(
|
||||
await PrinterLocalDatasource.instance.getPrinterByCode('checker');
|
||||
final kitchenPrinter =
|
||||
await PrinterLocalDatasource.instance.getPrinterByCode('kitchen');
|
||||
final barPrinter =
|
||||
await PrinterLocalDatasource.instance.getPrinterByCode('bar');
|
||||
final receiptPrinter =
|
||||
await PrinterLocalDatasource.instance.getPrinterByCode('receipt');
|
||||
final barPrinter =
|
||||
await PrinterLocalDatasource.instance.getPrinterByCode('bar');
|
||||
|
||||
if (receiptPrinter != null) {
|
||||
try {
|
||||
@@ -135,7 +135,8 @@ Future<void> onPrint(
|
||||
final productByPrinter = productQuantity
|
||||
.where((item) => item.product.printerType == 'kitchen')
|
||||
.toList();
|
||||
final printValue = await PrintDataoutputs.instance.printKitchen(
|
||||
final printValue =
|
||||
await PrintDataoutputs.instance.printKitchenPerProduct(
|
||||
productByPrinter,
|
||||
order.tableNumber ?? "",
|
||||
order.orderNumber ?? "",
|
||||
@@ -279,6 +280,114 @@ Future<void> onPrint(
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onPrintBill(
|
||||
BuildContext context, {
|
||||
required List<ProductQuantity> productQuantity,
|
||||
required Order order,
|
||||
}) async {
|
||||
final outlet = await OutletLocalDatasource().get();
|
||||
final settings = await SettingsLocalDatasource().getTax();
|
||||
final authData = await AuthLocalDataSource().getAuthData();
|
||||
|
||||
if (outlet.businessType == BusinessType.restaurant) {
|
||||
final receiptPrinter =
|
||||
await PrinterLocalDatasource.instance.getPrinterByCode('receipt');
|
||||
|
||||
if (receiptPrinter != null) {
|
||||
try {
|
||||
final printValue = await PrintDataoutputs.instance.printOrderV4(
|
||||
order,
|
||||
authData.user?.name ?? "",
|
||||
'',
|
||||
0,
|
||||
0,
|
||||
settings.value,
|
||||
receiptPrinter.paper.toIntegerFromText,
|
||||
order.orderType ?? "",
|
||||
outlet,
|
||||
productQuantity);
|
||||
await PrinterService()
|
||||
.printWithPrinter(receiptPrinter, printValue, context);
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Print receipt failed',
|
||||
information: [
|
||||
'Order ID: ${order.id}',
|
||||
'Printer: ${receiptPrinter.name}',
|
||||
],
|
||||
);
|
||||
log("Error printing receipt order: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing receipt order: $e')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Receipt printer not found',
|
||||
null,
|
||||
reason:
|
||||
'Receipt printer not found / Printer not setting in printer page',
|
||||
information: [
|
||||
'Order ID: ${order.id}',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Anda belum menghubungkan printer receipt')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (outlet.businessType == BusinessType.ticketing) {
|
||||
final ticketPrinter =
|
||||
await PrinterLocalDatasource.instance.getPrinterByCode('ticket');
|
||||
|
||||
final barcode = await generateBarcodeAsUint8List(order.orderNumber ?? "");
|
||||
|
||||
if (ticketPrinter != null) {
|
||||
try {
|
||||
final printValue = await PrintDataoutputs.instance.printTicket(
|
||||
order.totalAmount ?? 0,
|
||||
barcode,
|
||||
ticketPrinter.paper.toIntegerFromText,
|
||||
);
|
||||
|
||||
await PrinterService()
|
||||
// ignore: use_build_context_synchronously
|
||||
.printWithPrinter(ticketPrinter, printValue, context);
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing ticket ${ticketPrinter.name}',
|
||||
information: [
|
||||
'Printer: ticket',
|
||||
'data: ${ticketPrinter.toMap()}',
|
||||
],
|
||||
);
|
||||
log("Error printing ticket: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing ticket: $e')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Ticket printer not found',
|
||||
null,
|
||||
reason:
|
||||
'Ticket printer not found / Printer not setting in printer page',
|
||||
information: [
|
||||
'Order ID: ${order.id}',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Anda belum menghubungkan printer ticket')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onPrintRecipt(
|
||||
context, {
|
||||
required Order order,
|
||||
@@ -372,6 +481,56 @@ Future<void> onPrinVoidRecipt(
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onPrintSplit(
|
||||
context, {
|
||||
required Order order,
|
||||
}) async {
|
||||
final receiptPrinter =
|
||||
await PrinterLocalDatasource.instance.getPrinterByCode('receipt');
|
||||
final authData = await AuthLocalDataSource().getAuthData();
|
||||
final settings = await SettingsLocalDatasource().getTax();
|
||||
final outlet = await OutletLocalDatasource().get();
|
||||
|
||||
if (receiptPrinter != null) {
|
||||
try {
|
||||
final printValue = await PrintDataoutputs.instance.printSplitBill(
|
||||
order,
|
||||
authData.user?.name ?? "",
|
||||
receiptPrinter.paper.toIntegerFromText,
|
||||
outlet,
|
||||
);
|
||||
await PrinterService()
|
||||
.printWithPrinter(receiptPrinter, printValue, context);
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Print receipt failed',
|
||||
information: [
|
||||
'Order ID: ${order.id}',
|
||||
'Printer: ${receiptPrinter.name}',
|
||||
],
|
||||
);
|
||||
log("Error printing receipt order: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing receipt order: $e')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Kitchen printer not found',
|
||||
null,
|
||||
reason: 'Kitchen printer not found / Printer not setting in printer page',
|
||||
information: [
|
||||
'Order ID: ${order.id}',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Anda belum menghubungkan printer kitchen')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List> generateBarcodeAsUint8List(String data) async {
|
||||
// 1. Buat barcode instance (code128, qrCode, dll)
|
||||
final barcode = Barcode.code128();
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'package:awesome_dio_interceptor/awesome_dio_interceptor.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:enaklo_pos/core/constants/variables.dart';
|
||||
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
||||
import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/auth_response_model.dart';
|
||||
import 'package:enaklo_pos/presentation/auth/login_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -124,13 +127,17 @@ class AuthInterceptorWithRefresh extends Interceptor {
|
||||
Future<bool> _tryRefreshToken() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final refreshToken = prefs.getString('refresh_token');
|
||||
final authData = await AuthLocalDataSource().getAuthData();
|
||||
|
||||
if (refreshToken == null) return false;
|
||||
final url = '${Variables.baseUrl}/api/v1/auth/refresh';
|
||||
|
||||
final response = await Dio().post(
|
||||
'YOUR_REFRESH_TOKEN_ENDPOINT',
|
||||
data: {'refresh_token': refreshToken},
|
||||
url,
|
||||
options: Options(
|
||||
headers: {
|
||||
'Authorization': 'Bearer ${authData.refreshToken}',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
@@ -140,6 +147,11 @@ class AuthInterceptorWithRefresh extends Interceptor {
|
||||
await prefs.setString('auth_token', newToken);
|
||||
await prefs.setString('refresh_token', newRefreshToken);
|
||||
|
||||
AuthResponseModel authResponseModel =
|
||||
AuthResponseModel.fromMap(response.data['data']);
|
||||
|
||||
AuthLocalDataSource().saveAuthData(authResponseModel);
|
||||
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:enaklo_pos/core/utils/helper_pdf_service.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet/outlet_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/inventory_analytic_response_model.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
|
||||
@@ -4,12 +4,16 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_esc_pos_network/flutter_esc_pos_network.dart';
|
||||
import 'package:print_bluetooth_thermal/print_bluetooth_thermal.dart';
|
||||
import 'package:enaklo_pos/data/models/response/print_model.dart';
|
||||
import 'package:synchronized/synchronized.dart';
|
||||
|
||||
class PrinterService {
|
||||
static final PrinterService _instance = PrinterService._internal();
|
||||
factory PrinterService() => _instance;
|
||||
PrinterService._internal();
|
||||
|
||||
final Map<String, Lock> _locks = {};
|
||||
String? _connectedMac;
|
||||
|
||||
/// Connect to Bluetooth printer
|
||||
Future<bool> connectBluetoothPrinter(String macAddress) async {
|
||||
try {
|
||||
@@ -56,6 +60,71 @@ class PrinterService {
|
||||
}
|
||||
}
|
||||
|
||||
Lock _getLock(String address) {
|
||||
return _locks.putIfAbsent(address, () => Lock());
|
||||
}
|
||||
|
||||
Future<bool> printWithPrinter(
|
||||
PrintModel printer, List<int> printData, BuildContext context) async {
|
||||
if (printer.type == 'Bluetooth') {
|
||||
return await _getLock(printer.address).synchronized(() async {
|
||||
try {
|
||||
bool isConnected = await PrintBluetoothThermal.connectionStatus;
|
||||
if (!isConnected || _connectedMac != printer.address) {
|
||||
if (isConnected) {
|
||||
await PrintBluetoothThermal.disconnect;
|
||||
await Future.delayed(const Duration(milliseconds: 1500));
|
||||
}
|
||||
bool connected = await PrintBluetoothThermal.connect(
|
||||
macPrinterAddress: printer.address);
|
||||
if (!connected) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Gagal connect ke ${printer.name}')),
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
_connectedMac = printer.address;
|
||||
await Future.delayed(
|
||||
const Duration(milliseconds: 1000)); // naikkan dari 500ms
|
||||
}
|
||||
|
||||
bool result = await _writeBytesChunked(printData);
|
||||
|
||||
// Beri waktu printer flush sebelum job berikutnya
|
||||
await Future.delayed(const Duration(milliseconds: 1000));
|
||||
|
||||
log("Print result ${printer.name}: $result");
|
||||
return result;
|
||||
} catch (e, stackTrace) {
|
||||
_connectedMac = null;
|
||||
FirebaseCrashlytics.instance.recordError(e, stackTrace,
|
||||
reason: 'Error printing ${printer.name}',
|
||||
information: [
|
||||
'Printer: ${printer.name}',
|
||||
'MAC: ${printer.address}'
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return await printNetwork(printer, printData, context);
|
||||
}
|
||||
}
|
||||
|
||||
// Kirim data per chunk untuk hindari buffer overflow Bluetooth
|
||||
Future<bool> _writeBytesChunked(List<int> data, {int chunkSize = 512}) async {
|
||||
for (int i = 0; i < data.length; i += chunkSize) {
|
||||
final end = (i + chunkSize > data.length) ? data.length : i + chunkSize;
|
||||
final chunk = data.sublist(i, end);
|
||||
bool result = await PrintBluetoothThermal.writeBytes(chunk);
|
||||
if (!result) return false;
|
||||
await Future.delayed(const Duration(milliseconds: 30));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Print using Bluetooth printer
|
||||
Future<bool> printBluetooth(List<int> printData) async {
|
||||
try {
|
||||
@@ -99,17 +168,18 @@ class PrinterService {
|
||||
}
|
||||
|
||||
/// Print using Network printer
|
||||
Future<bool> printNetwork(String ipAddress, List<int> printData) async {
|
||||
Future<bool> printNetwork(
|
||||
PrintModel printer, List<int> printData, BuildContext context) async {
|
||||
try {
|
||||
final printer = PrinterNetworkManager(ipAddress);
|
||||
PosPrintResult connect = await printer.connect();
|
||||
final networkPrinter = PrinterNetworkManager(printer.address);
|
||||
PosPrintResult connect = await networkPrinter.connect();
|
||||
|
||||
if (connect == PosPrintResult.success) {
|
||||
PosPrintResult printing = await printer.printTicket(printData);
|
||||
printer.disconnect();
|
||||
PosPrintResult printing = await networkPrinter.printTicket(printData);
|
||||
networkPrinter.disconnect();
|
||||
|
||||
if (printing == PosPrintResult.success) {
|
||||
log("Successfully printed via Network printer: $ipAddress");
|
||||
log("Successfully printed via Network printer: ${printer.address}");
|
||||
return true;
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
@@ -117,28 +187,34 @@ class PrinterService {
|
||||
null,
|
||||
reason: 'Failed to print via Network printer',
|
||||
information: [
|
||||
'function: printNetwork(String ipAddress, List<int> printData)',
|
||||
'Printer: Network printer',
|
||||
'ipAddress: $ipAddress',
|
||||
'printData: $printData',
|
||||
'Printer: ${printer.name}',
|
||||
'ipAddress: ${printer.address}',
|
||||
],
|
||||
);
|
||||
log("Failed to print via Network printer: ${printing.msg}");
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Gagal print ke ${printer.name}')),
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to connect to Network printer: ${connect.msg}',
|
||||
null,
|
||||
reason: 'Failed to connectNetwork printer',
|
||||
reason: 'Failed to connect Network printer',
|
||||
information: [
|
||||
'function: printNetwork(String ipAddress, List<int> printData)',
|
||||
'Printer: Network printer',
|
||||
'ipAddress: $ipAddress',
|
||||
'printData: $printData',
|
||||
'Printer: ${printer.name}',
|
||||
'ipAddress: ${printer.address}',
|
||||
],
|
||||
);
|
||||
log("Failed to connect to Network printer: ${connect.msg}");
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Gagal connect ke ${printer.name}')),
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
@@ -147,10 +223,8 @@ class PrinterService {
|
||||
stackTrace,
|
||||
reason: 'Error printing via Network',
|
||||
information: [
|
||||
'function: printNetwork(String ipAddress, List<int> printData)',
|
||||
'Printer: Network printer',
|
||||
'ipAddress: $ipAddress',
|
||||
'printData: $printData',
|
||||
'Printer: ${printer.name}',
|
||||
'ipAddress: ${printer.address}',
|
||||
],
|
||||
);
|
||||
log("Error printing via Network: $e");
|
||||
@@ -158,81 +232,6 @@ class PrinterService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Print with automatic printer type detection
|
||||
Future<bool> printWithPrinter(
|
||||
PrintModel printer, List<int> printData, BuildContext context) async {
|
||||
try {
|
||||
if (printer.type == 'Bluetooth') {
|
||||
bool connected = await connectBluetoothPrinter(printer.address);
|
||||
if (!connected) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to connect to Bluetooth printer',
|
||||
null,
|
||||
reason: 'Failed to connect to Bluetooth printe',
|
||||
information: [
|
||||
'function: connectBluetoothPrinter(String macAddress)',
|
||||
'Printer: ${printer.name}',
|
||||
'macAddress: ${printer.address}',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to connect to ${printer.name}')),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool printResult = await printBluetooth(printData);
|
||||
if (!printResult) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to print to ${printer.name}',
|
||||
null,
|
||||
information: [
|
||||
'function: await printBluetooth(printData);',
|
||||
'print: $printData',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to print to ${printer.name}')),
|
||||
);
|
||||
}
|
||||
return printResult;
|
||||
} else {
|
||||
bool printResult = await printNetwork(printer.address, printData);
|
||||
if (!printResult) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
'Failed to connect to Network Printer',
|
||||
null,
|
||||
reason: 'Failed to connect to Network Printer',
|
||||
information: [
|
||||
'function: await printNetwork(printer.address, printData);',
|
||||
'Printer: ${printer.name}',
|
||||
'ipAddress: ${printer.address}',
|
||||
'print: $printData',
|
||||
],
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Failed to print to ${printer.name}')),
|
||||
);
|
||||
}
|
||||
return printResult;
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
e,
|
||||
stackTrace,
|
||||
reason: 'Error printing with printer ${printer.name}',
|
||||
information: [
|
||||
'Printer: ${printer.name}',
|
||||
],
|
||||
);
|
||||
log("Error printing with printer ${printer.name}: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error printing to ${printer.name}: $e')),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Disconnect from Bluetooth printer
|
||||
Future<bool> disconnectBluetooth() async {
|
||||
try {
|
||||
|
||||
@@ -882,6 +882,20 @@ class PrintDataoutputs {
|
||||
styles: const PosStyles(bold: true, align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
if (product.notes != '') {
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Note',
|
||||
width: 4,
|
||||
styles: const PosStyles(bold: false, align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: product.notes,
|
||||
width: 8,
|
||||
styles: const PosStyles(bold: false, align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
@@ -1398,141 +1412,7 @@ class PrintDataoutputs {
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1);
|
||||
//cut
|
||||
if (paper == 80) {
|
||||
bytes += generator.cut();
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
Future<List<int>> printKitchen(
|
||||
List<ProductQuantity> products,
|
||||
String tableNumber,
|
||||
String draftName,
|
||||
String cashierName,
|
||||
String customerName,
|
||||
int paper,
|
||||
String orderType) async {
|
||||
List<int> bytes = [];
|
||||
|
||||
final profile = await CapabilityProfile.load();
|
||||
final generator =
|
||||
Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile);
|
||||
|
||||
bytes += generator.reset();
|
||||
|
||||
bytes += generator.text('Table Kitchen',
|
||||
styles: const PosStyles(
|
||||
bold: true,
|
||||
align: PosAlign.center,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size2,
|
||||
));
|
||||
bytes += generator.feed(1);
|
||||
if (tableNumber.isNotEmpty) {
|
||||
bytes += generator.text(tableNumber,
|
||||
styles: const PosStyles(
|
||||
bold: true,
|
||||
align: PosAlign.center,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size2,
|
||||
));
|
||||
bytes += generator.feed(1);
|
||||
}
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Date',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
// bytes += generator.text(
|
||||
// 'Date: ${DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now())}',
|
||||
// styles: const PosStyles(bold: false, align: PosAlign.left));
|
||||
//reciept number
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Receipt',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: DateFormat('yyyyMMddhhmm').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Cashier',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: cashierName,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: '$customerName - $draftName',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: orderType,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right, bold: true),
|
||||
),
|
||||
]);
|
||||
|
||||
//----
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
bytes += generator.feed(1);
|
||||
final kitchenProducts =
|
||||
products.where((p) => p.product.printerType == 'kitchen');
|
||||
for (final product in kitchenProducts) {
|
||||
bytes += generator.text('${product.quantity} x ${product.product.name}',
|
||||
styles: const PosStyles(
|
||||
align: PosAlign.left,
|
||||
bold: false,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size1,
|
||||
));
|
||||
if (product.notes.isNotEmpty) {
|
||||
bytes += generator.text(' Notes: ${product.notes}',
|
||||
styles: const PosStyles(
|
||||
align: PosAlign.left,
|
||||
bold: false,
|
||||
height: PosTextSize.size1,
|
||||
width: PosTextSize.size1,
|
||||
fontType: PosFontType.fontA,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
bytes += generator.feed(1);
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1);
|
||||
//cut
|
||||
if (paper == 80) {
|
||||
bytes += generator.cut();
|
||||
}
|
||||
bytes += generator.cut();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
@@ -1662,9 +1542,7 @@ class PrintDataoutputs {
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1);
|
||||
//cut
|
||||
if (paper == 80) {
|
||||
bytes += generator.cut();
|
||||
}
|
||||
bytes += generator.cut();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
@@ -1703,4 +1581,520 @@ class PrintDataoutputs {
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
Future<List<int>> printKitchenAllItem(
|
||||
List<ProductQuantity> products,
|
||||
String tableNumber,
|
||||
String draftName,
|
||||
String cashierName,
|
||||
String customerName,
|
||||
int paper,
|
||||
String orderType) async {
|
||||
List<int> bytes = [];
|
||||
|
||||
final profile = await CapabilityProfile.load();
|
||||
final generator =
|
||||
Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile);
|
||||
|
||||
bytes += generator.reset();
|
||||
|
||||
bytes += generator.text('Table Kitchen',
|
||||
styles: const PosStyles(
|
||||
bold: true,
|
||||
align: PosAlign.center,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size2,
|
||||
));
|
||||
bytes += generator.feed(1);
|
||||
if (tableNumber.isNotEmpty) {
|
||||
bytes += generator.text(tableNumber,
|
||||
styles: const PosStyles(
|
||||
bold: true,
|
||||
align: PosAlign.center,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size2,
|
||||
));
|
||||
bytes += generator.feed(1);
|
||||
}
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Date',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
// bytes += generator.text(
|
||||
// 'Date: ${DateFormat('dd-MM-yyyy HH:mm').format(DateTime.now())}',
|
||||
// styles: const PosStyles(bold: false, align: PosAlign.left));
|
||||
//reciept number
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Receipt',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: DateFormat('yyyyMMddhhmm').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Cashier',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: cashierName,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: '$customerName - $draftName',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: orderType,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right, bold: true),
|
||||
),
|
||||
]);
|
||||
|
||||
//----
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
bytes += generator.feed(1);
|
||||
final kitchenProducts =
|
||||
products.where((p) => p.product.printerType == 'kitchen');
|
||||
for (final product in kitchenProducts) {
|
||||
bytes += generator.text('${product.quantity} x ${product.product.name}',
|
||||
styles: const PosStyles(
|
||||
align: PosAlign.left,
|
||||
bold: false,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size1,
|
||||
));
|
||||
if (product.notes.isNotEmpty) {
|
||||
bytes += generator.text(' Notes: ${product.notes}',
|
||||
styles: const PosStyles(
|
||||
align: PosAlign.left,
|
||||
bold: false,
|
||||
height: PosTextSize.size1,
|
||||
width: PosTextSize.size1,
|
||||
fontType: PosFontType.fontA,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
bytes += generator.feed(1);
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1);
|
||||
bytes += generator.cut();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
Future<List<int>> printKitchenPerProduct(
|
||||
List<ProductQuantity> products,
|
||||
String tableNumber,
|
||||
String draftName,
|
||||
String cashierName,
|
||||
String customerName,
|
||||
int paper,
|
||||
String orderType) async {
|
||||
List<int> allBytes = [];
|
||||
|
||||
final profile = await CapabilityProfile.load();
|
||||
final generator =
|
||||
Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile);
|
||||
|
||||
// Loop untuk setiap produk - print terpisah
|
||||
for (final product in products) {
|
||||
List<int> bytes = [];
|
||||
|
||||
bytes += generator.reset();
|
||||
|
||||
bytes += generator.text('Table Kitchen',
|
||||
styles: const PosStyles(
|
||||
bold: true,
|
||||
align: PosAlign.center,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size2,
|
||||
));
|
||||
bytes += generator.feed(1);
|
||||
|
||||
if (tableNumber.isNotEmpty) {
|
||||
bytes += generator.text(tableNumber,
|
||||
styles: const PosStyles(
|
||||
bold: true,
|
||||
align: PosAlign.center,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size2,
|
||||
));
|
||||
bytes += generator.feed(1);
|
||||
}
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: DateFormat('dd MMM yyyy').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: DateFormat('HH:mm').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: draftName,
|
||||
width: 8,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: '',
|
||||
width: 4,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: customerName,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: orderType,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right, bold: true),
|
||||
),
|
||||
]);
|
||||
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
bytes += generator.feed(1);
|
||||
|
||||
// Print hanya 1 produk per struk
|
||||
bytes += generator.text('${product.quantity} x ${product.product.name}',
|
||||
styles: const PosStyles(
|
||||
align: PosAlign.left,
|
||||
bold: false,
|
||||
height: PosTextSize.size2,
|
||||
width: PosTextSize.size1,
|
||||
));
|
||||
|
||||
if (product.notes.isNotEmpty) {
|
||||
bytes += generator.text(' Notes: ${product.notes}',
|
||||
styles: const PosStyles(
|
||||
align: PosAlign.left,
|
||||
bold: false,
|
||||
height: PosTextSize.size1,
|
||||
width: PosTextSize.size1,
|
||||
fontType: PosFontType.fontA,
|
||||
));
|
||||
}
|
||||
|
||||
bytes += generator.feed(1);
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
|
||||
paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(2);
|
||||
|
||||
bytes += generator.cut();
|
||||
|
||||
// Tambahkan ke allBytes
|
||||
allBytes += bytes;
|
||||
}
|
||||
|
||||
return allBytes;
|
||||
}
|
||||
|
||||
Future<List<int>> printSplitBill(
|
||||
Order order,
|
||||
String chashierName,
|
||||
int paper,
|
||||
Outlet outlet,
|
||||
) async {
|
||||
List<int> bytes = [];
|
||||
|
||||
final profile = await CapabilityProfile.load();
|
||||
final generator =
|
||||
Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile);
|
||||
|
||||
bytes += generator.reset();
|
||||
|
||||
bytes += generator.text(outlet.name ?? "",
|
||||
styles: const PosStyles(
|
||||
bold: true,
|
||||
align: PosAlign.center,
|
||||
height: PosTextSize.size1,
|
||||
width: PosTextSize.size1,
|
||||
));
|
||||
|
||||
bytes += generator.text(outlet.address ?? "",
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
bytes += generator.text(outlet.phoneNumber ?? "",
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: DateFormat('dd MMM yyyy').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: DateFormat('HH:mm').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Receipt Number',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: DateFormat('yyyyMMddhhmm').format(DateTime.now()),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Order ID',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: Random().nextInt(100000).toString(),
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Bill Name',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: order.metadata?['customer_name'] ?? '',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Collected By',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: chashierName,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
if (order.payments != null) {
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Payment',
|
||||
width: 8,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: order.payments?.last.paymentMethodName ?? '-',
|
||||
width: 4,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
bytes += generator.text(order.orderType ?? '-',
|
||||
styles: const PosStyles(bold: true, align: PosAlign.center));
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
bytes += generator.text("SPLIT",
|
||||
styles: const PosStyles(bold: true, align: PosAlign.center));
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
|
||||
for (final item in (order.orderItems ?? <OrderItem>[])) {
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: '${item.quantity} x ${item.productName}',
|
||||
width: 8,
|
||||
styles: const PosStyles(bold: true, align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: (((item.unitPrice ?? 0) * (item.quantity ?? 0)))
|
||||
.currencyFormatRpV2,
|
||||
width: 4,
|
||||
styles: const PosStyles(bold: true, align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
if (item.notes != '') {
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Note',
|
||||
width: 4,
|
||||
styles: const PosStyles(bold: false, align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: item.notes ?? "-",
|
||||
width: 8,
|
||||
styles: const PosStyles(bold: false, align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (order.orderItems?.isNotEmpty ?? false) {
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
}
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Subtotal',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: order.payments?.last.amount?.currencyFormatRpV2 ?? '-',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Discount',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: (order.discountAmount ?? 0).currencyFormatRpV2,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
|
||||
// Only show tax if it's greater than 0
|
||||
if ((order.taxAmount ?? 0) > 0) {
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Tax PB1 (${order.taxAmount}%)',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: (order.taxAmount ?? 0).currencyFormatRpV2,
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
// Only show service charge if it's greater than 0
|
||||
// if (serviceCharge > 0) {
|
||||
// bytes += generator.row([
|
||||
// PosColumn(
|
||||
// text: 'Service Charge($serviceChargePercentage%)',
|
||||
// width: 6,
|
||||
// styles: const PosStyles(align: PosAlign.left),
|
||||
// ),
|
||||
// PosColumn(
|
||||
// text: serviceCharge.currencyFormatRpV2,
|
||||
// width: 6,
|
||||
// styles: const PosStyles(align: PosAlign.right),
|
||||
// ),
|
||||
// ]);
|
||||
// }
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Total',
|
||||
width: 6,
|
||||
styles: const PosStyles(bold: true, align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: order.payments?.last.amount?.currencyFormatRpV2 ?? '-',
|
||||
width: 6,
|
||||
styles: const PosStyles(bold: true, align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: 'Dibayar',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.left),
|
||||
),
|
||||
PosColumn(
|
||||
text: order.payments?.last.amount?.currencyFormatRpV2 ?? '-',
|
||||
width: 6,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
bytes += generator.text(
|
||||
paper == 80
|
||||
? '------------------------------------------------'
|
||||
: '--------------------------------',
|
||||
styles: const PosStyles(bold: false, align: PosAlign.center));
|
||||
paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1);
|
||||
bytes += generator.cut();
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'package:enaklo_pos/core/database/database_handler.dart';
|
||||
import 'package:enaklo_pos/data/models/response/category_response_model.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
class CategoryLocalDatasource {
|
||||
static CategoryLocalDatasource? _instance;
|
||||
|
||||
CategoryLocalDatasource._internal();
|
||||
|
||||
static CategoryLocalDatasource get instance {
|
||||
_instance ??= CategoryLocalDatasource._internal();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
Future<Database> get _db async => await DatabaseHelper.instance.database;
|
||||
|
||||
// ========================================
|
||||
// CACHING SYSTEM
|
||||
// ========================================
|
||||
final Map<String, List<CategoryModel>> _queryCache = {};
|
||||
final Duration _cacheExpiry =
|
||||
Duration(minutes: 10); // Lebih lama untuk categories
|
||||
final Map<String, DateTime> _cacheTimestamps = {};
|
||||
|
||||
// ========================================
|
||||
// BATCH SAVE CATEGORIES
|
||||
// ========================================
|
||||
Future<void> saveCategoriesBatch(List<CategoryModel> categories,
|
||||
{bool clearFirst = false}) async {
|
||||
final db = await _db;
|
||||
|
||||
try {
|
||||
await db.transaction((txn) async {
|
||||
if (clearFirst) {
|
||||
log('🗑️ Clearing existing categories...');
|
||||
await txn.delete('categories');
|
||||
}
|
||||
|
||||
log('💾 Batch saving ${categories.length} categories...');
|
||||
|
||||
// Batch insert categories
|
||||
final batch = txn.batch();
|
||||
for (final category in categories) {
|
||||
batch.insert(
|
||||
'categories',
|
||||
_categoryToMap(category),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
}
|
||||
await batch.commit(noResult: true);
|
||||
});
|
||||
|
||||
// Clear cache after update
|
||||
clearCache();
|
||||
log('✅ Successfully batch saved ${categories.length} categories');
|
||||
} catch (e) {
|
||||
log('❌ Error batch saving categories: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// CACHED QUERY
|
||||
// ========================================
|
||||
Future<List<CategoryModel>> getCachedCategories({
|
||||
int page = 1,
|
||||
int limit = 10,
|
||||
bool isActive = true,
|
||||
String? search,
|
||||
}) async {
|
||||
final cacheKey = _generateCacheKey(page, limit, isActive, search);
|
||||
final now = DateTime.now();
|
||||
|
||||
// Check cache first
|
||||
if (_queryCache.containsKey(cacheKey) &&
|
||||
_cacheTimestamps.containsKey(cacheKey)) {
|
||||
final cacheTime = _cacheTimestamps[cacheKey]!;
|
||||
if (now.difference(cacheTime) < _cacheExpiry) {
|
||||
log('🚀 Cache HIT: $cacheKey (${_queryCache[cacheKey]!.length} categories)');
|
||||
return _queryCache[cacheKey]!;
|
||||
}
|
||||
}
|
||||
|
||||
log('📀 Cache MISS: $cacheKey, querying database...');
|
||||
|
||||
// Cache miss, query database
|
||||
final categories = await getCategories(
|
||||
page: page,
|
||||
limit: limit,
|
||||
isActive: isActive,
|
||||
search: search,
|
||||
);
|
||||
|
||||
// Store in cache
|
||||
_queryCache[cacheKey] = categories;
|
||||
_cacheTimestamps[cacheKey] = now;
|
||||
|
||||
log('💾 Cached ${categories.length} categories for key: $cacheKey');
|
||||
return categories;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// REGULAR GET CATEGORIES
|
||||
// ========================================
|
||||
Future<List<CategoryModel>> getCategories({
|
||||
int page = 1,
|
||||
int limit = 10,
|
||||
bool isActive = true,
|
||||
String? search,
|
||||
}) async {
|
||||
final db = await _db;
|
||||
|
||||
try {
|
||||
String query = 'SELECT * FROM categories WHERE 1=1';
|
||||
List<dynamic> whereArgs = [];
|
||||
|
||||
// Note: Assuming is_active will be added to database schema
|
||||
if (isActive) {
|
||||
query += ' AND is_active = ?';
|
||||
whereArgs.add(1);
|
||||
}
|
||||
|
||||
if (search != null && search.isNotEmpty) {
|
||||
query += ' AND (name LIKE ? OR description LIKE ?)';
|
||||
whereArgs.add('%$search%');
|
||||
whereArgs.add('%$search%');
|
||||
}
|
||||
|
||||
// query += ' ORDER BY name ASC';
|
||||
|
||||
if (limit > 0) {
|
||||
query += ' LIMIT ?';
|
||||
whereArgs.add(limit);
|
||||
|
||||
if (page > 1) {
|
||||
query += ' OFFSET ?';
|
||||
whereArgs.add((page - 1) * limit);
|
||||
}
|
||||
}
|
||||
|
||||
final List<Map<String, dynamic>> maps =
|
||||
await db.rawQuery(query, whereArgs);
|
||||
|
||||
List<CategoryModel> categories = [];
|
||||
for (final map in maps) {
|
||||
categories.add(_mapToCategory(map));
|
||||
}
|
||||
|
||||
log('📊 Retrieved ${categories.length} categories from database');
|
||||
return categories;
|
||||
} catch (e) {
|
||||
log('❌ Error getting categories: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// GET ALL CATEGORIES (For dropdowns)
|
||||
// ========================================
|
||||
Future<List<CategoryModel>> getAllCategories() async {
|
||||
const cacheKey = 'all_categories';
|
||||
final now = DateTime.now();
|
||||
|
||||
// Check cache
|
||||
if (_queryCache.containsKey(cacheKey) &&
|
||||
_cacheTimestamps.containsKey(cacheKey)) {
|
||||
final cacheTime = _cacheTimestamps[cacheKey]!;
|
||||
if (now.difference(cacheTime) < _cacheExpiry) {
|
||||
return _queryCache[cacheKey]!;
|
||||
}
|
||||
}
|
||||
|
||||
final db = await _db;
|
||||
|
||||
try {
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'categories',
|
||||
orderBy: 'name ASC',
|
||||
);
|
||||
|
||||
final categories = maps.map((map) => _mapToCategory(map)).toList();
|
||||
|
||||
// Cache all categories
|
||||
_queryCache[cacheKey] = categories;
|
||||
_cacheTimestamps[cacheKey] = now;
|
||||
|
||||
log('📊 Retrieved ${categories.length} total categories');
|
||||
return categories;
|
||||
} catch (e) {
|
||||
log('❌ Error getting all categories: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// GET CATEGORY BY ID
|
||||
// ========================================
|
||||
Future<CategoryModel?> getCategoryById(String id) async {
|
||||
final db = await _db;
|
||||
|
||||
try {
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'categories',
|
||||
where: 'id = ?',
|
||||
whereArgs: [id],
|
||||
);
|
||||
|
||||
if (maps.isEmpty) {
|
||||
log('❌ Category not found: $id');
|
||||
return null;
|
||||
}
|
||||
|
||||
final category = _mapToCategory(maps.first);
|
||||
log('✅ Category found: ${category.name}');
|
||||
return category;
|
||||
} catch (e) {
|
||||
log('❌ Error getting category by ID: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// GET TOTAL COUNT
|
||||
// ========================================
|
||||
Future<int> getTotalCount({bool isActive = true, String? search}) async {
|
||||
final db = await _db;
|
||||
|
||||
try {
|
||||
String query = 'SELECT COUNT(*) FROM categories WHERE 1=1';
|
||||
List<dynamic> whereArgs = [];
|
||||
|
||||
if (isActive) {
|
||||
query += ' AND is_active = ?';
|
||||
whereArgs.add(1);
|
||||
}
|
||||
|
||||
if (search != null && search.isNotEmpty) {
|
||||
query += ' AND (name LIKE ? OR description LIKE ?)';
|
||||
whereArgs.add('%$search%');
|
||||
whereArgs.add('%$search%');
|
||||
}
|
||||
|
||||
final result = await db.rawQuery(query, whereArgs);
|
||||
final count = Sqflite.firstIntValue(result) ?? 0;
|
||||
log('📊 Category total count: $count (isActive: $isActive, search: $search)');
|
||||
return count;
|
||||
} catch (e) {
|
||||
log('❌ Error getting category total count: $e');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// HAS CATEGORIES
|
||||
// ========================================
|
||||
Future<bool> hasCategories() async {
|
||||
final count = await getTotalCount();
|
||||
final hasData = count > 0;
|
||||
log('🔍 Has categories: $hasData ($count categories)');
|
||||
return hasData;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// CLEAR ALL CATEGORIES
|
||||
// ========================================
|
||||
Future<void> clearAllCategories() async {
|
||||
final db = await _db;
|
||||
|
||||
try {
|
||||
await db.delete('categories');
|
||||
clearCache();
|
||||
log('🗑️ All categories cleared from local DB');
|
||||
} catch (e) {
|
||||
log('❌ Error clearing categories: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// CACHE MANAGEMENT
|
||||
// ========================================
|
||||
String _generateCacheKey(int page, int limit, bool isActive, String? search) {
|
||||
return 'categories_${page}_${limit}_${isActive}_${search ?? 'null'}';
|
||||
}
|
||||
|
||||
void clearCache() {
|
||||
final count = _queryCache.length;
|
||||
_queryCache.clear();
|
||||
_cacheTimestamps.clear();
|
||||
log('🧹 Category cache cleared: $count entries removed');
|
||||
}
|
||||
|
||||
void clearExpiredCache() {
|
||||
final now = DateTime.now();
|
||||
final expiredKeys = <String>[];
|
||||
|
||||
_cacheTimestamps.forEach((key, timestamp) {
|
||||
if (now.difference(timestamp) > _cacheExpiry) {
|
||||
expiredKeys.add(key);
|
||||
}
|
||||
});
|
||||
|
||||
for (final key in expiredKeys) {
|
||||
_queryCache.remove(key);
|
||||
_cacheTimestamps.remove(key);
|
||||
}
|
||||
|
||||
if (expiredKeys.isNotEmpty) {
|
||||
log('⏰ Expired category cache cleared: ${expiredKeys.length} entries');
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// DATABASE STATS
|
||||
// ========================================
|
||||
Future<Map<String, dynamic>> getDatabaseStats() async {
|
||||
final db = await _db;
|
||||
|
||||
try {
|
||||
final categoryCount = Sqflite.firstIntValue(
|
||||
await db.rawQuery('SELECT COUNT(*) FROM categories')) ??
|
||||
0;
|
||||
|
||||
final activeCount = Sqflite.firstIntValue(await db.rawQuery(
|
||||
'SELECT COUNT(*) FROM categories WHERE is_active = 1')) ??
|
||||
0;
|
||||
|
||||
final stats = {
|
||||
'total_categories': categoryCount,
|
||||
'active_categories': activeCount,
|
||||
'cache_entries': _queryCache.length,
|
||||
};
|
||||
|
||||
log('📊 Category Database Stats: $stats');
|
||||
return stats;
|
||||
} catch (e) {
|
||||
log('❌ Error getting category database stats: $e');
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// HELPER METHODS
|
||||
// ========================================
|
||||
Map<String, dynamic> _categoryToMap(CategoryModel category) {
|
||||
return {
|
||||
'id': category.id,
|
||||
'organization_id': category.organizationId,
|
||||
'name': category.name,
|
||||
'description': category.description,
|
||||
'business_type': category.businessType,
|
||||
'metadata': json.encode(category.metadata),
|
||||
'is_active': 1, // Assuming all synced categories are active
|
||||
'created_at': category.createdAt.toIso8601String(),
|
||||
'updated_at': category.updatedAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
CategoryModel _mapToCategory(Map<String, dynamic> map) {
|
||||
return CategoryModel(
|
||||
id: map['id'],
|
||||
organizationId: map['organization_id'],
|
||||
name: map['name'],
|
||||
description: map['description'],
|
||||
businessType: map['business_type'],
|
||||
metadata: map['metadata'] != null ? json.decode(map['metadata']) : {},
|
||||
createdAt: DateTime.parse(map['created_at']),
|
||||
updatedAt: DateTime.parse(map['updated_at']),
|
||||
);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -2,12 +2,12 @@ import 'dart:developer';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:enaklo_pos/core/network/dio_client.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet/outlet_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart';
|
||||
import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
|
||||
import 'package:enaklo_pos/presentation/setting/models/tax_model.dart';
|
||||
import '../../core/constants/variables.dart';
|
||||
import 'auth_local_datasource.dart';
|
||||
import '../../../core/constants/variables.dart';
|
||||
import '../auth_local_datasource.dart';
|
||||
|
||||
class OutletRemoteDataSource {
|
||||
final Dio dio = DioClient.instance;
|
||||
@@ -2,9 +2,11 @@ import 'dart:convert';
|
||||
|
||||
class AuthResponseModel {
|
||||
final String? token;
|
||||
final String? refreshToken;
|
||||
final User? user;
|
||||
|
||||
AuthResponseModel({
|
||||
this.refreshToken,
|
||||
this.token,
|
||||
this.user,
|
||||
});
|
||||
@@ -17,11 +19,13 @@ class AuthResponseModel {
|
||||
factory AuthResponseModel.fromMap(Map<String, dynamic> json) =>
|
||||
AuthResponseModel(
|
||||
token: json["token"],
|
||||
refreshToken: json["refresh_token"],
|
||||
user: json["user"] == null ? null : User.fromMap(json["user"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
"token": token,
|
||||
"refresh_token": refreshToken,
|
||||
"user": user?.toMap(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -117,4 +117,14 @@ class CategoryModel {
|
||||
'updated_at': updatedAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
factory CategoryModel.all() => CategoryModel(
|
||||
id: 'all',
|
||||
organizationId: '',
|
||||
name: 'Semua',
|
||||
businessType: 'restaurant',
|
||||
metadata: {},
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -401,3 +401,103 @@ extension OrderItemListExtension on List<OrderItem> {
|
||||
quantity: e.quantity ?? 0,
|
||||
)).toList();
|
||||
}
|
||||
|
||||
extension OrderCopyWith on Order {
|
||||
Order copyWith({
|
||||
String? id,
|
||||
String? orderNumber,
|
||||
String? outletId,
|
||||
String? userId,
|
||||
String? tableNumber,
|
||||
String? orderType,
|
||||
String? status,
|
||||
int? subtotal,
|
||||
int? taxAmount,
|
||||
int? discountAmount,
|
||||
int? totalAmount,
|
||||
num? totalCost,
|
||||
int? remainingAmount,
|
||||
String? paymentStatus,
|
||||
int? refundAmount,
|
||||
bool? isVoid,
|
||||
bool? isRefund,
|
||||
String? notes,
|
||||
Map<String, dynamic>? metadata,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
List<OrderItem>? orderItems,
|
||||
List<Payment>? payments,
|
||||
int? totalPaid,
|
||||
int? paymentCount,
|
||||
String? splitType,
|
||||
}) {
|
||||
return Order(
|
||||
id: id ?? this.id,
|
||||
orderNumber: orderNumber ?? this.orderNumber,
|
||||
outletId: outletId ?? this.outletId,
|
||||
userId: userId ?? this.userId,
|
||||
tableNumber: tableNumber ?? this.tableNumber,
|
||||
orderType: orderType ?? this.orderType,
|
||||
status: status ?? this.status,
|
||||
subtotal: subtotal ?? this.subtotal,
|
||||
taxAmount: taxAmount ?? this.taxAmount,
|
||||
discountAmount: discountAmount ?? this.discountAmount,
|
||||
totalAmount: totalAmount ?? this.totalAmount,
|
||||
totalCost: totalCost ?? this.totalCost,
|
||||
remainingAmount: remainingAmount ?? this.remainingAmount,
|
||||
paymentStatus: paymentStatus ?? this.paymentStatus,
|
||||
refundAmount: refundAmount ?? this.refundAmount,
|
||||
isVoid: isVoid ?? this.isVoid,
|
||||
isRefund: isRefund ?? this.isRefund,
|
||||
notes: notes ?? this.notes,
|
||||
metadata: metadata ?? this.metadata,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
orderItems: orderItems ?? this.orderItems,
|
||||
payments: payments ?? this.payments,
|
||||
totalPaid: totalPaid ?? this.totalPaid,
|
||||
paymentCount: paymentCount ?? this.paymentCount,
|
||||
splitType: splitType ?? this.splitType,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension OrderItemCopyWith on OrderItem {
|
||||
OrderItem copyWith({
|
||||
String? id,
|
||||
String? orderId,
|
||||
String? productId,
|
||||
String? productName,
|
||||
String? productVariantId,
|
||||
String? productVariantName,
|
||||
int? quantity,
|
||||
int? unitPrice,
|
||||
int? totalPrice,
|
||||
List<dynamic>? modifiers,
|
||||
String? notes,
|
||||
String? status,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
String? printerType,
|
||||
int? paidQuantity,
|
||||
}) {
|
||||
return OrderItem(
|
||||
id: id ?? this.id,
|
||||
orderId: orderId ?? this.orderId,
|
||||
productId: productId ?? this.productId,
|
||||
productName: productName ?? this.productName,
|
||||
productVariantId: productVariantId ?? this.productVariantId,
|
||||
productVariantName: productVariantName ?? this.productVariantName,
|
||||
quantity: quantity ?? this.quantity,
|
||||
unitPrice: unitPrice ?? this.unitPrice,
|
||||
totalPrice: totalPrice ?? this.totalPrice,
|
||||
modifiers: modifiers ?? this.modifiers,
|
||||
notes: notes ?? this.notes,
|
||||
status: status ?? this.status,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
printerType: printerType ?? this.printerType,
|
||||
paidQuantity: paidQuantity ?? this.paidQuantity,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
import 'dart:developer';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:enaklo_pos/data/datasources/category/category_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/category/category_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/category_response_model.dart';
|
||||
|
||||
class CategoryRepository {
|
||||
static CategoryRepository? _instance;
|
||||
|
||||
final CategoryLocalDatasource _localDatasource;
|
||||
final CategoryRemoteDatasource _remoteDatasource;
|
||||
|
||||
CategoryRepository._internal()
|
||||
: _localDatasource = CategoryLocalDatasource.instance,
|
||||
_remoteDatasource = CategoryRemoteDatasource();
|
||||
|
||||
static CategoryRepository get instance {
|
||||
_instance ??= CategoryRepository._internal();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// SYNC STRATEGY: REMOTE-FIRST WITH LOCAL FALLBACK
|
||||
// ========================================
|
||||
Future<Either<String, CategoryResponseModel>> getCategories({
|
||||
int page = 1,
|
||||
int limit = 10,
|
||||
bool isActive = true,
|
||||
String? search,
|
||||
bool forceRemote = false,
|
||||
}) async {
|
||||
try {
|
||||
log('📱 Getting categories - page: $page, isActive: $isActive, search: $search, forceRemote: $forceRemote');
|
||||
|
||||
// Clean expired cache
|
||||
_localDatasource.clearExpiredCache();
|
||||
|
||||
// Check if we should try remote first
|
||||
if (forceRemote || !await _localDatasource.hasCategories()) {
|
||||
log('🌐 Attempting remote fetch first...');
|
||||
|
||||
final remoteResult = await _getRemoteCategories(
|
||||
page: page,
|
||||
limit: limit,
|
||||
isActive: isActive,
|
||||
);
|
||||
|
||||
return await remoteResult.fold(
|
||||
(failure) async {
|
||||
log('❌ Remote fetch failed: $failure');
|
||||
log('📱 Falling back to local data...');
|
||||
return _getLocalCategories(
|
||||
page: page,
|
||||
limit: limit,
|
||||
isActive: isActive,
|
||||
search: search,
|
||||
);
|
||||
},
|
||||
(response) async {
|
||||
log('✅ Remote fetch successful, syncing to local...');
|
||||
|
||||
// Sync remote data to local
|
||||
if (response.data.categories.isNotEmpty) {
|
||||
await _syncToLocal(response.data.categories,
|
||||
clearFirst: page == 1);
|
||||
}
|
||||
|
||||
return Right(response);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
log('📱 Using local data (cache available)...');
|
||||
return _getLocalCategories(
|
||||
page: page,
|
||||
limit: limit,
|
||||
isActive: isActive,
|
||||
search: search,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
log('❌ Error in getCategories: $e');
|
||||
return Left('Gagal memuat kategori: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// PURE LOCAL OPERATIONS
|
||||
// ========================================
|
||||
Future<Either<String, CategoryResponseModel>> _getLocalCategories({
|
||||
int page = 1,
|
||||
int limit = 10,
|
||||
bool isActive = true,
|
||||
String? search,
|
||||
}) async {
|
||||
try {
|
||||
final cachedCategories = await _localDatasource.getCachedCategories(
|
||||
page: page,
|
||||
limit: limit,
|
||||
isActive: isActive,
|
||||
search: search,
|
||||
);
|
||||
|
||||
final totalCount = await _localDatasource.getTotalCount(
|
||||
isActive: isActive,
|
||||
search: search,
|
||||
);
|
||||
|
||||
final categoryData = CategoryData(
|
||||
categories: cachedCategories,
|
||||
totalCount: totalCount,
|
||||
page: page,
|
||||
limit: limit,
|
||||
totalPages: totalCount > 0 ? (totalCount / limit).ceil() : 0,
|
||||
);
|
||||
|
||||
final response = CategoryResponseModel(
|
||||
success: true,
|
||||
data: categoryData,
|
||||
);
|
||||
|
||||
log('✅ Returned ${cachedCategories.length} local categories (${totalCount} total)');
|
||||
return Right(response);
|
||||
} catch (e) {
|
||||
log('❌ Error getting local categories: $e');
|
||||
return Left('Gagal memuat kategori dari database lokal: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// REMOTE FETCH
|
||||
// ========================================
|
||||
Future<Either<String, CategoryResponseModel>> _getRemoteCategories({
|
||||
int page = 1,
|
||||
int limit = 10,
|
||||
bool isActive = true,
|
||||
}) async {
|
||||
try {
|
||||
log('🌐 Fetching categories from remote...');
|
||||
return await _remoteDatasource.getCategories(
|
||||
page: page,
|
||||
limit: limit,
|
||||
isActive: isActive,
|
||||
);
|
||||
} catch (e) {
|
||||
log('❌ Remote fetch error: $e');
|
||||
return Left('Gagal mengambil data dari server: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// SYNC TO LOCAL
|
||||
// ========================================
|
||||
Future<void> _syncToLocal(List<CategoryModel> categories,
|
||||
{bool clearFirst = false}) async {
|
||||
try {
|
||||
log('💾 Syncing ${categories.length} categories to local database...');
|
||||
await _localDatasource.saveCategoriesBatch(categories,
|
||||
clearFirst: clearFirst);
|
||||
log('✅ Categories synced to local successfully');
|
||||
} catch (e) {
|
||||
log('❌ Error syncing categories to local: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// MANUAL SYNC OPERATIONS
|
||||
// ========================================
|
||||
Future<Either<String, String>> syncAllCategories() async {
|
||||
try {
|
||||
log('🔄 Starting manual sync of all categories...');
|
||||
|
||||
int page = 1;
|
||||
const limit = 50; // Higher limit for bulk sync
|
||||
bool hasMore = true;
|
||||
int totalSynced = 0;
|
||||
|
||||
// Clear local data first for fresh sync
|
||||
await _localDatasource.clearAllCategories();
|
||||
|
||||
while (hasMore) {
|
||||
log('📄 Syncing page $page...');
|
||||
|
||||
final result = await _remoteDatasource.getCategories(
|
||||
page: page,
|
||||
limit: limit,
|
||||
isActive: true,
|
||||
);
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
log('❌ Sync failed at page $page: $failure');
|
||||
throw Exception(failure);
|
||||
},
|
||||
(response) async {
|
||||
final categories = response.data.categories;
|
||||
|
||||
if (categories.isNotEmpty) {
|
||||
await _localDatasource.saveCategoriesBatch(
|
||||
categories,
|
||||
clearFirst: false, // Don't clear on subsequent pages
|
||||
);
|
||||
totalSynced += categories.length;
|
||||
|
||||
// Check if we have more pages
|
||||
hasMore = page < response.data.totalPages;
|
||||
page++;
|
||||
|
||||
log('📦 Page $page synced: ${categories.length} categories');
|
||||
} else {
|
||||
hasMore = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
final message = 'Berhasil sinkronisasi $totalSynced kategori';
|
||||
log('✅ $message');
|
||||
return Right(message);
|
||||
} catch (e) {
|
||||
final error = 'Gagal sinkronisasi kategori: $e';
|
||||
log('❌ $error');
|
||||
return Left(error);
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// UTILITY METHODS
|
||||
// ========================================
|
||||
Future<Either<String, CategoryResponseModel>> refreshCategories({
|
||||
bool isActive = true,
|
||||
String? search,
|
||||
}) async {
|
||||
log('🔄 Refreshing categories...');
|
||||
clearCache();
|
||||
|
||||
return await getCategories(
|
||||
page: 1,
|
||||
limit: 10,
|
||||
isActive: isActive,
|
||||
search: search,
|
||||
forceRemote: true, // Force remote refresh
|
||||
);
|
||||
}
|
||||
|
||||
Future<CategoryModel?> getCategoryById(String id) async {
|
||||
log('🔍 Getting category by ID: $id');
|
||||
return await _localDatasource.getCategoryById(id);
|
||||
}
|
||||
|
||||
Future<List<CategoryModel>> getAllCategories() async {
|
||||
log('📋 Getting all categories for dropdown...');
|
||||
return await _localDatasource.getAllCategories();
|
||||
}
|
||||
|
||||
Future<bool> hasLocalCategories() async {
|
||||
final hasCategories = await _localDatasource.hasCategories();
|
||||
log('📊 Has local categories: $hasCategories');
|
||||
return hasCategories;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getDatabaseStats() async {
|
||||
final stats = await _localDatasource.getDatabaseStats();
|
||||
log('📊 Category database stats: $stats');
|
||||
return stats;
|
||||
}
|
||||
|
||||
void clearCache() {
|
||||
log('🧹 Clearing category cache');
|
||||
_localDatasource.clearCache();
|
||||
}
|
||||
|
||||
Future<bool> isLocalDatabaseReady() async {
|
||||
try {
|
||||
final stats = await getDatabaseStats();
|
||||
final categoryCount = stats['total_categories'] ?? 0;
|
||||
final isReady = categoryCount > 0;
|
||||
log('🔍 Category database ready: $isReady ($categoryCount categories)');
|
||||
return isReady;
|
||||
} catch (e) {
|
||||
log('❌ Error checking category database readiness: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearAllCategories() async {
|
||||
try {
|
||||
log('🗑️ Clearing all categories from repository...');
|
||||
await _localDatasource.clearAllCategories();
|
||||
clearCache();
|
||||
log('✅ All categories cleared successfully');
|
||||
} catch (e) {
|
||||
log('❌ Error clearing all categories: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,18 @@
|
||||
import 'dart:developer';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:enaklo_pos/data/datasources/product/product_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/product_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/product_response_model.dart';
|
||||
|
||||
class ProductRepository {
|
||||
static ProductRepository? _instance;
|
||||
|
||||
final ProductLocalDatasource _localDatasource;
|
||||
final ProductRemoteDatasource _remoteDatasource;
|
||||
|
||||
ProductRepository._internal()
|
||||
: _localDatasource = ProductLocalDatasource.instance;
|
||||
: _localDatasource = ProductLocalDatasource.instance,
|
||||
_remoteDatasource = ProductRemoteDatasource();
|
||||
|
||||
static ProductRepository get instance {
|
||||
_instance ??= ProductRepository._internal();
|
||||
@@ -85,6 +88,66 @@ class ProductRepository {
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// PRODUCT SYNC OPERATIONS
|
||||
// ========================================
|
||||
Future<Either<String, String>> syncAllProducts() async {
|
||||
try {
|
||||
log('🔄 Starting manual sync of all products...');
|
||||
|
||||
int page = 1;
|
||||
const limit = 50; // Higher limit for bulk sync
|
||||
bool hasMore = true;
|
||||
int totalSynced = 0;
|
||||
|
||||
// Clear local data first for fresh sync
|
||||
await _localDatasource.clearAllProducts();
|
||||
|
||||
while (hasMore) {
|
||||
log('📄 Syncing page $page...');
|
||||
|
||||
final result = await _remoteDatasource.getProducts(
|
||||
page: page,
|
||||
limit: limit,
|
||||
);
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
log('❌ Sync failed at page $page: $failure');
|
||||
throw Exception(failure);
|
||||
},
|
||||
(response) async {
|
||||
final products = response.data?.products ?? [];
|
||||
|
||||
if (products.isNotEmpty) {
|
||||
await _localDatasource.saveProductsBatch(
|
||||
products,
|
||||
clearFirst: false, // Don't clear on subsequent pages
|
||||
);
|
||||
totalSynced += products.length;
|
||||
|
||||
// Check if we have more pages
|
||||
hasMore = page < (response.data?.totalPages ?? 0);
|
||||
page++;
|
||||
|
||||
log('📦 Page $page synced: ${products.length} products');
|
||||
} else {
|
||||
hasMore = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
final message = 'Berhasil sinkronisasi $totalSynced produk';
|
||||
log('✅ $message');
|
||||
return Right(message);
|
||||
} catch (e) {
|
||||
final error = 'Gagal sinkronisasi produk: $e';
|
||||
log('❌ $error');
|
||||
return Left(error);
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// LOCAL DATABASE OPERATIONS
|
||||
// ========================================
|
||||
@@ -142,4 +205,16 @@ class ProductRepository {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearAllProducts() async {
|
||||
try {
|
||||
log('🗑️ Clearing all products from repository...');
|
||||
await _localDatasource.clearAllProducts();
|
||||
clearCache();
|
||||
log('✅ All products cleared successfully');
|
||||
} catch (e) {
|
||||
log('❌ Error clearing all products: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ import 'package:enaklo_pos/core/network/dio_client.dart';
|
||||
import 'package:enaklo_pos/data/datasources/analytic_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/customer_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/file_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet_remote_data_source.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet/outlet_remote_data_source.dart';
|
||||
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/user_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/presentation/customer/bloc/customer_form/customer_form_bloc.dart';
|
||||
@@ -34,7 +34,7 @@ import 'package:firebase_crashlytics/firebase_crashlytics.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';
|
||||
import 'package:enaklo_pos/data/datasources/category_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/category/category_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/discount_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/midtrans_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart';
|
||||
@@ -275,7 +275,7 @@ class _MyAppState extends State<MyApp> {
|
||||
create: (context) => UploadFileBloc(FileRemoteDataSource()),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => CategoryLoaderBloc(CategoryRemoteDatasource()),
|
||||
create: (context) => CategoryLoaderBloc(),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => GetPrinterTicketBloc(),
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dart:async';
|
||||
import 'dart:developer';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:enaklo_pos/data/datasources/product/product_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/category/category_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/repositories/category/category_repository.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import '../../../data/datasources/product_remote_datasource.dart';
|
||||
|
||||
@@ -9,7 +11,7 @@ part 'data_sync_event.dart';
|
||||
part 'data_sync_state.dart';
|
||||
part 'data_sync_bloc.freezed.dart';
|
||||
|
||||
enum SyncStep { products, categories, variants, completed }
|
||||
enum SyncStep { categories, products, variants, completed }
|
||||
|
||||
class SyncStats {
|
||||
final int totalProducts;
|
||||
@@ -26,9 +28,13 @@ class SyncStats {
|
||||
}
|
||||
|
||||
class DataSyncBloc extends Bloc<DataSyncEvent, DataSyncState> {
|
||||
final ProductRemoteDatasource _remoteDatasource = ProductRemoteDatasource();
|
||||
final ProductLocalDatasource _localDatasource =
|
||||
final ProductRemoteDatasource _productRemoteDatasource =
|
||||
ProductRemoteDatasource();
|
||||
final ProductLocalDatasource _productLocalDatasource =
|
||||
ProductLocalDatasource.instance;
|
||||
final CategoryLocalDatasource _categoryLocalDatasource =
|
||||
CategoryLocalDatasource.instance;
|
||||
final CategoryRepository _categoryRepository = CategoryRepository.instance;
|
||||
|
||||
Timer? _progressTimer;
|
||||
bool _isCancelled = false;
|
||||
@@ -48,36 +54,75 @@ class DataSyncBloc extends Bloc<DataSyncEvent, DataSyncState> {
|
||||
_StartSync event,
|
||||
Emitter<DataSyncState> emit,
|
||||
) async {
|
||||
log('🔄 Starting data sync...');
|
||||
log('🔄 Starting full data sync (categories + products)...');
|
||||
_isCancelled = false;
|
||||
|
||||
try {
|
||||
// Step 1: Clear existing local data
|
||||
emit(const DataSyncState.syncing(
|
||||
SyncStep.products, 0.1, 'Membersihkan data lama...'));
|
||||
await _localDatasource.clearAllProducts();
|
||||
SyncStep.categories, 0.05, 'Membersihkan data lama...'));
|
||||
|
||||
await _productLocalDatasource.clearAllProducts();
|
||||
await _categoryLocalDatasource.clearAllCategories();
|
||||
|
||||
if (_isCancelled) return;
|
||||
|
||||
// Step 2: Sync products
|
||||
// Step 2: Sync categories first (products depend on categories)
|
||||
await _syncCategories(emit);
|
||||
|
||||
if (_isCancelled) return;
|
||||
|
||||
// Step 3: Sync products
|
||||
await _syncProducts(emit);
|
||||
|
||||
if (_isCancelled) return;
|
||||
|
||||
// Step 3: Generate final stats
|
||||
// Step 4: Generate final stats
|
||||
emit(const DataSyncState.syncing(
|
||||
SyncStep.completed, 0.9, 'Menyelesaikan sinkronisasi...'));
|
||||
SyncStep.completed, 0.95, 'Menyelesaikan sinkronisasi...'));
|
||||
|
||||
final stats = await _generateSyncStats();
|
||||
|
||||
emit(DataSyncState.completed(stats));
|
||||
log('✅ Sync completed successfully');
|
||||
log('✅ Full sync completed successfully');
|
||||
} catch (e) {
|
||||
log('❌ Sync failed: $e');
|
||||
emit(DataSyncState.error('Gagal sinkronisasi: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _syncCategories(Emitter<DataSyncState> emit) async {
|
||||
log('📁 Syncing categories...');
|
||||
|
||||
emit(const DataSyncState.syncing(
|
||||
SyncStep.categories,
|
||||
0.1,
|
||||
'Mengunduh kategori...',
|
||||
));
|
||||
|
||||
try {
|
||||
// Use CategoryRepository sync method
|
||||
final result = await _categoryRepository.syncAllCategories();
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
throw Exception('Gagal sync kategori: $failure');
|
||||
},
|
||||
(successMessage) async {
|
||||
log('✅ Categories sync completed: $successMessage');
|
||||
emit(const DataSyncState.syncing(
|
||||
SyncStep.categories,
|
||||
0.2,
|
||||
'Kategori berhasil diunduh',
|
||||
));
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
log('❌ Category sync failed: $e');
|
||||
throw Exception('Gagal sync kategori: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _syncProducts(Emitter<DataSyncState> emit) async {
|
||||
log('📦 Syncing products...');
|
||||
|
||||
@@ -88,10 +133,10 @@ class DataSyncBloc extends Bloc<DataSyncEvent, DataSyncState> {
|
||||
bool shouldContinue = true;
|
||||
|
||||
while (!_isCancelled && shouldContinue) {
|
||||
// Calculate accurate progress based on total count
|
||||
// Calculate accurate progress (categories = 0.2, products = 0.2-0.9)
|
||||
double progress = 0.2;
|
||||
if (totalCount != null && (totalCount ?? 0) > 0) {
|
||||
progress = 0.2 + (totalSynced / (totalCount ?? 0)) * 0.6;
|
||||
progress = 0.2 + (totalSynced / (totalCount ?? 0)) * 0.7;
|
||||
}
|
||||
|
||||
emit(DataSyncState.syncing(
|
||||
@@ -102,7 +147,7 @@ class DataSyncBloc extends Bloc<DataSyncEvent, DataSyncState> {
|
||||
: 'Mengunduh produk... ($totalSynced produk)',
|
||||
));
|
||||
|
||||
final result = await _remoteDatasource.getProducts(
|
||||
final result = await _productRemoteDatasource.getProducts(
|
||||
page: page,
|
||||
limit: 50, // Bigger batch for sync
|
||||
);
|
||||
@@ -128,7 +173,7 @@ class DataSyncBloc extends Bloc<DataSyncEvent, DataSyncState> {
|
||||
}
|
||||
|
||||
// Save to local database in batches
|
||||
await _localDatasource.saveProductsBatch(products);
|
||||
await _productLocalDatasource.saveProductsBatch(products);
|
||||
|
||||
totalSynced += products.length;
|
||||
page++;
|
||||
@@ -154,8 +199,8 @@ class DataSyncBloc extends Bloc<DataSyncEvent, DataSyncState> {
|
||||
}
|
||||
|
||||
emit(DataSyncState.syncing(
|
||||
SyncStep.completed,
|
||||
0.8,
|
||||
SyncStep.products,
|
||||
0.9,
|
||||
'Produk berhasil diunduh ($totalSynced dari ${totalCount ?? totalSynced})',
|
||||
));
|
||||
|
||||
@@ -163,13 +208,15 @@ class DataSyncBloc extends Bloc<DataSyncEvent, DataSyncState> {
|
||||
}
|
||||
|
||||
Future<SyncStats> _generateSyncStats() async {
|
||||
final dbStats = await _localDatasource.getDatabaseStats();
|
||||
final productStats = await _productLocalDatasource.getDatabaseStats();
|
||||
final categoryStats = await _categoryLocalDatasource.getDatabaseStats();
|
||||
|
||||
return SyncStats(
|
||||
totalProducts: dbStats['total_products'] ?? 0,
|
||||
totalCategories: dbStats['total_categories'] ?? 0,
|
||||
totalVariants: dbStats['total_variants'] ?? 0,
|
||||
databaseSizeMB: dbStats['database_size_mb'] ?? 0.0,
|
||||
totalProducts: productStats['total_products'] ?? 0,
|
||||
totalCategories: categoryStats['total_categories'] ?? 0,
|
||||
totalVariants: productStats['total_variants'] ?? 0,
|
||||
databaseSizeMB: (productStats['database_size_mb'] ?? 0.0) +
|
||||
(categoryStats['database_size_mb'] ?? 0.0),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,20 +87,15 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
);
|
||||
}
|
||||
|
||||
// Portrait layout (original)
|
||||
// Portrait layout
|
||||
Widget _buildPortraitLayout(DataSyncState state, double screenHeight) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: screenHeight * 0.08), // Responsive spacing
|
||||
|
||||
// Header
|
||||
_buildHeader(false),
|
||||
|
||||
SizedBox(height: screenHeight * 0.08),
|
||||
|
||||
// Sync progress
|
||||
_buildHeader(false),
|
||||
SizedBox(height: screenHeight * 0.08),
|
||||
Expanded(
|
||||
child: state.when(
|
||||
initial: () => _buildInitialState(false),
|
||||
@@ -110,24 +105,20 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
error: (message) => _buildErrorState(message, false),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 20),
|
||||
|
||||
// Actions
|
||||
_buildActions(state),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Landscape layout (side by side)
|
||||
// Landscape layout
|
||||
Widget _buildLandscapeLayout(
|
||||
DataSyncState state, double screenWidth, double screenHeight) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 32, vertical: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
// Left side - Header and info
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
@@ -139,10 +130,7 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(width: 40),
|
||||
|
||||
// Right side - Sync progress
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Container(
|
||||
@@ -188,7 +176,7 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
),
|
||||
SizedBox(height: isLandscape ? 4 : 8),
|
||||
Text(
|
||||
'Mengunduh data terbaru ke perangkat',
|
||||
'Mengunduh kategori dan produk terbaru',
|
||||
style: TextStyle(
|
||||
fontSize: isLandscape ? 14 : 16,
|
||||
color: Colors.grey.shade600,
|
||||
@@ -319,8 +307,8 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
|
||||
Widget _buildStepIndicator(SyncStep currentStep, bool isLandscape) {
|
||||
final steps = [
|
||||
('Produk', SyncStep.products, Icons.inventory_2),
|
||||
('Kategori', SyncStep.categories, Icons.category),
|
||||
('Produk', SyncStep.products, Icons.inventory_2),
|
||||
('Variant', SyncStep.variants, Icons.tune),
|
||||
('Selesai', SyncStep.completed, Icons.check_circle),
|
||||
];
|
||||
@@ -551,11 +539,11 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
// Vertical layout for landscape
|
||||
Column(
|
||||
children: [
|
||||
_buildStatItem('Produk', '${stats.totalProducts}',
|
||||
Icons.inventory_2, Colors.blue, isLandscape),
|
||||
SizedBox(height: 8),
|
||||
_buildStatItem('Kategori', '${stats.totalCategories}',
|
||||
Icons.category, Colors.green, isLandscape),
|
||||
Icons.category, Colors.blue, isLandscape),
|
||||
SizedBox(height: 8),
|
||||
_buildStatItem('Produk', '${stats.totalProducts}',
|
||||
Icons.inventory_2, Colors.green, isLandscape),
|
||||
SizedBox(height: 8),
|
||||
_buildStatItem('Variant', '${stats.totalVariants}',
|
||||
Icons.tune, Colors.orange, isLandscape),
|
||||
@@ -566,10 +554,10 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildStatItem('Produk', '${stats.totalProducts}',
|
||||
Icons.inventory_2, Colors.blue, isLandscape),
|
||||
_buildStatItem('Kategori', '${stats.totalCategories}',
|
||||
Icons.category, Colors.green, isLandscape),
|
||||
Icons.category, Colors.blue, isLandscape),
|
||||
_buildStatItem('Produk', '${stats.totalProducts}',
|
||||
Icons.inventory_2, Colors.green, isLandscape),
|
||||
_buildStatItem('Variant', '${stats.totalVariants}',
|
||||
Icons.tune, Colors.orange, isLandscape),
|
||||
],
|
||||
@@ -765,10 +753,10 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
|
||||
IconData _getSyncIcon(SyncStep step) {
|
||||
switch (step) {
|
||||
case SyncStep.products:
|
||||
return Icons.inventory_2;
|
||||
case SyncStep.categories:
|
||||
return Icons.category;
|
||||
case SyncStep.products:
|
||||
return Icons.inventory_2;
|
||||
case SyncStep.variants:
|
||||
return Icons.tune;
|
||||
case SyncStep.completed:
|
||||
@@ -778,10 +766,10 @@ class _DataSyncPageState extends State<DataSyncPage>
|
||||
|
||||
String _getStepLabel(SyncStep step) {
|
||||
switch (step) {
|
||||
case SyncStep.products:
|
||||
return 'Mengunduh Produk';
|
||||
case SyncStep.categories:
|
||||
return 'Mengunduh Kategori';
|
||||
case SyncStep.products:
|
||||
return 'Mengunduh Produk';
|
||||
case SyncStep.variants:
|
||||
return 'Mengunduh Variant';
|
||||
case SyncStep.completed:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:enaklo_pos/data/datasources/category_remote_datasource.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
import 'package:enaklo_pos/data/models/response/category_response_model.dart';
|
||||
import 'package:enaklo_pos/data/repositories/category/category_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'category_loader_event.dart';
|
||||
@@ -9,35 +11,314 @@ part 'category_loader_bloc.freezed.dart';
|
||||
|
||||
class CategoryLoaderBloc
|
||||
extends Bloc<CategoryLoaderEvent, CategoryLoaderState> {
|
||||
final CategoryRemoteDatasource _datasource;
|
||||
CategoryLoaderBloc(this._datasource) : super(CategoryLoaderState.initial()) {
|
||||
on<_Get>((event, emit) async {
|
||||
emit(const _Loading());
|
||||
final result = await _datasource.getCategories(limit: 50);
|
||||
result.fold(
|
||||
(l) => emit(_Error(l)),
|
||||
(r) async {
|
||||
List<CategoryModel> categories = r.data.categories;
|
||||
categories.insert(
|
||||
0,
|
||||
CategoryModel(
|
||||
id: "",
|
||||
name: 'Semua',
|
||||
organizationId: '',
|
||||
businessType: '',
|
||||
metadata: {},
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
),
|
||||
);
|
||||
emit(_Loaded(categories, null));
|
||||
final CategoryRepository _categoryRepository = CategoryRepository.instance;
|
||||
|
||||
Timer? _searchDebounce;
|
||||
bool _isLoadingMore = false;
|
||||
|
||||
CategoryLoaderBloc() : super(const CategoryLoaderState.initial()) {
|
||||
on<_GetCategories>(_onGetCategories);
|
||||
on<_LoadMore>(_onLoadMore);
|
||||
on<_Refresh>(_onRefresh);
|
||||
on<_Search>(_onSearch);
|
||||
on<_SyncAll>(_onSyncAll);
|
||||
on<_GetAllCategories>(_onGetAllCategories);
|
||||
on<_ClearCache>(_onClearCache);
|
||||
on<_GetDatabaseStats>(_onGetDatabaseStats);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_searchDebounce?.cancel();
|
||||
return super.close();
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// GET CATEGORIES (Remote-first with local fallback)
|
||||
// ========================================
|
||||
Future<void> _onGetCategories(
|
||||
_GetCategories event,
|
||||
Emitter<CategoryLoaderState> emit,
|
||||
) async {
|
||||
emit(const CategoryLoaderState.loading());
|
||||
_isLoadingMore = false;
|
||||
|
||||
log('📱 Loading categories - isActive: ${event.isActive}, forceRemote: ${event.forceRemote}');
|
||||
|
||||
final result = await _categoryRepository.getCategories(
|
||||
page: 1,
|
||||
limit: 50,
|
||||
isActive: event.isActive,
|
||||
search: event.search,
|
||||
forceRemote: event.forceRemote,
|
||||
);
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
log('❌ Error loading categories: $failure');
|
||||
emit(CategoryLoaderState.error(failure));
|
||||
},
|
||||
(response) async {
|
||||
final categories = [
|
||||
CategoryModel.all(),
|
||||
...response.data.categories,
|
||||
];
|
||||
|
||||
final totalPages = response.data.totalPages;
|
||||
final hasReachedMax = categories.length < 50 || 1 >= totalPages;
|
||||
|
||||
log('✅ Categories loaded: ${categories.length}, hasReachedMax: $hasReachedMax');
|
||||
|
||||
emit(CategoryLoaderState.loaded(
|
||||
categories: categories,
|
||||
hasReachedMax: hasReachedMax,
|
||||
currentPage: 1,
|
||||
isLoadingMore: false,
|
||||
isActive: event.isActive,
|
||||
searchQuery: event.search,
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// LOAD MORE CATEGORIES
|
||||
// ========================================
|
||||
Future<void> _onLoadMore(
|
||||
_LoadMore event,
|
||||
Emitter<CategoryLoaderState> emit,
|
||||
) async {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is! _Loaded ||
|
||||
currentState.hasReachedMax ||
|
||||
_isLoadingMore ||
|
||||
currentState.isLoadingMore) {
|
||||
log('⏹️ Load more blocked - state: ${currentState.runtimeType}, isLoadingMore: $_isLoadingMore');
|
||||
return;
|
||||
}
|
||||
|
||||
_isLoadingMore = true;
|
||||
emit(currentState.copyWith(isLoadingMore: true));
|
||||
|
||||
final nextPage = currentState.currentPage + 1;
|
||||
log('📄 Loading more categories - page: $nextPage');
|
||||
|
||||
try {
|
||||
final result = await _categoryRepository.getCategories(
|
||||
page: nextPage,
|
||||
limit: 10,
|
||||
isActive: currentState.isActive,
|
||||
search: currentState.searchQuery,
|
||||
);
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
log('❌ Error loading more categories: $failure');
|
||||
emit(currentState.copyWith(isLoadingMore: false));
|
||||
},
|
||||
(response) async {
|
||||
final newCategories = response.data.categories;
|
||||
final totalPages = response.data.totalPages;
|
||||
|
||||
// Prevent duplicate categories
|
||||
final currentCategoryIds =
|
||||
currentState.categories.map((c) => c.id).toSet();
|
||||
final filteredNewCategories = newCategories
|
||||
.where((category) => !currentCategoryIds.contains(category.id))
|
||||
.toList();
|
||||
|
||||
final allCategories =
|
||||
List<CategoryModel>.from(currentState.categories)
|
||||
..addAll(filteredNewCategories);
|
||||
|
||||
final hasReachedMax =
|
||||
newCategories.length < 10 || nextPage >= totalPages;
|
||||
|
||||
log('✅ More categories loaded: ${filteredNewCategories.length} new, total: ${allCategories.length}');
|
||||
|
||||
emit(CategoryLoaderState.loaded(
|
||||
categories: allCategories,
|
||||
hasReachedMax: hasReachedMax,
|
||||
currentPage: nextPage,
|
||||
isLoadingMore: false,
|
||||
isActive: currentState.isActive,
|
||||
searchQuery: currentState.searchQuery,
|
||||
));
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
log('❌ Exception loading more categories: $e');
|
||||
emit(currentState.copyWith(isLoadingMore: false));
|
||||
} finally {
|
||||
_isLoadingMore = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// REFRESH CATEGORIES
|
||||
// ========================================
|
||||
Future<void> _onRefresh(
|
||||
_Refresh event,
|
||||
Emitter<CategoryLoaderState> emit,
|
||||
) async {
|
||||
final currentState = state;
|
||||
bool isActive = true;
|
||||
String? searchQuery;
|
||||
|
||||
if (currentState is _Loaded) {
|
||||
isActive = currentState.isActive;
|
||||
searchQuery = currentState.searchQuery;
|
||||
}
|
||||
|
||||
_isLoadingMore = false;
|
||||
_searchDebounce?.cancel();
|
||||
|
||||
log('🔄 Refreshing categories');
|
||||
|
||||
// Clear local cache
|
||||
_categoryRepository.clearCache();
|
||||
|
||||
add(CategoryLoaderEvent.getCategories(
|
||||
isActive: isActive,
|
||||
search: searchQuery,
|
||||
forceRemote: true, // Force remote refresh
|
||||
));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// SEARCH CATEGORIES
|
||||
// ========================================
|
||||
Future<void> _onSearch(
|
||||
_Search event,
|
||||
Emitter<CategoryLoaderState> emit,
|
||||
) async {
|
||||
// Cancel previous search
|
||||
_searchDebounce?.cancel();
|
||||
|
||||
// Debounce search for better UX
|
||||
_searchDebounce = Timer(Duration(milliseconds: 300), () async {
|
||||
emit(const CategoryLoaderState.loading());
|
||||
_isLoadingMore = false;
|
||||
|
||||
log('🔍 Searching categories: "${event.query}"');
|
||||
|
||||
final result = await _categoryRepository.getCategories(
|
||||
page: 1,
|
||||
limit: 20, // More results for search
|
||||
isActive: event.isActive,
|
||||
search: event.query,
|
||||
);
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
log('❌ Search error: $failure');
|
||||
emit(CategoryLoaderState.error(failure));
|
||||
},
|
||||
(response) async {
|
||||
final categories = response.data.categories;
|
||||
final totalPages = response.data.totalPages;
|
||||
final hasReachedMax = categories.length < 20 || 1 >= totalPages;
|
||||
|
||||
log('✅ Search results: ${categories.length} categories found');
|
||||
|
||||
emit(CategoryLoaderState.loaded(
|
||||
categories: categories,
|
||||
hasReachedMax: hasReachedMax,
|
||||
currentPage: 1,
|
||||
isLoadingMore: false,
|
||||
isActive: event.isActive,
|
||||
searchQuery: event.query,
|
||||
));
|
||||
},
|
||||
);
|
||||
});
|
||||
on<_SetCategoryId>((event, emit) async {
|
||||
var currentState = state as _Loaded;
|
||||
}
|
||||
|
||||
emit(_Loaded(currentState.categories, event.categoryId));
|
||||
});
|
||||
// ========================================
|
||||
// SYNC ALL CATEGORIES
|
||||
// ========================================
|
||||
Future<void> _onSyncAll(
|
||||
_SyncAll event,
|
||||
Emitter<CategoryLoaderState> emit,
|
||||
) async {
|
||||
emit(const CategoryLoaderState.syncing());
|
||||
|
||||
log('🔄 Starting full category sync...');
|
||||
|
||||
final result = await _categoryRepository.syncAllCategories();
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
log('❌ Sync failed: $failure');
|
||||
emit(CategoryLoaderState.syncError(failure));
|
||||
|
||||
// After sync error, try to load local data
|
||||
Timer(Duration(seconds: 2), () {
|
||||
add(const CategoryLoaderEvent.getCategories());
|
||||
});
|
||||
},
|
||||
(successMessage) async {
|
||||
log('✅ Sync completed: $successMessage');
|
||||
emit(CategoryLoaderState.syncSuccess(successMessage));
|
||||
|
||||
// After successful sync, load the updated data
|
||||
Timer(Duration(seconds: 1), () {
|
||||
add(const CategoryLoaderEvent.getCategories());
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// GET ALL CATEGORIES (For Dropdown)
|
||||
// ========================================
|
||||
Future<void> _onGetAllCategories(
|
||||
_GetAllCategories event,
|
||||
Emitter<CategoryLoaderState> emit,
|
||||
) async {
|
||||
try {
|
||||
log('📋 Loading all categories for dropdown...');
|
||||
|
||||
final categories = await _categoryRepository.getAllCategories();
|
||||
|
||||
emit(CategoryLoaderState.allCategoriesLoaded(categories));
|
||||
log('✅ All categories loaded: ${categories.length}');
|
||||
} catch (e) {
|
||||
log('❌ Error loading all categories: $e');
|
||||
emit(CategoryLoaderState.error('Gagal memuat semua kategori: $e'));
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// GET DATABASE STATS
|
||||
// ========================================
|
||||
Future<void> _onGetDatabaseStats(
|
||||
_GetDatabaseStats event,
|
||||
Emitter<CategoryLoaderState> emit,
|
||||
) async {
|
||||
try {
|
||||
final stats = await _categoryRepository.getDatabaseStats();
|
||||
log('📊 Category database stats retrieved: $stats');
|
||||
|
||||
// You can emit a special state here if needed for UI updates
|
||||
// For now, just log the stats
|
||||
} catch (e) {
|
||||
log('❌ Error getting category database stats: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// CLEAR CACHE
|
||||
// ========================================
|
||||
Future<void> _onClearCache(
|
||||
_ClearCache event,
|
||||
Emitter<CategoryLoaderState> emit,
|
||||
) async {
|
||||
log('🧹 Manually clearing category cache');
|
||||
_categoryRepository.clearCache();
|
||||
|
||||
// Refresh current data after cache clear
|
||||
add(const CategoryLoaderEvent.refresh());
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,26 @@ part of 'category_loader_bloc.dart';
|
||||
|
||||
@freezed
|
||||
class CategoryLoaderEvent with _$CategoryLoaderEvent {
|
||||
const factory CategoryLoaderEvent.get() = _Get;
|
||||
const factory CategoryLoaderEvent.setCategoryId(String categoryId) =
|
||||
_SetCategoryId;
|
||||
const factory CategoryLoaderEvent.getCategories({
|
||||
@Default(true) bool isActive,
|
||||
String? search,
|
||||
@Default(false) bool forceRemote,
|
||||
}) = _GetCategories;
|
||||
|
||||
const factory CategoryLoaderEvent.loadMore() = _LoadMore;
|
||||
|
||||
const factory CategoryLoaderEvent.refresh() = _Refresh;
|
||||
|
||||
const factory CategoryLoaderEvent.search({
|
||||
required String query,
|
||||
@Default(true) bool isActive,
|
||||
}) = _Search;
|
||||
|
||||
const factory CategoryLoaderEvent.syncAll() = _SyncAll;
|
||||
|
||||
const factory CategoryLoaderEvent.getAllCategories() = _GetAllCategories;
|
||||
|
||||
const factory CategoryLoaderEvent.getDatabaseStats() = _GetDatabaseStats;
|
||||
|
||||
const factory CategoryLoaderEvent.clearCache() = _ClearCache;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,29 @@ part of 'category_loader_bloc.dart';
|
||||
@freezed
|
||||
class CategoryLoaderState with _$CategoryLoaderState {
|
||||
const factory CategoryLoaderState.initial() = _Initial;
|
||||
|
||||
const factory CategoryLoaderState.loading() = _Loading;
|
||||
const factory CategoryLoaderState.loaded(
|
||||
List<CategoryModel> categories, String? categoryId) = _Loaded;
|
||||
|
||||
const factory CategoryLoaderState.loaded({
|
||||
required List<CategoryModel> categories,
|
||||
required bool hasReachedMax,
|
||||
required int currentPage,
|
||||
required bool isLoadingMore,
|
||||
required bool isActive,
|
||||
String? searchQuery,
|
||||
}) = _Loaded;
|
||||
|
||||
const factory CategoryLoaderState.error(String message) = _Error;
|
||||
|
||||
// Sync-specific states
|
||||
const factory CategoryLoaderState.syncing() = _Syncing;
|
||||
|
||||
const factory CategoryLoaderState.syncSuccess(String message) = _SyncSuccess;
|
||||
|
||||
const factory CategoryLoaderState.syncError(String message) = _SyncError;
|
||||
|
||||
// For dropdown/all categories
|
||||
const factory CategoryLoaderState.allCategoriesLoaded(
|
||||
List<CategoryModel> categories,
|
||||
) = _AllCategoriesLoaded;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet_remote_data_source.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet/outlet_remote_data_source.dart';
|
||||
import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet_remote_data_source.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet/outlet_remote_data_source.dart';
|
||||
import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:enaklo_pos/presentation/customer/pages/customer_page.dart';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// ========================================
|
||||
// OFFLINE-ONLY HOMEPAGE - NO API CALLS
|
||||
// HOMEPAGE - LOCAL DATA ONLY, NO SYNC
|
||||
// lib/presentation/home/pages/home_page.dart
|
||||
// ========================================
|
||||
|
||||
import 'dart:developer';
|
||||
import 'package:enaklo_pos/core/components/flushbar.dart';
|
||||
import 'package:enaklo_pos/data/datasources/product/product_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/category_response_model.dart';
|
||||
import 'package:enaklo_pos/presentation/home/bloc/category_loader/category_loader_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/home/bloc/current_outlet/current_outlet_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/home/bloc/product_loader/product_loader_bloc.dart';
|
||||
@@ -50,17 +50,10 @@ class _HomePageState extends State<HomePage> {
|
||||
final ScrollController scrollController = ScrollController();
|
||||
String searchQuery = '';
|
||||
|
||||
// Local database only
|
||||
Map<String, dynamic> _databaseStats = {};
|
||||
final ProductLocalDatasource _localDatasource =
|
||||
ProductLocalDatasource.instance;
|
||||
bool _isLoadingStats = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeLocalData();
|
||||
_loadProducts();
|
||||
_loadData();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -70,49 +63,29 @@ class _HomePageState extends State<HomePage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// Initialize local data only
|
||||
void _initializeLocalData() {
|
||||
_loadDatabaseStats();
|
||||
}
|
||||
void _loadData() {
|
||||
log('📱 Loading data from local database...');
|
||||
|
||||
// Load database statistics
|
||||
void _loadDatabaseStats() async {
|
||||
try {
|
||||
final stats = await _localDatasource.getDatabaseStats();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_databaseStats = stats;
|
||||
_isLoadingStats = false;
|
||||
});
|
||||
}
|
||||
log('📊 Local database stats: $stats');
|
||||
} catch (e) {
|
||||
log('❌ Error loading local stats: $e');
|
||||
setState(() {
|
||||
_isLoadingStats = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
// Load categories from local database
|
||||
context
|
||||
.read<CategoryLoaderBloc>()
|
||||
.add(const CategoryLoaderEvent.getCategories());
|
||||
|
||||
void _loadProducts() {
|
||||
log('📱 Loading products from local database only...');
|
||||
|
||||
// Load products from local database only
|
||||
// Load products from local database
|
||||
context
|
||||
.read<ProductLoaderBloc>()
|
||||
.add(const ProductLoaderEvent.getProduct());
|
||||
|
||||
// Initialize other components
|
||||
context.read<CheckoutBloc>().add(CheckoutEvent.started(widget.items));
|
||||
context.read<CategoryLoaderBloc>().add(CategoryLoaderEvent.get());
|
||||
context.read<CurrentOutletBloc>().add(CurrentOutletEvent.currentOutlet());
|
||||
}
|
||||
|
||||
void _refreshLocalData() {
|
||||
log('🔄 Refreshing local data...');
|
||||
context.read<ProductLoaderBloc>().add(const ProductLoaderEvent.refresh());
|
||||
_loadDatabaseStats();
|
||||
}
|
||||
// void _refreshData() {
|
||||
// log('🔄 Refreshing l ocal data...');
|
||||
// context.read<ProductLoaderBloc>().add(const ProductLoaderEvent.refresh());
|
||||
// context.read<CategoryLoaderBloc>().add(const CategoryLoaderEvent.refresh());
|
||||
// }
|
||||
|
||||
void onCategoryTap(int index) {
|
||||
searchController.clear();
|
||||
@@ -125,11 +98,9 @@ class _HomePageState extends State<HomePage> {
|
||||
ScrollNotification notification, String? categoryId) {
|
||||
if (notification is ScrollEndNotification &&
|
||||
scrollController.position.extentAfter == 0) {
|
||||
log('📄 Loading more local products for category: $categoryId');
|
||||
log('📄 Loading more products...');
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
ProductLoaderEvent.loadMore(
|
||||
categoryId: categoryId,
|
||||
),
|
||||
ProductLoaderEvent.loadMore(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
@@ -142,7 +113,6 @@ class _HomePageState extends State<HomePage> {
|
||||
listener: (context, state) {
|
||||
state.maybeWhen(
|
||||
orElse: () {},
|
||||
loading: () {},
|
||||
success: () {
|
||||
Future.delayed(Duration(milliseconds: 300), () {
|
||||
AppFlushbar.showSuccess(context, 'Outlet berhasil diubah');
|
||||
@@ -160,81 +130,30 @@ class _HomePageState extends State<HomePage> {
|
||||
backgroundColor: AppColors.white,
|
||||
body: Column(
|
||||
children: [
|
||||
// Local database indicator
|
||||
_buildLocalModeIndicator(),
|
||||
|
||||
// Main content
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
// Left panel - Products
|
||||
// Left panel - Products with Categories
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.topStart,
|
||||
child: BlocBuilder<CategoryLoaderBloc,
|
||||
CategoryLoaderState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () =>
|
||||
Center(child: CircularProgressIndicator()),
|
||||
loaded: (categories, categoryId) => Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
// Enhanced home title with local stats
|
||||
_buildLocalHomeTitle(categoryId),
|
||||
|
||||
// Products section
|
||||
Expanded(
|
||||
child: BlocBuilder<ProductLoaderBloc,
|
||||
ProductLoaderState>(
|
||||
builder: (context, productState) {
|
||||
return CategoryTabBar(
|
||||
categories: categories,
|
||||
tabViews: categories.map((category) {
|
||||
return SizedBox(
|
||||
child: productState.maybeWhen(
|
||||
orElse: () =>
|
||||
_buildLoadingState(),
|
||||
loading: () =>
|
||||
_buildLoadingState(),
|
||||
loaded: (products,
|
||||
hasReachedMax,
|
||||
currentPage,
|
||||
isLoadingMore,
|
||||
categoryId,
|
||||
searchQuery) {
|
||||
if (products.isEmpty) {
|
||||
return _buildEmptyState(
|
||||
categoryId);
|
||||
}
|
||||
return _buildProductGrid(
|
||||
products,
|
||||
hasReachedMax,
|
||||
isLoadingMore,
|
||||
categoryId,
|
||||
currentPage,
|
||||
);
|
||||
},
|
||||
error: (message) =>
|
||||
_buildErrorState(
|
||||
message, categoryId),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
child:
|
||||
BlocBuilder<CategoryLoaderBloc, CategoryLoaderState>(
|
||||
builder: (context, categoryState) {
|
||||
return categoryState.maybeWhen(
|
||||
orElse: () => _buildCategoryLoadingState(),
|
||||
loading: () => _buildCategoryLoadingState(),
|
||||
error: (message) =>
|
||||
_buildCategoryErrorState(message),
|
||||
loaded: (categories, hasReachedMax, currentPage,
|
||||
isLoadingMore, isActive, searchQuery) =>
|
||||
_buildCategoryContent(categories),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// Right panel - Cart (unchanged)
|
||||
// Right panel - Cart
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: _buildCartSection(),
|
||||
@@ -249,219 +168,120 @@ class _HomePageState extends State<HomePage> {
|
||||
);
|
||||
}
|
||||
|
||||
// Local mode indicator
|
||||
Widget _buildLocalModeIndicator() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||
color: Colors.blue.shade600,
|
||||
child: Row(
|
||||
Widget _buildCategoryLoadingState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.storage, color: Colors.white, size: 16),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_isLoadingStats
|
||||
? 'Mode Lokal - Memuat data...'
|
||||
: 'Mode Lokal - ${_databaseStats['total_products'] ?? 0} produk tersimpan',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_databaseStats.isNotEmpty) ...[
|
||||
Text(
|
||||
'${(_databaseStats['database_size_mb'] ?? 0.0).toStringAsFixed(1)} MB',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
],
|
||||
InkWell(
|
||||
onTap: _refreshLocalData,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Icon(Icons.refresh, color: Colors.white, size: 14),
|
||||
),
|
||||
CircularProgressIndicator(color: AppColors.primary),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Memuat kategori...',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Enhanced home title with local stats only
|
||||
Widget _buildLocalHomeTitle(String? categoryId) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border(bottom: BorderSide(color: Colors.grey.shade200)),
|
||||
),
|
||||
Widget _buildCategoryErrorState(String message) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Original HomeTitle with faster search
|
||||
HomeTitle(
|
||||
controller: searchController,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
searchQuery = value;
|
||||
});
|
||||
Icon(Icons.error_outline, size: 48, color: Colors.red.shade400),
|
||||
SizedBox(height: 16),
|
||||
Text('Error Kategori',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
SizedBox(height: 8),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 32),
|
||||
child: Text(
|
||||
message,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Button.filled(
|
||||
width: 120,
|
||||
onPressed: () {
|
||||
context
|
||||
.read<CategoryLoaderBloc>()
|
||||
.add(const CategoryLoaderEvent.getCategories());
|
||||
},
|
||||
label: 'Coba Lagi',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Fast local search - no debounce needed for local data
|
||||
Future.delayed(Duration(milliseconds: 200), () {
|
||||
if (value == searchController.text) {
|
||||
log('🔍 Local search: "$value"');
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
ProductLoaderEvent.searchProduct(
|
||||
categoryId: categoryId,
|
||||
query: value,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
Widget _buildCategoryContent(List<CategoryModel> categories) {
|
||||
return Column(
|
||||
children: [
|
||||
// Simple home title
|
||||
_buildSimpleHomeTitle(),
|
||||
|
||||
// Products section with categories
|
||||
Expanded(
|
||||
child: BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
|
||||
builder: (context, productState) {
|
||||
return CategoryTabBar(
|
||||
key: ValueKey(categories.length),
|
||||
categories: categories,
|
||||
tabViews: categories.map((category) {
|
||||
return SizedBox(
|
||||
child: productState.maybeWhen(
|
||||
orElse: () => _buildLoadingState(),
|
||||
loading: () => _buildLoadingState(),
|
||||
loaded: (products, hasReachedMax, currentPage,
|
||||
isLoadingMore, categoryId, searchQuery) {
|
||||
if (products.isEmpty) {
|
||||
return _buildEmptyState(categoryId);
|
||||
}
|
||||
return _buildProductGrid(
|
||||
products,
|
||||
hasReachedMax,
|
||||
isLoadingMore,
|
||||
categoryId,
|
||||
currentPage,
|
||||
);
|
||||
},
|
||||
error: (message) =>
|
||||
_buildErrorState(message, category.id),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
// Local database stats
|
||||
if (_databaseStats.isNotEmpty) ...[
|
||||
SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
// Local storage indicator
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 6, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.shade50,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.storage,
|
||||
size: 12, color: Colors.blue.shade600),
|
||||
SizedBox(width: 3),
|
||||
Text(
|
||||
'Lokal',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.blue.shade600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(width: 8),
|
||||
|
||||
// Database stats chips
|
||||
_buildStatChip(
|
||||
'${_databaseStats['total_products'] ?? 0}',
|
||||
'produk',
|
||||
Icons.inventory_2,
|
||||
Colors.green,
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
_buildStatChip(
|
||||
'${_databaseStats['total_variants'] ?? 0}',
|
||||
'varian',
|
||||
Icons.tune,
|
||||
Colors.orange,
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
_buildStatChip(
|
||||
'${_databaseStats['cache_entries'] ?? 0}',
|
||||
'cache',
|
||||
Icons.memory,
|
||||
Colors.purple,
|
||||
),
|
||||
|
||||
Spacer(),
|
||||
|
||||
// Clear cache button
|
||||
InkWell(
|
||||
onTap: () {
|
||||
_localDatasource.clearExpiredCache();
|
||||
_loadDatabaseStats();
|
||||
AppFlushbar.showSuccess(context, 'Cache dibersihkan');
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.clear_all,
|
||||
size: 14,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
// Refresh button
|
||||
InkWell(
|
||||
onTap: _refreshLocalData,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.refresh,
|
||||
size: 14,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatChip(
|
||||
String value, String label, IconData icon, Color color) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 5, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 10, color: color),
|
||||
SizedBox(width: 2),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 1),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 8,
|
||||
color: color.withOpacity(0.8),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// Simple home title
|
||||
Widget _buildSimpleHomeTitle() {
|
||||
return HomeTitle(
|
||||
controller: searchController,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
searchQuery = value;
|
||||
});
|
||||
|
||||
// Fast local search
|
||||
Future.delayed(Duration(milliseconds: 200), () {
|
||||
if (value == searchController.text) {
|
||||
log('🔍 Local search: "$value"');
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
ProductLoaderEvent.searchProduct(
|
||||
query: value,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -473,7 +293,7 @@ class _HomePageState extends State<HomePage> {
|
||||
CircularProgressIndicator(color: AppColors.primary),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Memuat data lokal...',
|
||||
'Memuat data...',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
],
|
||||
@@ -491,12 +311,12 @@ class _HomePageState extends State<HomePage> {
|
||||
Text(
|
||||
searchQuery.isNotEmpty
|
||||
? 'Produk "$searchQuery" tidak ditemukan'
|
||||
: 'Belum ada data produk lokal',
|
||||
: 'Belum ada data produk',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Tambahkan produk ke database lokal terlebih dahulu',
|
||||
'Data akan dimuat dari database lokal',
|
||||
style: TextStyle(
|
||||
color: Colors.grey.shade600,
|
||||
fontSize: 12,
|
||||
@@ -542,18 +362,11 @@ class _HomePageState extends State<HomePage> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: Colors.red.shade400,
|
||||
),
|
||||
Icon(Icons.error_outline, size: 48, color: Colors.red.shade400),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Error Database Lokal',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
'Error Database',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Padding(
|
||||
@@ -588,61 +401,19 @@ class _HomePageState extends State<HomePage> {
|
||||
) {
|
||||
return Column(
|
||||
children: [
|
||||
// Product count with local indicator
|
||||
// Simple product count
|
||||
if (products.isNotEmpty)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.shade50,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.storage,
|
||||
size: 10, color: Colors.blue.shade600),
|
||||
SizedBox(width: 2),
|
||||
Text(
|
||||
'${products.length}',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.blue.shade600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(width: 6),
|
||||
Text(
|
||||
'produk dari database lokal',
|
||||
'${products.length} produk ditemukan',
|
||||
style: TextStyle(
|
||||
color: Colors.grey.shade600,
|
||||
fontSize: 11,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
if (currentPage > 1) ...[
|
||||
SizedBox(width: 6),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 4, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
'Hal $currentPage',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
Spacer(),
|
||||
if (isLoadingMore)
|
||||
SizedBox(
|
||||
@@ -657,7 +428,7 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
),
|
||||
|
||||
// Products grid - faster loading from local DB
|
||||
// Products grid
|
||||
Expanded(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) =>
|
||||
@@ -666,7 +437,7 @@ class _HomePageState extends State<HomePage> {
|
||||
itemCount: products.length,
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.all(16),
|
||||
cacheExtent: 200.0, // Bigger cache for smooth scrolling
|
||||
cacheExtent: 200.0,
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 180,
|
||||
mainAxisSpacing: 30,
|
||||
@@ -683,12 +454,12 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
),
|
||||
|
||||
// End of data indicator
|
||||
// End indicator
|
||||
if (hasReachedMax && products.isNotEmpty)
|
||||
Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: Text(
|
||||
'Semua produk lokal telah dimuat',
|
||||
'Semua produk telah dimuat',
|
||||
style: TextStyle(
|
||||
color: Colors.grey.shade500,
|
||||
fontSize: 11,
|
||||
@@ -786,7 +557,7 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
),
|
||||
|
||||
// Payment section (unchanged)
|
||||
// Payment section
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0).copyWith(top: 0),
|
||||
child: Column(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:enaklo_pos/core/constants/colors.dart';
|
||||
import 'package:enaklo_pos/data/models/response/category_response_model.dart';
|
||||
import 'package:enaklo_pos/presentation/home/bloc/category_loader/category_loader_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/home/bloc/product_loader/product_loader_bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -37,14 +36,41 @@ class _CategoryTabBarState extends State<CategoryTabBar>
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
ProductLoaderEvent.getProduct(categoryId: selectedCategoryId),
|
||||
);
|
||||
context
|
||||
.read<CategoryLoaderBloc>()
|
||||
.add(CategoryLoaderEvent.setCategoryId(selectedCategoryId ?? ""));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(CategoryTabBar oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
|
||||
// ✅ Update TabController when categories length changes
|
||||
if (oldWidget.categories.length != widget.categories.length) {
|
||||
_tabController.dispose();
|
||||
_tabController = TabController(
|
||||
length: widget.categories.length,
|
||||
vsync: this,
|
||||
initialIndex: 0, // Reset to first tab
|
||||
);
|
||||
|
||||
_tabController.addListener(() {
|
||||
if (_tabController.indexIsChanging) {
|
||||
if (_tabController.index == 0) {
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
ProductLoaderEvent.getProduct(),
|
||||
);
|
||||
} else {
|
||||
selectedCategoryId = widget.categories[_tabController.index].id;
|
||||
context.read<ProductLoaderBloc>().add(
|
||||
ProductLoaderEvent.getProduct(categoryId: selectedCategoryId),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
@@ -53,48 +79,45 @@ class _CategoryTabBarState extends State<CategoryTabBar>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultTabController(
|
||||
length: widget.categories.length,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Material(
|
||||
elevation: 0,
|
||||
color: Colors.white,
|
||||
borderOnForeground: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
isScrollable: true,
|
||||
tabAlignment: TabAlignment.start,
|
||||
labelColor: AppColors.primary,
|
||||
labelStyle: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
dividerColor: AppColors.primary,
|
||||
unselectedLabelColor: AppColors.primary,
|
||||
indicatorSize: TabBarIndicatorSize.label,
|
||||
indicatorWeight: 4,
|
||||
indicatorColor: AppColors.primary,
|
||||
tabs: widget.categories
|
||||
.map((category) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Tab(text: category.name),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
// ✅ ini bagian penting
|
||||
child: TabBarView(
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Material(
|
||||
elevation: 0,
|
||||
color: Colors.white,
|
||||
borderOnForeground: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
children: widget.tabViews,
|
||||
isScrollable: true,
|
||||
tabAlignment: TabAlignment.start,
|
||||
labelColor: AppColors.primary,
|
||||
labelStyle: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
dividerColor: AppColors.primary,
|
||||
unselectedLabelColor: AppColors.primary,
|
||||
indicatorSize: TabBarIndicatorSize.label,
|
||||
indicatorWeight: 4,
|
||||
indicatorColor: AppColors.primary,
|
||||
tabs: widget.categories
|
||||
.map((category) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Tab(text: category.name),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
// ✅ ini bagian penting
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: widget.tabViews,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class ConfirmPaymentTitle extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: context.deviceHeight * 0.1,
|
||||
height: context.deviceHeight * 0.123,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:enaklo_pos/core/extensions/int_ext.dart';
|
||||
import 'package:enaklo_pos/presentation/home/dialog/variant_dialog.dart';
|
||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:enaklo_pos/core/constants/variables.dart';
|
||||
@@ -53,27 +54,47 @@ class ProductCard extends StatelessWidget {
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(8.0)),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: (data.imageUrl ?? "").contains('http')
|
||||
? data.imageUrl!
|
||||
: '${Variables.baseUrl}/${data.imageUrl}',
|
||||
fit: BoxFit.cover,
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
memCacheHeight: 120,
|
||||
memCacheWidth: 120,
|
||||
errorWidget: (context, url, error) => Container(
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.disabled.withOpacity(0.4),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.image,
|
||||
color: AppColors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: data.imageUrl == ""
|
||||
? Container(
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.disabled.withOpacity(0.4),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.image,
|
||||
color: AppColors.grey,
|
||||
),
|
||||
)
|
||||
: CachedNetworkImage(
|
||||
imageUrl: (data.imageUrl ?? "").contains('http')
|
||||
? data.imageUrl!
|
||||
: '${Variables.baseUrl}/${data.imageUrl}',
|
||||
fit: BoxFit.cover,
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
memCacheHeight: 120,
|
||||
memCacheWidth: 120,
|
||||
errorWidget: (context, url, error) {
|
||||
FirebaseCrashlytics.instance.recordError(
|
||||
error,
|
||||
StackTrace.current,
|
||||
reason:
|
||||
'Failed to load image from: $url, productId: ${data.id}, productName: ${data.name}, dataUrl: ${data.imageUrl}',
|
||||
fatal: false,
|
||||
);
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.disabled.withOpacity(0.4),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.image,
|
||||
color: AppColors.grey,
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:enaklo_pos/presentation/home/bloc/payment_methods/payment_method
|
||||
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
|
||||
import 'package:enaklo_pos/presentation/sales/blocs/payment_form/payment_form_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/success/pages/success_payment_page.dart';
|
||||
import 'package:enaklo_pos/presentation/success/pages/success_split_bill_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
@@ -370,23 +371,43 @@ class _PaymentPageState extends State<PaymentPage> {
|
||||
state.maybeWhen(
|
||||
orElse: () {},
|
||||
success: (data) {
|
||||
context.pushReplacement(SuccessPaymentPage(
|
||||
productQuantity: widget.order.orderItems
|
||||
?.map(
|
||||
(item) => ProductQuantity(
|
||||
product: Product(
|
||||
name: item.productName,
|
||||
price: item.unitPrice,
|
||||
),
|
||||
quantity: item.quantity ?? 0,
|
||||
if (widget.isSplit) {
|
||||
context.pushReplacement(SuccessSplitBillPage(
|
||||
productQuantity: getOrderItemPending()
|
||||
.map(
|
||||
(item) => ProductQuantity(
|
||||
product: Product(
|
||||
name: item.productName,
|
||||
price: item.unitPrice,
|
||||
),
|
||||
)
|
||||
.toList() ??
|
||||
[],
|
||||
payment: data,
|
||||
paymentMethod: selectedPaymentMethod?.name ?? '',
|
||||
nominalBayar: totalPriceController.text.toIntegerFromText,
|
||||
));
|
||||
quantity: item.quantity ?? 0,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
payment: data,
|
||||
paymentMethod: selectedPaymentMethod?.name ?? '',
|
||||
nominalBayar:
|
||||
totalPriceController.text.toIntegerFromText,
|
||||
));
|
||||
} else {
|
||||
context.pushReplacement(SuccessPaymentPage(
|
||||
productQuantity: getOrderItemPending()
|
||||
.map(
|
||||
(item) => ProductQuantity(
|
||||
product: Product(
|
||||
name: item.productName,
|
||||
price: item.unitPrice,
|
||||
),
|
||||
quantity: item.quantity ?? 0,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
payment: data,
|
||||
paymentMethod: selectedPaymentMethod?.name ?? '',
|
||||
nominalBayar:
|
||||
totalPriceController.text.toIntegerFromText,
|
||||
));
|
||||
}
|
||||
},
|
||||
error: (message) {
|
||||
AppFlushbar.showError(context, message);
|
||||
@@ -443,6 +464,7 @@ class _PaymentPageState extends State<PaymentPage> {
|
||||
final itemPending = widget.order.orderItems
|
||||
?.where((item) => item.status == "pending")
|
||||
.toList();
|
||||
|
||||
if (widget.isSplit == false) {
|
||||
final request = PaymentRequestModel(
|
||||
amount: widget.order.totalAmount ?? 0,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:enaklo_pos/data/datasources/analytic_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/outlet/outlet_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/category_analytic_response_model.dart';
|
||||
import 'package:enaklo_pos/data/models/response/payment_method_analytic_response_model.dart';
|
||||
import 'package:enaklo_pos/data/models/response/product_analytic_response_model.dart';
|
||||
|
||||
@@ -271,18 +271,24 @@ class _SalesPageState extends State<SalesPage> {
|
||||
nominalBayar: orderDetail?.totalPaid ?? 0,
|
||||
kembalian: 0,
|
||||
productQuantity: orderDetail!.orderItems!
|
||||
.where((item) =>
|
||||
item.status != 'cancelled')
|
||||
.toList()
|
||||
.toProductQuantities(),
|
||||
);
|
||||
} else {
|
||||
onPrint(
|
||||
onPrintBill(
|
||||
context,
|
||||
productQuantity: orderDetail!.orderItems!
|
||||
.where((item) =>
|
||||
item.status != 'cancelled')
|
||||
.toList()
|
||||
.toProductQuantities(),
|
||||
order: orderDetail!,
|
||||
);
|
||||
}
|
||||
},
|
||||
label: 'Print',
|
||||
label: 'Print Bill',
|
||||
icon: Icon(
|
||||
Icons.print,
|
||||
),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:enaklo_pos/data/datasources/category_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/category/category_remote_datasource.dart';
|
||||
import 'package:enaklo_pos/data/models/response/category_response_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:enaklo_pos/core/constants/colors.dart';
|
||||
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
||||
import 'package:enaklo_pos/presentation/setting/pages/printer_page.dart';
|
||||
import 'package:enaklo_pos/presentation/setting/pages/setting_tile.dart';
|
||||
import 'package:enaklo_pos/presentation/setting/pages/sync_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingPage extends StatefulWidget {
|
||||
@@ -84,6 +85,14 @@ class _SettingPageState extends State<SettingPage> {
|
||||
icon: Icons.print_outlined,
|
||||
onTap: () => indexValue(0),
|
||||
),
|
||||
SettingTile(
|
||||
index: 1,
|
||||
currentIndex: currentIndex,
|
||||
title: 'Sinkronisasi',
|
||||
subtitle: 'Sinkronisasi data',
|
||||
icon: Icons.sync_outlined,
|
||||
onTap: () => indexValue(1),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -101,6 +110,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
index: currentIndex,
|
||||
children: [
|
||||
SettingPrinterPage(),
|
||||
SettingSyncPage(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,580 @@
|
||||
import 'dart:developer';
|
||||
import 'package:enaklo_pos/core/components/flushbar.dart';
|
||||
import 'package:enaklo_pos/core/components/buttons.dart';
|
||||
import 'package:enaklo_pos/data/repositories/product/product_repository.dart';
|
||||
import 'package:enaklo_pos/data/repositories/category/category_repository.dart';
|
||||
import 'package:enaklo_pos/data/datasources/product/product_local_datasource.dart';
|
||||
import 'package:enaklo_pos/data/datasources/category/category_local_datasource.dart';
|
||||
import 'package:enaklo_pos/presentation/setting/widgets/settings_title.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingSyncPage extends StatefulWidget {
|
||||
const SettingSyncPage({super.key});
|
||||
|
||||
@override
|
||||
State<SettingSyncPage> createState() => _SettingSyncPageState();
|
||||
}
|
||||
|
||||
class _SettingSyncPageState extends State<SettingSyncPage> {
|
||||
final ProductRepository _productRepository = ProductRepository.instance;
|
||||
final CategoryRepository _categoryRepository = CategoryRepository.instance;
|
||||
final ProductLocalDatasource _productLocalDatasource =
|
||||
ProductLocalDatasource.instance;
|
||||
final CategoryLocalDatasource _categoryLocalDatasource =
|
||||
CategoryLocalDatasource.instance;
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isSyncing = false;
|
||||
Map<String, dynamic> _productStats = {};
|
||||
Map<String, dynamic> _categoryStats = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadStats();
|
||||
}
|
||||
|
||||
Future<void> _loadStats() async {
|
||||
setState(() => _isLoading = true);
|
||||
try {
|
||||
final productStats = await _productRepository.getDatabaseStats();
|
||||
final categoryStats = await _categoryRepository.getDatabaseStats();
|
||||
|
||||
setState(() {
|
||||
_productStats = productStats;
|
||||
_categoryStats = categoryStats;
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
log('Error loading stats: $e');
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _syncAllData() async {
|
||||
setState(() => _isSyncing = true);
|
||||
|
||||
try {
|
||||
// Show loading dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 16),
|
||||
Text('Sinkronisasi semua data...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Sync categories first
|
||||
final categoryResult = await _categoryRepository.syncAllCategories();
|
||||
|
||||
await categoryResult.fold(
|
||||
(error) async {
|
||||
Navigator.of(context).pop();
|
||||
AppFlushbar.showError(context, 'Gagal sync kategori: $error');
|
||||
return;
|
||||
},
|
||||
(success) async {
|
||||
log('Categories synced successfully');
|
||||
},
|
||||
);
|
||||
|
||||
// Sync products after categories
|
||||
final productResult = await _productRepository.syncAllProducts();
|
||||
|
||||
await productResult.fold(
|
||||
(error) async {
|
||||
Navigator.of(context).pop();
|
||||
AppFlushbar.showError(context, 'Gagal sync produk: $error');
|
||||
return;
|
||||
},
|
||||
(success) async {
|
||||
log('Products synced successfully');
|
||||
},
|
||||
);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
AppFlushbar.showSuccess(context, 'Sinkronisasi berhasil');
|
||||
_loadStats(); // Refresh stats
|
||||
} catch (e) {
|
||||
Navigator.of(context).pop();
|
||||
AppFlushbar.showError(context, 'Gagal sinkronisasi: $e');
|
||||
} finally {
|
||||
setState(() => _isSyncing = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _clearAllData() async {
|
||||
// Show confirmation dialog
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Hapus Semua Data'),
|
||||
content: Text(
|
||||
'Apakah Anda yakin ingin menghapus semua data lokal? Tindakan ini tidak dapat dibatalkan.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: Text('Batal'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: Text('Hapus', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed != true) return;
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
// Clear products and categories using datasource
|
||||
await _productLocalDatasource.clearAllProducts();
|
||||
await _categoryLocalDatasource.clearAllCategories();
|
||||
|
||||
// Clear caches
|
||||
_productRepository.clearCache();
|
||||
_categoryRepository.clearCache();
|
||||
|
||||
AppFlushbar.showSuccess(context, 'Semua data berhasil dihapus');
|
||||
_loadStats(); // Refresh stats
|
||||
} catch (e) {
|
||||
AppFlushbar.showError(context, 'Gagal menghapus data: $e');
|
||||
} finally {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _syncProducts() async {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final result = await _productRepository.syncAllProducts();
|
||||
|
||||
await result.fold(
|
||||
(error) async {
|
||||
AppFlushbar.showError(context, 'Gagal sync produk: $error');
|
||||
},
|
||||
(success) async {
|
||||
AppFlushbar.showSuccess(context, success);
|
||||
_loadStats(); // Refresh stats
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
AppFlushbar.showError(context, 'Gagal sync produk: $e');
|
||||
} finally {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _syncCategories() async {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final result = await _categoryRepository.syncAllCategories();
|
||||
|
||||
await result.fold(
|
||||
(error) async {
|
||||
AppFlushbar.showError(context, 'Gagal sync kategori: $error');
|
||||
},
|
||||
(success) async {
|
||||
AppFlushbar.showSuccess(context, success);
|
||||
_loadStats(); // Refresh stats
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
AppFlushbar.showError(context, 'Gagal sync kategori: $e');
|
||||
} finally {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
SettingsTitle(
|
||||
'Sinkronisasi',
|
||||
subtitle: 'Sinkronisasi data dengan server',
|
||||
),
|
||||
|
||||
SizedBox(height: 24),
|
||||
|
||||
// Quick Actions
|
||||
_buildQuickActions(),
|
||||
|
||||
SizedBox(height: 24),
|
||||
|
||||
// Sync Tables
|
||||
_buildSyncTables(),
|
||||
|
||||
SizedBox(height: 24),
|
||||
|
||||
// Database Stats
|
||||
_buildDatabaseStats(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuickActions() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Aksi Cepat',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey.shade800,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Button.filled(
|
||||
onPressed: _isSyncing || _isLoading ? null : _syncAllData,
|
||||
label: _isSyncing ? 'Menyinkronkan...' : 'Sync Semua Data',
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Button.outlined(
|
||||
onPressed: _isLoading || _isSyncing ? null : _clearAllData,
|
||||
label: 'Hapus Semua Data',
|
||||
textColor: Colors.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSyncTables() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Sinkronisasi per Tabel',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey.shade800,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
|
||||
// Categories Sync
|
||||
_buildSyncTableItem(
|
||||
title: 'Kategori',
|
||||
subtitle: 'Sinkronkan data kategori produk',
|
||||
icon: Icons.category,
|
||||
color: Colors.blue,
|
||||
count: _categoryStats['total_categories'] ?? 0,
|
||||
onSync: _syncCategories,
|
||||
onClear: () async {
|
||||
final confirmed = await _showClearConfirmation('kategori');
|
||||
if (confirmed) {
|
||||
await _categoryLocalDatasource.clearAllCategories();
|
||||
_categoryRepository.clearCache();
|
||||
AppFlushbar.showSuccess(
|
||||
context, 'Data kategori berhasil dihapus');
|
||||
_loadStats();
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
SizedBox(height: 12),
|
||||
Divider(),
|
||||
SizedBox(height: 12),
|
||||
|
||||
// Products Sync
|
||||
_buildSyncTableItem(
|
||||
title: 'Produk',
|
||||
subtitle: 'Sinkronkan data produk dan variant',
|
||||
icon: Icons.inventory_2,
|
||||
color: Colors.green,
|
||||
count: _productStats['total_products'] ?? 0,
|
||||
onSync: _syncProducts,
|
||||
onClear: () async {
|
||||
final confirmed = await _showClearConfirmation('produk');
|
||||
if (confirmed) {
|
||||
await _productLocalDatasource.clearAllProducts();
|
||||
_productRepository.clearCache();
|
||||
AppFlushbar.showSuccess(
|
||||
context, 'Data produk berhasil dihapus');
|
||||
_loadStats();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSyncTableItem({
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required IconData icon,
|
||||
required Color color,
|
||||
required int count,
|
||||
required VoidCallback onSync,
|
||||
required VoidCallback onClear,
|
||||
}) {
|
||||
return Row(
|
||||
children: [
|
||||
// Icon and info
|
||||
Container(
|
||||
padding: EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
|
||||
SizedBox(width: 12),
|
||||
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
'$count',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Actions
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: _isLoading || _isSyncing ? null : onSync,
|
||||
icon: Icon(Icons.sync, size: 20),
|
||||
tooltip: 'Sync $title',
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: color.withOpacity(0.1),
|
||||
foregroundColor: color,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
IconButton(
|
||||
onPressed: _isLoading || _isSyncing ? null : onClear,
|
||||
icon: Icon(Icons.delete_outline, size: 20),
|
||||
tooltip: 'Hapus $title',
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: Colors.red.withOpacity(0.1),
|
||||
foregroundColor: Colors.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDatabaseStats() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'Statistik Database',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey.shade800,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
if (_isLoading)
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
else
|
||||
IconButton(
|
||||
onPressed: _loadStats,
|
||||
icon: Icon(Icons.refresh, size: 20),
|
||||
tooltip: 'Refresh Stats',
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
if (_isLoading)
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 20),
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
children: [
|
||||
// Category stats
|
||||
_buildStatRow(
|
||||
'Kategori',
|
||||
_categoryStats['total_categories']?.toString() ?? '0',
|
||||
Icons.category,
|
||||
Colors.blue,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Product stats
|
||||
_buildStatRow(
|
||||
'Produk',
|
||||
_productStats['total_products']?.toString() ?? '0',
|
||||
Icons.inventory_2,
|
||||
Colors.green,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Variant stats
|
||||
_buildStatRow(
|
||||
'Variant',
|
||||
_productStats['total_variants']?.toString() ?? '0',
|
||||
Icons.tune,
|
||||
Colors.orange,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Cache stats
|
||||
_buildStatRow(
|
||||
'Cache Entries',
|
||||
'${(_productStats['cache_entries'] ?? 0) + (_categoryStats['cache_entries'] ?? 0)}',
|
||||
Icons.memory,
|
||||
Colors.purple,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Database size
|
||||
_buildStatRow(
|
||||
'Ukuran Database',
|
||||
'${((_productStats['database_size_mb'] ?? 0.0) + (_categoryStats['database_size_mb'] ?? 0.0)).toStringAsFixed(2)} MB',
|
||||
Icons.storage,
|
||||
Colors.grey.shade600,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatRow(String label, String value, IconData icon, Color color) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: color),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey.shade700,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> _showClearConfirmation(String dataType) async {
|
||||
return await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Hapus Data $dataType'),
|
||||
content:
|
||||
Text('Apakah Anda yakin ingin menghapus semua data $dataType?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: Text('Batal'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: Text('Hapus', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
}
|
||||
@@ -175,7 +175,7 @@ class _KitchenPrinterPageState extends State<KitchenPrinterPage> {
|
||||
// Generate test print data
|
||||
final testPrintData = await PrintDataoutputs
|
||||
.instance
|
||||
.printKitchen(
|
||||
.printKitchenAllItem(
|
||||
[], // Empty product list for test
|
||||
'Test Table',
|
||||
'Test Order',
|
||||
|
||||
@@ -0,0 +1,993 @@
|
||||
import 'package:enaklo_pos/core/constants/colors.dart';
|
||||
import 'package:enaklo_pos/core/extensions/build_context_ext.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/extensions/string_ext.dart';
|
||||
import 'package:enaklo_pos/core/function/app_function.dart';
|
||||
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
|
||||
import 'package:enaklo_pos/data/models/response/payment_response_model.dart';
|
||||
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
|
||||
import 'package:enaklo_pos/presentation/home/pages/dashboard_page.dart';
|
||||
import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class SuccessSplitBillPage extends StatefulWidget {
|
||||
final List<ProductQuantity> productQuantity;
|
||||
final PaymentData payment;
|
||||
final String paymentMethod;
|
||||
final int nominalBayar;
|
||||
const SuccessSplitBillPage({
|
||||
super.key,
|
||||
required this.payment,
|
||||
required this.productQuantity,
|
||||
required this.paymentMethod,
|
||||
required this.nominalBayar,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SuccessSplitBillPage> createState() => _SuccessSplitBillPageState();
|
||||
}
|
||||
|
||||
class _SuccessSplitBillPageState extends State<SuccessSplitBillPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
context
|
||||
.read<OrderLoaderBloc>()
|
||||
.add(OrderLoaderEvent.getById(widget.payment.orderId ?? ""));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.05),
|
||||
AppColors.background,
|
||||
AppColors.background,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: BlocBuilder<OrderLoaderBloc, OrderLoaderState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => SizedBox.shrink(),
|
||||
loading: () => Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
loadedDetail: (order) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Row(
|
||||
children: [
|
||||
// Left Panel - Success Message & Order Info
|
||||
Expanded(
|
||||
flex: 35,
|
||||
child: _buildLeftPanel(order),
|
||||
),
|
||||
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Right Panel - Order Details
|
||||
Expanded(
|
||||
flex: 65,
|
||||
child: _buildRightPanel(order),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLeftPanel(Order order) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
blurRadius: 30,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Success Header
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(32.0),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
AppColors.primary.withOpacity(0.05),
|
||||
],
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(24),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Success Icon
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primary,
|
||||
AppColors.primary.withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.check_rounded,
|
||||
size: 48,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Success Title
|
||||
const Text(
|
||||
'Split Bill Berhasil!',
|
||||
style: TextStyle(
|
||||
fontSize: 26,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: const Text(
|
||||
'Pesanan telah diterima dan sedang diproses',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Order Information Section
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSectionTitle('Informasi Pesanan'),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Customer Card
|
||||
_buildInfoCard(
|
||||
icon: Icons.person_outline_rounded,
|
||||
title: 'Nama Pelanggan',
|
||||
value: order.metadata?['customer_name'] ?? "-",
|
||||
gradient: [
|
||||
Colors.blue.withOpacity(0.1),
|
||||
Colors.purple.withOpacity(0.1),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Order Details
|
||||
Column(
|
||||
children: [
|
||||
_buildInfoRow(
|
||||
icon: Icons.receipt_long_outlined,
|
||||
label: 'No. Pesanan',
|
||||
value: order.orderNumber ?? "-",
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow(
|
||||
icon: Icons.receipt_long_outlined,
|
||||
label: 'Metode Pembayaran',
|
||||
value: widget.paymentMethod,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow(
|
||||
icon: Icons.access_time_rounded,
|
||||
label: 'Waktu',
|
||||
value: (order.createdAt ?? DateTime.now())
|
||||
.toFormattedDate3(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow(
|
||||
icon: Icons.check_circle_outline,
|
||||
label: 'Status Pembayaran',
|
||||
value: 'Lunas',
|
||||
valueColor: Colors.green,
|
||||
showBadge: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Total and Action Buttons
|
||||
_buildBottomSection(order),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRightPanel(Order order) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.08),
|
||||
blurRadius: 30,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.background,
|
||||
Colors.grey.shade50,
|
||||
],
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(24),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.2),
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.receipt_long_rounded,
|
||||
color: AppColors.primary,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Detail Pesanan',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Ringkasan item yang dipesan',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.primary,
|
||||
AppColors.primary.withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
'${widget.productQuantity.length} Items',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Product List
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
itemCount: widget.productQuantity.length,
|
||||
separatorBuilder: (context, index) => const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) {
|
||||
return _buildProductCard(index);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// Summary Footer
|
||||
_buildSummaryFooter(order),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProductCard(int index) {
|
||||
final item = widget.productQuantity[index];
|
||||
final totalPrice = (item.product.price ?? 0) * item.quantity;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Colors.grey.shade50,
|
||||
Colors.white,
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
border: Border.all(
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
width: 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Product Image
|
||||
Container(
|
||||
width: 70,
|
||||
height: 70,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.2),
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Icon(
|
||||
Icons.restaurant_rounded,
|
||||
color: AppColors.primary,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Product Details
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.product.name ?? "-",
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
(item.product.price ?? 0).toString().currencyFormatRpV2,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey.shade700,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Quantity and Total
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.primary,
|
||||
AppColors.primary.withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
'${item.quantity}x',
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
totalPrice.toString().currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoCard({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String value,
|
||||
required List<Color> gradient,
|
||||
}) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: gradient,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required String value,
|
||||
Color? valueColor,
|
||||
bool showBadge = false,
|
||||
}) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 18,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showBadge && valueColor != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: valueColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
size: 14,
|
||||
color: valueColor,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: valueColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: valueColor ?? Colors.black87,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomSection(Order order) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.grey.shade50,
|
||||
Colors.white,
|
||||
],
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
bottom: Radius.circular(24),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Total Amount
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
AppColors.primary.withOpacity(0.05),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Total Pembayaran',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
widget.nominalBayar.currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Action Buttons
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
onTap: () {
|
||||
context.push(DashboardPage());
|
||||
},
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'Kembali ke Beranda',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.centerLeft,
|
||||
end: Alignment.centerRight,
|
||||
colors: [
|
||||
AppColors.primary,
|
||||
AppColors.primary.withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: () async {
|
||||
final updatedOrderItems =
|
||||
widget.productQuantity.map((pq) {
|
||||
return OrderItem(
|
||||
productName: pq.product.name,
|
||||
printerType: pq.product.printerType,
|
||||
productVariantName: pq.variant?.name,
|
||||
quantity: pq.quantity,
|
||||
unitPrice: pq.product.price,
|
||||
totalPrice: (pq.product.price ?? 0) * (pq.quantity),
|
||||
);
|
||||
}).toList();
|
||||
onPrintSplit(
|
||||
context,
|
||||
order: order.copyWith(
|
||||
orderItems: updatedOrderItems,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.print_rounded,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'Cetak Struk',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummaryFooter(Order order) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.grey.shade50,
|
||||
Colors.white,
|
||||
],
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
bottom: Radius.circular(24),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Decorative Divider
|
||||
Container(
|
||||
height: 1,
|
||||
margin: const EdgeInsets.only(bottom: 20),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
AppColors.primary.withOpacity(0.3),
|
||||
Colors.transparent,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Subtotal Row
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.shopping_cart_outlined,
|
||||
size: 16,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Subtotal (${widget.productQuantity.length} items)',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey.shade600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
widget.nominalBayar.currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Total Payment Row
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.1),
|
||||
AppColors.primary.withOpacity(0.05),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.payments_rounded,
|
||||
size: 16,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'Total Pembayaran',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.primary,
|
||||
AppColors.primary.withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
widget.nominalBayar.currencyFormatRpV2,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:enaklo_pos/data/models/response/table_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
+32
-45
@@ -5,10 +5,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: _fe_analyzer_shared
|
||||
sha256: "16e298750b6d0af7ce8a3ba7c18c69c3785d11b15ec83f6dcd0ad2a0009b3cab"
|
||||
sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "76.0.0"
|
||||
version: "67.0.0"
|
||||
_flutterfire_internals:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -17,19 +17,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.61"
|
||||
_macros:
|
||||
dependency: transitive
|
||||
description: dart
|
||||
source: sdk
|
||||
version: "0.3.3"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
sha256: "1f14db053a8c23e260789e9b0980fa27f2680dd640932cae5e1137cce0e46e1e"
|
||||
sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.11.0"
|
||||
version: "6.4.1"
|
||||
another_flushbar:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -114,10 +109,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build
|
||||
sha256: cef23f1eda9b57566c81e2133d196f8e3df48f244b317368d65c5943d91148f0
|
||||
sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.2"
|
||||
version: "2.4.1"
|
||||
build_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -138,26 +133,26 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build_resolvers
|
||||
sha256: "99d3980049739a985cf9b21f30881f46db3ebc62c5b8d5e60e27440876b1ba1e"
|
||||
sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.3"
|
||||
version: "2.4.2"
|
||||
build_runner:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: build_runner
|
||||
sha256: "74691599a5bc750dc96a6b4bfd48f7d9d66453eab04c7f4063134800d6a5c573"
|
||||
sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.14"
|
||||
version: "2.4.13"
|
||||
build_runner_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build_runner_core
|
||||
sha256: "22e3aa1c80e0ada3722fe5b63fd43d9c8990759d0a2cf489c8c5d7b2bdebc021"
|
||||
sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.0.0"
|
||||
version: "7.3.2"
|
||||
built_collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -322,10 +317,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: dart_style
|
||||
sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab"
|
||||
sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.7"
|
||||
version: "2.3.6"
|
||||
dartx:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -633,10 +628,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: freezed
|
||||
sha256: "44c19278dd9d89292cf46e97dc0c1e52ce03275f40a97c5a348e802a924bf40e"
|
||||
sha256: a434911f643466d78462625df76fd9eb13e57348ff43fe1f77bbe909522c67a1
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.7"
|
||||
version: "2.5.2"
|
||||
freezed_annotation:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -857,26 +852,26 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
|
||||
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.0.9"
|
||||
version: "11.0.2"
|
||||
leak_tracker_flutter_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_flutter_testing
|
||||
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
|
||||
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.9"
|
||||
version: "3.0.10"
|
||||
leak_tracker_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_testing
|
||||
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
|
||||
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
version: "3.0.2"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -893,14 +888,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
macros:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: macros
|
||||
sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.3-main.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -921,10 +908,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
|
||||
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
version: "1.17.0"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1451,13 +1438,13 @@ packages:
|
||||
source: hosted
|
||||
version: "30.2.5"
|
||||
synchronized:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: synchronized
|
||||
sha256: "69fe30f3a8b04a0be0c15ae6490fc859a78ef4c43ae2dd5e8a623d45bfcf9225"
|
||||
sha256: c254ade258ec8282947a0acbbc90b9575b4f19673533ee46f2f6e9b3aeefd7c0
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.3.0+3"
|
||||
version: "3.4.0"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1470,10 +1457,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
|
||||
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.4"
|
||||
version: "0.7.7"
|
||||
time:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1534,10 +1521,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
|
||||
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
version: "2.2.0"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1635,5 +1622,5 @@ packages:
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
sdks:
|
||||
dart: ">=3.7.0 <4.0.0"
|
||||
dart: ">=3.8.0 <4.0.0"
|
||||
flutter: ">=3.29.0"
|
||||
|
||||
+2
-1
@@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.0.0+1
|
||||
version: 1.0.5+16
|
||||
|
||||
environment:
|
||||
sdk: ">=3.2.4 <4.0.0"
|
||||
@@ -70,6 +70,7 @@ dependencies:
|
||||
firebase_core: ^4.1.0
|
||||
firebase_crashlytics: ^5.0.1
|
||||
path: ^1.9.1
|
||||
synchronized: ^3.4.0
|
||||
# imin_printer: ^0.6.10
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user