Printer Local data and remove unused

This commit is contained in:
efrilm 2025-09-20 03:56:07 +07:00
parent 04811015b6
commit 44402140fb
46 changed files with 685 additions and 7150 deletions

View File

@ -23,7 +23,7 @@ class DatabaseHelper {
return await openDatabase(
path,
version: 1,
version: 2, // Updated version for printer table
onCreate: _onCreate,
onUpgrade: _onUpgrade,
);
@ -66,17 +66,49 @@ class DatabaseHelper {
)
''');
// Printer table - NEW
await db.execute('''
CREATE TABLE printers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
code TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
address TEXT,
paper TEXT,
type TEXT,
created_at TEXT,
updated_at TEXT
)
''');
// Create indexes for better performance
await db.execute(
'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_products_description ON products(description)');
await db.execute('CREATE INDEX idx_printers_code ON printers(code)');
await db.execute('CREATE INDEX idx_printers_type ON printers(type)');
}
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
// Handle database upgrades here
if (oldVersion < 2) {
// Add printer table in version 2
await db.execute('''
CREATE TABLE printers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
code TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
address TEXT,
paper TEXT,
type TEXT,
created_at TEXT,
updated_at TEXT
)
''');
// 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)');
}
}
Future<void> close() async {

View File

@ -7,7 +7,7 @@ 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/product_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';
import 'package:enaklo_pos/data/type/bussines_type.dart';
@ -28,13 +28,13 @@ Future<void> onPrint(
if (outlet.businessType == BusinessType.restaurant) {
final checkerPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('checker');
await PrinterLocalDatasource.instance.getPrinterByCode('checker');
final kitchenPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('kitchen');
await PrinterLocalDatasource.instance.getPrinterByCode('kitchen');
final barPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('bar');
await PrinterLocalDatasource.instance.getPrinterByCode('bar');
final receiptPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('receipt');
await PrinterLocalDatasource.instance.getPrinterByCode('receipt');
if (receiptPrinter != null) {
try {
@ -232,7 +232,7 @@ Future<void> onPrint(
if (outlet.businessType == BusinessType.ticketing) {
final ticketPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('ticket');
await PrinterLocalDatasource.instance.getPrinterByCode('ticket');
final barcode = await generateBarcodeAsUint8List(order.orderNumber ?? "");
@ -288,7 +288,7 @@ Future<void> onPrintRecipt(
required List<ProductQuantity> productQuantity,
}) async {
final receiptPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('receipt');
await PrinterLocalDatasource.instance.getPrinterByCode('receipt');
final authData = await AuthLocalDataSource().getAuthData();
final settings = await SettingsLocalDatasource().getTax();
final outlet = await OutletLocalDatasource().get();
@ -346,7 +346,7 @@ Future<void> onPrinVoidRecipt(
required int totalVoid,
}) async {
final receiptPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('receipt');
await PrinterLocalDatasource.instance.getPrinterByCode('receipt');
final authData = await AuthLocalDataSource().getAuthData();
final settings = await SettingsLocalDatasource().getTax();
final outlet = await OutletLocalDatasource().get();

View File

@ -0,0 +1,317 @@
import 'dart:developer';
import 'package:enaklo_pos/core/database/database_handler.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:sqflite/sqflite.dart';
class PrinterLocalDatasource {
static PrinterLocalDatasource? _instance;
PrinterLocalDatasource._internal();
static PrinterLocalDatasource get instance {
_instance ??= PrinterLocalDatasource._internal();
return _instance!;
}
Future<Database> get _db async => await DatabaseHelper.instance.database;
// Create new printer
Future<int> createPrinter(PrintModel printer) async {
final db = await _db;
try {
log('Creating printer: ${printer.toString()}');
final id = await db.insert(
'printers',
printer.toMapForInsert(),
conflictAlgorithm:
ConflictAlgorithm.abort, // Fail if code already exists
);
log('Successfully created printer with ID: $id');
return id;
} catch (e) {
log('Error creating printer: $e');
rethrow;
}
}
// Update existing printer
Future<void> updatePrinter(PrintModel printer, int id) async {
final db = await _db;
try {
log('Updating printer ID $id: ${printer.toString()}');
final updatedRows = await db.update(
'printers',
printer.toMapForUpdate(),
where: 'id = ?',
whereArgs: [id],
);
if (updatedRows == 0) {
throw Exception('Printer with ID $id not found');
}
log('Successfully updated printer ID: $id');
} catch (e) {
log('Error updating printer: $e');
rethrow;
}
}
// Delete printer by ID
Future<void> deletePrinter(int id) async {
final db = await _db;
try {
log('Deleting printer ID: $id');
final deletedRows = await db.delete(
'printers',
where: 'id = ?',
whereArgs: [id],
);
if (deletedRows == 0) {
throw Exception('Printer with ID $id not found');
}
log('Successfully deleted printer ID: $id');
} catch (e) {
log('Error deleting printer: $e');
rethrow;
}
}
// Get printer by code
Future<PrintModel?> getPrinterByCode(String code) async {
final db = await _db;
try {
log('Getting printer by code: $code');
final result = await db.query(
'printers',
where: 'code = ?',
whereArgs: [code],
);
if (result.isEmpty) {
log('Printer with code $code not found');
return null;
}
final printer = PrintModel.fromMap(result.first);
log('Found printer: ${printer.toString()}');
return printer;
} catch (e) {
log('Error getting printer by code: $e');
return null;
}
}
// Get printer by ID
Future<PrintModel?> getPrinterById(int id) async {
final db = await _db;
try {
log('Getting printer by ID: $id');
final result = await db.query(
'printers',
where: 'id = ?',
whereArgs: [id],
);
if (result.isEmpty) {
log('Printer with ID $id not found');
return null;
}
final printer = PrintModel.fromMap(result.first);
log('Found printer: ${printer.toString()}');
return printer;
} catch (e) {
log('Error getting printer by ID: $e');
return null;
}
}
// Get all printers
Future<List<PrintModel>> getAllPrinters() async {
final db = await _db;
try {
log('Getting all printers');
final result = await db.query(
'printers',
orderBy: 'name ASC',
);
final printers = result.map((map) => PrintModel.fromMap(map)).toList();
log('Found ${printers.length} printers');
return printers;
} catch (e) {
log('Error getting all printers: $e');
return [];
}
}
// Get printers by type
Future<List<PrintModel>> getPrintersByType(String type) async {
final db = await _db;
try {
log('Getting printers by type: $type');
final result = await db.query(
'printers',
where: 'type = ?',
whereArgs: [type],
orderBy: 'name ASC',
);
final printers = result.map((map) => PrintModel.fromMap(map)).toList();
log('Found ${printers.length} printers with type $type');
return printers;
} catch (e) {
log('Error getting printers by type: $e');
return [];
}
}
// Search printers by name
Future<List<PrintModel>> searchPrintersByName(String query) async {
final db = await _db;
try {
log('Searching printers by name: $query');
final result = await db.query(
'printers',
where: 'name LIKE ?',
whereArgs: ['%$query%'],
orderBy: 'name ASC',
);
final printers = result.map((map) => PrintModel.fromMap(map)).toList();
log('Found ${printers.length} printers matching "$query"');
return printers;
} catch (e) {
log('Error searching printers: $e');
return [];
}
}
// Check if printer code exists
Future<bool> isPrinterCodeExists(String code, {int? excludeId}) async {
final db = await _db;
try {
String whereClause = 'code = ?';
List<dynamic> whereArgs = [code];
if (excludeId != null) {
whereClause += ' AND id != ?';
whereArgs.add(excludeId);
}
final result = await db.query(
'printers',
where: whereClause,
whereArgs: whereArgs,
);
final exists = result.isNotEmpty;
log('Printer code "$code" exists: $exists');
return exists;
} catch (e) {
log('Error checking printer code existence: $e');
return false;
}
}
// Get printer statistics
Future<Map<String, dynamic>> getPrinterStats() async {
final db = await _db;
try {
// Total count
final totalResult =
await db.rawQuery('SELECT COUNT(*) as total FROM printers');
final totalCount = totalResult.first['total'] as int;
// Count by type
final typeResult = await db.rawQuery('''
SELECT type, COUNT(*) as count
FROM printers
WHERE type IS NOT NULL
GROUP BY type
''');
final typeStats = <String, int>{};
for (final row in typeResult) {
typeStats[row['type'] as String] = row['count'] as int;
}
final stats = {
'total_printers': totalCount,
'by_type': typeStats,
};
log('Printer stats: $stats');
return stats;
} catch (e) {
log('Error getting printer stats: $e');
return {
'total_printers': 0,
'by_type': <String, int>{},
};
}
}
// Clear all printers (for testing/reset purposes)
Future<void> clearAllPrinters() async {
final db = await _db;
try {
log('Clearing all printers');
await db.delete('printers');
log('All printers cleared');
} catch (e) {
log('Error clearing printers: $e');
rethrow;
}
}
// Batch insert printers
Future<void> insertPrinters(List<PrintModel> printers) async {
final db = await _db;
try {
log('Batch inserting ${printers.length} printers');
await db.transaction((txn) async {
for (final printer in printers) {
await txn.insert(
'printers',
printer.toMapForInsert(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
}
});
log('Successfully batch inserted ${printers.length} printers');
} catch (e) {
log('Error batch inserting printers: $e');
rethrow;
}
}
}

View File

@ -1,639 +0,0 @@
import 'dart:developer';
import 'dart:ui';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:enaklo_pos/data/models/response/product_response_model.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:enaklo_pos/presentation/home/models/order_model.dart';
import 'package:enaklo_pos/presentation/table/models/draft_order_item.dart';
import 'package:enaklo_pos/presentation/table/models/draft_order_model.dart';
import 'package:sqflite/sqflite.dart';
import '../../presentation/home/models/product_quantity.dart';
class ProductLocalDatasource {
ProductLocalDatasource._init();
static final ProductLocalDatasource instance = ProductLocalDatasource._init();
final String tableProduct = 'products';
final String tableOrder = 'orders';
final String tableOrderItem = 'order_items';
final String tableManagement = 'table_management';
final String tablePrint = 'prints';
static Database? _database;
// "id": 1,
// "category_id": 1,
// "name": "Mie Ayam",
// "description": "Ipsa dolorem impedit dolor. Libero nisi quidem expedita quod mollitia ad. Voluptas ut quia nemo nisi odit fuga. Fugit autem qui ratione laborum eum.",
// "image": "https://via.placeholder.com/640x480.png/002200?text=nihil",
// "price": "2000.44",
// "stock": 94,
// "status": 1,
// "is_favorite": 1,
// "created_at": "2024-02-08T14:30:22.000000Z",
// "updated_at": "2024-02-08T15:14:22.000000Z"
Future<void> _createDb(Database db, int version) async {
await db.execute('''
CREATE TABLE $tableProduct (
id INTEGER PRIMARY KEY,
product_id INTEGER,
name TEXT,
printer_type TEXT,
categoryId INTEGER,
categoryName TEXT,
description TEXT,
image TEXT,
price TEXT,
stock INTEGER,
status INTEGER,
isFavorite INTEGER,
createdAt TEXT,
updatedAt TEXT
)
''');
await db.execute('''
CREATE TABLE $tableOrder (
id INTEGER PRIMARY KEY AUTOINCREMENT,
payment_amount INTEGER,
sub_total INTEGER,
tax INTEGER,
discount INTEGER,
discount_amount INTEGER,
service_charge INTEGER,
total INTEGER,
payment_method TEXT,
total_item INTEGER,
id_kasir INTEGER,
nama_kasir TEXT,
transaction_time TEXT,
table_number INTEGER,
customer_name TEXT,
status TEXT,
payment_status TEXT,
order_type TEXT DEFAULT 'DINE IN',
is_sync INTEGER DEFAULT 0
)
''');
await db.execute('''
CREATE TABLE $tableOrderItem (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id_order INTEGER,
id_product INTEGER,
quantity INTEGER,
price INTEGER,
notes TEXT DEFAULT ''
)
''');
await db.execute('''
CREATE TABLE $tableManagement (
id INTEGER PRIMARY KEY AUTOINCREMENT,
table_name Text,
start_time Text,
order_id INTEGER,
payment_amount INTEGER,
x_position REAL NOT NULL,
y_position REAL NOT NULL,
status TEXT
)
''');
await db.execute('''
CREATE TABLE draft_orders (
id INTEGER PRIMARY KEY AUTOINCREMENT,
total_item INTEGER,
subtotal INTEGER,
tax INTEGER,
discount INTEGER,
discount_amount INTEGER,
service_charge INTEGER,
total INTEGER,
transaction_time TEXT,
table_number INTEGER,
draft_name TEXT
)
''');
await db.execute('''
CREATE TABLE draft_order_items (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id_draft_order INTEGER,
id_product INTEGER,
quantity INTEGER,
price INTEGER
)
''');
await db.execute('''
CREATE TABLE $tablePrint (
id INTEGER PRIMARY KEY AUTOINCREMENT,
code TEXT,
name TEXT,
address TEXT,
paper TEXT,
type TEXT
)
''');
}
Future<Database> _initDB(String filePath) async {
final dbPath = await getDatabasesPath();
final path = dbPath + filePath;
// Force delete existing database to ensure new schema
try {
final dbExists = await databaseExists(path);
if (dbExists) {
log("Deleting existing database to ensure new schema with order_type column");
// await deleteDatabase(path);
}
} catch (e) {
log("Error deleting database: $e");
}
return await openDatabase(
path,
version: 2,
onCreate: _createDb,
onUpgrade: _onUpgrade,
);
}
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
if (oldVersion < 2) {
// Add order_type column to orders table if it doesn't exist
try {
await db.execute(
'ALTER TABLE $tableOrder ADD COLUMN order_type TEXT DEFAULT "DINE IN"');
log("Added order_type column to orders table");
} catch (e) {
log("order_type column might already exist: $e");
}
}
}
Future<Database> get database async {
if (_database != null) return _database!;
_database = await _initDB('dbresto36.db');
return _database!;
}
//save order
Future<int> saveOrder(OrderModel order) async {
final db = await instance.database;
// Since we're forcing database recreation, order_type column should exist
final orderMap = order.toMap(includeOrderType: true);
log("Final orderMap for insertion: $orderMap");
int id = await db.insert(tableOrder, orderMap,
conflictAlgorithm: ConflictAlgorithm.replace);
for (var item in order.orderItems) {
log("Item: ${item.toLocalMap(id)}");
await db.insert(tableOrderItem, item.toLocalMap(id),
conflictAlgorithm: ConflictAlgorithm.replace);
}
log("Success Order: ${order.toMap()}");
return id;
}
//get data order
Future<List<OrderModel>> getOrderByIsNotSync() async {
final db = await instance.database;
final List<Map<String, dynamic>> maps =
await db.query(tableOrder, where: 'is_sync = ?', whereArgs: [0]);
return List.generate(maps.length, (i) {
return OrderModel.fromMap(maps[i]);
});
}
Future<List<OrderModel>> getAllOrder(
DateTime date,
) async {
final db = await instance.database;
//date to iso8601
final dateIso = date.toIso8601String();
//get yyyy-MM-dd
final dateYYYYMMDD = dateIso.substring(0, 10);
// final formattedDate = DateFormat('yyyy-MM-dd').format(date);
final List<Map<String, dynamic>> maps = await db.query(
tableOrder,
where: 'transaction_time like ?',
whereArgs: ['$dateYYYYMMDD%'],
// where: 'transaction_time BETWEEN ? AND ?',
// whereArgs: [
// DateFormat.yMd().format(start),
// DateFormat.yMd().format(end)
// ],
);
return List.generate(maps.length, (i) {
log("Save save OrderModel: ${OrderModel.fromMap(maps[i])}");
return OrderModel.fromMap(maps[i]);
});
}
Future<List<OrderModel>> getAllOrderByRange(
DateTime start, DateTime end) async {
final db = await instance.database;
// Format ke ISO 8601 untuk range, hasil: yyyy-MM-ddTHH:mm:ss
final startIso = start.toIso8601String();
final endIso = end.toIso8601String();
final startDateYYYYMMDD = startIso.substring(0, 10);
final endDateYYYYMMDD = endIso.substring(0, 10);
final List<Map<String, dynamic>> maps = await db.query(
tableOrder,
where: 'substr(transaction_time, 1, 10) BETWEEN ? AND ?',
whereArgs: [startDateYYYYMMDD, endDateYYYYMMDD],
orderBy: 'transaction_time DESC',
);
log("Get All Order By Range: $startDateYYYYMMDD $endDateYYYYMMDD");
return List.generate(maps.length, (i) {
log("Save save OrderModel: ${OrderModel.fromMap(maps[i])}");
return OrderModel.fromMap(maps[i]);
});
}
//get order item by order id
Future<List<ProductQuantity>> getOrderItemByOrderId(int orderId) async {
final db = await instance.database;
final List<Map<String, dynamic>> maps = await db
.query(tableOrderItem, where: 'id_order = ?', whereArgs: [orderId]);
return List.generate(maps.length, (i) {
log("ProductQuantity: ${ProductQuantity.fromLocalMap(maps[i])}");
return ProductQuantity.fromLocalMap(maps[i]);
});
}
//update payment status by order id
Future<void> updatePaymentStatus(
int orderId, String paymentStatus, String status) async {
final db = await instance.database;
await db.update(
tableOrder, {'payment_status': paymentStatus, 'status': status},
where: 'id = ?', whereArgs: [orderId]);
log('update payment status success | order id: $orderId | payment status: $paymentStatus | status: $status');
}
//update order is sync
Future<void> updateOrderIsSync(int orderId) async {
final db = await instance.database;
await db.update(tableOrder, {'is_sync': 1},
where: 'id = ?', whereArgs: [orderId]);
}
//insert data product
Future<void> insertProduct(Product product) async {
log("Product: ${product.toMap()}");
final db = await instance.database;
await db.insert(tableProduct, product.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace);
}
//update product
Future<void> updateProduct(Product product) async {
log("Update Product: ${product.toMap()}");
final db = await instance.database;
await db.update(
tableProduct,
product.toLocalMap(),
where: 'product_id = ?',
whereArgs: [product.id],
);
}
//insert list of product
Future<void> insertProducts(List<Product> products) async {
final db = await instance.database;
log("Save Products to Local");
for (var product in products) {
await db.insert(tableProduct, product.toLocalMap(),
conflictAlgorithm: ConflictAlgorithm.replace);
log('inserted success id: ${product.id} | name: ${product.name} | price: ${product.price} ');
}
}
//get all products
Future<List<Product>> getProducts() async {
final db = await instance.database;
final List<Map<String, dynamic>> maps = await db.query(tableProduct);
return List.generate(maps.length, (i) {
return Product.fromLocalMap(maps[i]);
});
}
Future<Product?> getProductById(int id) async {
final db = await instance.database;
final result =
await db.query(tableProduct, where: 'product_id = ?', whereArgs: [id]);
if (result.isEmpty) {
return null;
}
return Product.fromMap(result.first);
}
// get Last Table Management
Future<TableModel?> getLastTableManagement() async {
final db = await instance.database;
final List<Map<String, dynamic>> maps =
await db.query(tableManagement, orderBy: 'id DESC', limit: 1);
if (maps.isEmpty) {
return null;
}
return TableModel.fromMap(maps[0]);
}
// generate table managent with count
Future<void> createTableManagement(String tableName, Offset position) async {
// final db = await instance.database;
// TableModel newTable = TableModel(
// tableName: tableName,
// status: 'available',
// orderId: 0,
// paymentAmount: 0,
// startTime: DateTime.now().toIso8601String(),
// position: position,
// );
// await db.insert(
// tableManagement,
// newTable.toMap(),
// );
}
// change position table
Future<void> changePositionTable(int id, Offset position) async {
final db = await instance.database;
await db.update(
tableManagement,
{'x_position': position.dx, 'y_position': position.dy},
where: 'id = ?',
whereArgs: [id],
);
}
// update table
Future<void> updateTable(TableModel table) async {
final db = await instance.database;
await db.update(
tableManagement,
table.toMap(),
where: 'id = ?',
whereArgs: [table.id],
);
}
// get all table
Future<List<TableModel>> getAllTable() async {
final db = await instance.database;
final List<Map<String, dynamic>> maps = await db.query(tableManagement);
log("Table Management: $maps");
return List.generate(maps.length, (i) {
return TableModel.fromMap(maps[i]);
});
}
// get last order where table number
Future<OrderModel?> getLastOrderTable(int tableNumber) async {
final db = await instance.database;
final List<Map<String, dynamic>> maps = await db.query(
tableOrder,
where: 'table_number = ?',
whereArgs: [tableNumber],
orderBy: 'id DESC', // Urutkan berdasarkan id dari yang terbesar (terbaru)
limit: 1, // Ambil hanya satu data terakhir
);
if (maps.isEmpty) {
return null;
}
return OrderModel.fromMap(maps[0]);
}
// get table by status
Future<List<TableModel>> getTableByStatus(String status) async {
final db = await instance.database;
List<Map<String, dynamic>> maps;
if (status == 'all') {
// Get all tables
maps = await db.query(tableManagement);
log("Getting all tables, found: ${maps.length}");
// If no tables exist, create some default tables
if (maps.isEmpty) {
log("No tables found, creating default tables...");
await _createDefaultTables();
maps = await db.query(tableManagement);
log("After creating default tables, found: ${maps.length}");
}
} else {
// Get tables by specific status
maps = await db.query(
tableManagement,
where: 'status = ?',
whereArgs: [status],
);
log("Getting tables with status '$status', found: ${maps.length}");
}
final tables = List.generate(maps.length, (i) {
return TableModel.fromMap(maps[i]);
});
log("Returning ${tables.length} tables");
tables.forEach((table) {
log("Table: ${table.tableName} (ID: ${table.id}, Status: ${table.status})");
});
return tables;
}
// Create default tables if none exist
Future<void> _createDefaultTables() async {
final db = await instance.database;
// Create 5 default tables
for (int i = 1; i <= 5; i++) {
await db.insert(tableManagement, {
'table_name': 'Table $i',
'start_time': DateTime.now().toIso8601String(),
'order_id': 0,
'payment_amount': 0,
'x_position': 100.0 + (i * 50.0),
'y_position': 100.0 + (i * 50.0),
'status': 'available',
});
log("Created default table: Table $i");
}
}
// update status tabel
Future<void> updateStatusTable(TableModel table) async {
log("Updating table status: ${table.toMap()}");
final db = await instance.database;
await db.update(tableManagement, table.toMap(),
where: 'id = ?', whereArgs: [table.id]);
log("Success Update Status Table: ${table.toMap()}");
// Verify the update
final updatedTable = await db.query(
tableManagement,
where: 'id = ?',
whereArgs: [table.id],
);
if (updatedTable.isNotEmpty) {
log("Verified table update: ${updatedTable.first}");
}
}
// Debug method to reset all tables to available status
Future<void> resetAllTablesToAvailable() async {
log("Resetting all tables to available status...");
final db = await instance.database;
await db.update(
tableManagement,
{
'status': 'available',
'order_id': 0,
'payment_amount': 0,
'start_time': DateTime.now().toIso8601String(),
},
);
log("All tables reset to available status");
}
//delete all products
Future<void> deleteAllProducts() async {
final db = await instance.database;
await db.delete(tableProduct);
}
Future<int> saveDraftOrder(DraftOrderModel order) async {
log("save draft order: ${order.toMapForLocal()}");
final db = await instance.database;
int id = await db.insert('draft_orders', order.toMapForLocal());
log("draft order id: $id | ${order.discountAmount}");
for (var orderItem in order.orders) {
await db.insert('draft_order_items', orderItem.toMapForLocal(id));
log("draft order item ${orderItem.toMapForLocal(id)}");
}
return id;
}
//get all draft order
Future<List<DraftOrderModel>> getAllDraftOrder() async {
final db = await instance.database;
final result = await db.query('draft_orders', orderBy: 'id ASC');
List<DraftOrderModel> results = await Future.wait(result.map((item) async {
// Your asynchronous operation here
final draftOrderItem =
await getDraftOrderItemByOrderId(item['id'] as int);
return DraftOrderModel.newFromLocalMap(item, draftOrderItem);
}));
return results;
}
// get Darft Order by id
Future<DraftOrderModel?> getDraftOrderById(int id) async {
final db = await instance.database;
final result =
await db.query('draft_orders', where: 'id = ?', whereArgs: [id]);
if (result.isEmpty) {
return null;
}
final draftOrderItem =
await getDraftOrderItemByOrderId(result.first['id'] as int);
log("draft order item: $draftOrderItem | ${result.first.toString()}");
return DraftOrderModel.newFromLocalMap(result.first, draftOrderItem);
}
//get draft order item by id order
Future<List<DraftOrderItem>> getDraftOrderItemByOrderId(int idOrder) async {
final db = await instance.database;
final result =
await db.query('draft_order_items', where: 'id_draft_order = $idOrder');
List<DraftOrderItem> results = await Future.wait(result.map((item) async {
// Your asynchronous operation here
final product = await getProductById(item['id_product'] as int);
return DraftOrderItem(
product: product!, quantity: item['quantity'] as int);
}));
return results;
}
//remove draft order by id
Future<void> removeDraftOrderById(int id) async {
final db = await instance.database;
await db.delete('draft_orders', where: 'id = ?', whereArgs: [id]);
await db.delete('draft_order_items',
where: 'id_draft_order = ?', whereArgs: [id]);
}
//update draft order
Future<void> updateDraftOrder(DraftOrderModel draftOrder) async {
final db = await instance.database;
// Update the draft order
await db.update(
'draft_orders',
draftOrder.toMapForLocal(),
where: 'id = ?',
whereArgs: [draftOrder.id],
);
// Remove existing items and add new ones
await db.delete('draft_order_items',
where: 'id_draft_order = ?', whereArgs: [draftOrder.id]);
for (var orderItem in draftOrder.orders) {
await db.insert(
'draft_order_items', orderItem.toMapForLocal(draftOrder.id!));
}
}
/// create printer
Future<void> createPrinter(PrintModel print) async {
final db = await instance.database;
await db.insert(tablePrint, print.toMap());
}
Future<void> updatePrinter(PrintModel print, int id) async {
final db = await instance.database;
log("Update Printer: ${print.toMap()} | id: $id");
await db
.update(tablePrint, print.toMap(), where: 'id = ?', whereArgs: [id]);
}
Future<void> deletePrinter(int id) async {
final db = await instance.database;
await db.delete(tablePrint, where: 'id = ?', whereArgs: [id]);
}
// get printer by code
Future<PrintModel?> getPrinterByCode(String code) async {
final db = await instance.database;
final result =
await db.query(tablePrint, where: 'code = ?', whereArgs: [code]);
if (result.isEmpty) {
return null;
}
return PrintModel.fromMap(result.first);
}
}

View File

@ -5,6 +5,8 @@ class PrintModel {
final String address;
final String paper;
final String type;
final DateTime? createdAt;
final DateTime? updatedAt;
PrintModel({
this.id,
@ -13,26 +15,130 @@ class PrintModel {
required this.address,
required this.paper,
required this.type,
this.createdAt,
this.updatedAt,
});
// from map
// Factory constructor from map (updated)
factory PrintModel.fromMap(Map<String, dynamic> map) {
return PrintModel(
id: map['id'],
code: map['code'],
name: map['name'],
address: map['address'],
paper: map['paper'],
type: map['type'],
id: map['id'] as int?,
code: map['code'] as String,
name: map['name'] as String,
address: map['address'] as String,
paper: map['paper'] as String,
type: map['type'] as String,
createdAt: map['created_at'] != null
? DateTime.tryParse(map['created_at'] as String)
: null,
updatedAt: map['updated_at'] != null
? DateTime.tryParse(map['updated_at'] as String)
: null,
);
}
// to map
Map<String, dynamic> toMap() => {
"code": code,
"name": name,
"address": address,
"paper": paper,
"type": type,
};
// Convert to map for database insertion (without id, with timestamps)
Map<String, dynamic> toMapForInsert() {
final now = DateTime.now().toIso8601String();
return {
'code': code,
'name': name,
'address': address,
'paper': paper,
'type': type,
'created_at': now,
'updated_at': now,
};
}
// Convert to map for database update (without id and created_at)
Map<String, dynamic> toMapForUpdate() {
return {
'code': code,
'name': name,
'address': address,
'paper': paper,
'type': type,
'updated_at': DateTime.now().toIso8601String(),
};
}
// Convert to complete map (original method, enhanced)
Map<String, dynamic> toMap() {
return {
if (id != null) 'id': id,
'code': code,
'name': name,
'address': address,
'paper': paper,
'type': type,
if (createdAt != null) 'created_at': createdAt!.toIso8601String(),
if (updatedAt != null) 'updated_at': updatedAt!.toIso8601String(),
};
}
// Copy with method for creating modified instances
PrintModel copyWith({
int? id,
String? code,
String? name,
String? address,
String? paper,
String? type,
DateTime? createdAt,
DateTime? updatedAt,
}) {
return PrintModel(
id: id ?? this.id,
code: code ?? this.code,
name: name ?? this.name,
address: address ?? this.address,
paper: paper ?? this.paper,
type: type ?? this.type,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
}
// Equality and hashCode
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is PrintModel &&
other.id == id &&
other.code == code &&
other.name == name &&
other.address == address &&
other.paper == paper &&
other.type == type;
}
@override
int get hashCode {
return Object.hash(id, code, name, address, paper, type);
}
// String representation for debugging (matches datasource logging)
@override
String toString() {
return 'PrintModel(id: $id, code: $code, name: $name, address: $address, paper: $paper, type: $type, createdAt: $createdAt, updatedAt: $updatedAt)';
}
// Validation methods
bool get isValid {
return code.isNotEmpty &&
name.isNotEmpty &&
address.isNotEmpty &&
paper.isNotEmpty &&
type.isNotEmpty;
}
String? get validationError {
if (code.isEmpty) return 'Printer code cannot be empty';
if (name.isEmpty) return 'Printer name cannot be empty';
if (address.isEmpty) return 'Printer address cannot be empty';
if (paper.isEmpty) return 'Paper size cannot be empty';
if (type.isEmpty) return 'Printer type cannot be empty';
return null;
}
}

View File

@ -38,7 +38,6 @@ import 'package:enaklo_pos/data/datasources/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';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/product_remote_datasource.dart';
import 'package:enaklo_pos/data/datasources/payment_methods_remote_datasource.dart';
import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart';
@ -48,14 +47,11 @@ import 'package:enaklo_pos/presentation/home/bloc/get_table_status/get_table_sta
import 'package:enaklo_pos/presentation/home/bloc/online_checker/online_checker_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/payment_methods/payment_methods_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/qris/qris_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/status_table/status_table_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart';
import 'package:enaklo_pos/presentation/report/blocs/item_sales_report/item_sales_report_bloc.dart';
import 'package:enaklo_pos/presentation/report/blocs/payment_method_report/payment_method_report_bloc.dart';
import 'package:enaklo_pos/presentation/report/blocs/product_sales/product_sales_bloc.dart';
import 'package:enaklo_pos/presentation/report/blocs/summary/summary_bloc.dart';
import 'package:enaklo_pos/presentation/sales/blocs/bloc/last_order_table_bloc.dart';
import 'package:enaklo_pos/presentation/sales/blocs/day_sales/day_sales_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/add_product/add_product_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/create_printer/create_printer_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/get_categories/get_categories_bloc.dart';
@ -69,12 +65,10 @@ import 'package:enaklo_pos/presentation/setting/bloc/update_printer/update_print
import 'package:enaklo_pos/presentation/table/blocs/change_position_table/change_position_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/local_product/local_product_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/order/order_bloc.dart';
import 'package:enaklo_pos/presentation/report/blocs/transaction_report/transaction_report_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/add_discount/add_discount_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/discount/discount_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/sync_order/sync_order_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/sync_product/sync_product_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/tax_settings/tax_settings_bloc.dart';
import 'package:enaklo_pos/presentation/table/blocs/update_table/update_table_bloc.dart';
@ -148,10 +142,6 @@ class _MyAppState extends State<MyApp> {
BlocProvider(
create: (context) => SyncProductBloc(ProductRemoteDatasource()),
),
BlocProvider(
create: (context) =>
LocalProductBloc(ProductLocalDatasource.instance),
),
BlocProvider(
create: (context) =>
CheckoutBloc(settingsLocalDatasource: SettingsLocalDatasource()),
@ -165,9 +155,6 @@ class _MyAppState extends State<MyApp> {
return OrderBloc(OrderRemoteDatasource());
},
),
BlocProvider(
create: (context) => SyncOrderBloc(OrderRemoteDatasource()),
),
BlocProvider(
create: (context) => DiscountBloc(DiscountRemoteDatasource()),
),
@ -189,13 +176,6 @@ class _MyAppState extends State<MyApp> {
BlocProvider(
create: (context) => UpdateTableBloc(),
),
BlocProvider(
create: (context) => StatusTableBloc(ProductLocalDatasource.instance),
),
BlocProvider(
create: (context) =>
LastOrderTableBloc(ProductLocalDatasource.instance),
),
BlocProvider(
create: (context) => GetTableStatusBloc(TableRemoteDataSource()),
),
@ -227,9 +207,6 @@ class _MyAppState extends State<MyApp> {
create: (context) =>
PaymentMethodReportBloc(AnalyticRemoteDatasource()),
),
BlocProvider(
create: (context) => DaySalesBloc(ProductLocalDatasource.instance),
),
BlocProvider(
create: (context) => QrisBloc(MidtransRemoteDatasource()),
),

View File

@ -1,7 +1,6 @@
import 'dart:developer';
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/delivery_response_model.dart';
import 'package:enaklo_pos/data/models/response/discount_response_model.dart';
import 'package:enaklo_pos/presentation/table/models/draft_order_item.dart';
@ -310,9 +309,9 @@ class CheckoutBloc extends Bloc<CheckoutEvent, CheckoutState> {
DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
);
log("draftOrder12: ${draftOrder.toMapForLocal()}");
final orderDraftId =
await ProductLocalDatasource.instance.saveDraftOrder(draftOrder);
emit(_SavedDraftOrder(orderDraftId));
// final orderDraftId =
// await ProductLocalDatasource.instance.saveDraftOrder(draftOrder);
emit(_SavedDraftOrder(0));
});
//load draft order

View File

@ -1,26 +0,0 @@
import 'dart:developer';
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import '../../../../data/models/response/product_response_model.dart';
part 'local_product_bloc.freezed.dart';
part 'local_product_event.dart';
part 'local_product_state.dart';
class LocalProductBloc extends Bloc<LocalProductEvent, LocalProductState> {
final ProductLocalDatasource productLocalDatasource;
LocalProductBloc(
this.productLocalDatasource,
) : super(const _Initial()) {
on<_GetLocalProduct>((event, emit) async {
emit(const _Loading());
final result = await productLocalDatasource.getProducts();
log("Result: ${result.length}");
emit(_Loaded(result));
});
}
}

View File

@ -1,907 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'local_product_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$LocalProductEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function() getLocalProduct,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function()? getLocalProduct,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function()? getLocalProduct,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_GetLocalProduct value) getLocalProduct,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_GetLocalProduct value)? getLocalProduct,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_GetLocalProduct value)? getLocalProduct,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LocalProductEventCopyWith<$Res> {
factory $LocalProductEventCopyWith(
LocalProductEvent value, $Res Function(LocalProductEvent) then) =
_$LocalProductEventCopyWithImpl<$Res, LocalProductEvent>;
}
/// @nodoc
class _$LocalProductEventCopyWithImpl<$Res, $Val extends LocalProductEvent>
implements $LocalProductEventCopyWith<$Res> {
_$LocalProductEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LocalProductEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$StartedImplCopyWith<$Res> {
factory _$$StartedImplCopyWith(
_$StartedImpl value, $Res Function(_$StartedImpl) then) =
__$$StartedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$StartedImplCopyWithImpl<$Res>
extends _$LocalProductEventCopyWithImpl<$Res, _$StartedImpl>
implements _$$StartedImplCopyWith<$Res> {
__$$StartedImplCopyWithImpl(
_$StartedImpl _value, $Res Function(_$StartedImpl) _then)
: super(_value, _then);
/// Create a copy of LocalProductEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$StartedImpl implements _Started {
const _$StartedImpl();
@override
String toString() {
return 'LocalProductEvent.started()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$StartedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function() getLocalProduct,
}) {
return started();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function()? getLocalProduct,
}) {
return started?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function()? getLocalProduct,
required TResult orElse(),
}) {
if (started != null) {
return started();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_GetLocalProduct value) getLocalProduct,
}) {
return started(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_GetLocalProduct value)? getLocalProduct,
}) {
return started?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_GetLocalProduct value)? getLocalProduct,
required TResult orElse(),
}) {
if (started != null) {
return started(this);
}
return orElse();
}
}
abstract class _Started implements LocalProductEvent {
const factory _Started() = _$StartedImpl;
}
/// @nodoc
abstract class _$$GetLocalProductImplCopyWith<$Res> {
factory _$$GetLocalProductImplCopyWith(_$GetLocalProductImpl value,
$Res Function(_$GetLocalProductImpl) then) =
__$$GetLocalProductImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$GetLocalProductImplCopyWithImpl<$Res>
extends _$LocalProductEventCopyWithImpl<$Res, _$GetLocalProductImpl>
implements _$$GetLocalProductImplCopyWith<$Res> {
__$$GetLocalProductImplCopyWithImpl(
_$GetLocalProductImpl _value, $Res Function(_$GetLocalProductImpl) _then)
: super(_value, _then);
/// Create a copy of LocalProductEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$GetLocalProductImpl implements _GetLocalProduct {
const _$GetLocalProductImpl();
@override
String toString() {
return 'LocalProductEvent.getLocalProduct()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$GetLocalProductImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function() getLocalProduct,
}) {
return getLocalProduct();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function()? getLocalProduct,
}) {
return getLocalProduct?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function()? getLocalProduct,
required TResult orElse(),
}) {
if (getLocalProduct != null) {
return getLocalProduct();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_GetLocalProduct value) getLocalProduct,
}) {
return getLocalProduct(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_GetLocalProduct value)? getLocalProduct,
}) {
return getLocalProduct?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_GetLocalProduct value)? getLocalProduct,
required TResult orElse(),
}) {
if (getLocalProduct != null) {
return getLocalProduct(this);
}
return orElse();
}
}
abstract class _GetLocalProduct implements LocalProductEvent {
const factory _GetLocalProduct() = _$GetLocalProductImpl;
}
/// @nodoc
mixin _$LocalProductState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<Product> products) loaded,
required TResult Function(String message) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<Product> products)? loaded,
TResult? Function(String message)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<Product> products)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LocalProductStateCopyWith<$Res> {
factory $LocalProductStateCopyWith(
LocalProductState value, $Res Function(LocalProductState) then) =
_$LocalProductStateCopyWithImpl<$Res, LocalProductState>;
}
/// @nodoc
class _$LocalProductStateCopyWithImpl<$Res, $Val extends LocalProductState>
implements $LocalProductStateCopyWith<$Res> {
_$LocalProductStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$InitialImplCopyWith<$Res> {
factory _$$InitialImplCopyWith(
_$InitialImpl value, $Res Function(_$InitialImpl) then) =
__$$InitialImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$InitialImplCopyWithImpl<$Res>
extends _$LocalProductStateCopyWithImpl<$Res, _$InitialImpl>
implements _$$InitialImplCopyWith<$Res> {
__$$InitialImplCopyWithImpl(
_$InitialImpl _value, $Res Function(_$InitialImpl) _then)
: super(_value, _then);
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$InitialImpl implements _Initial {
const _$InitialImpl();
@override
String toString() {
return 'LocalProductState.initial()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$InitialImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<Product> products) loaded,
required TResult Function(String message) error,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<Product> products)? loaded,
TResult? Function(String message)? error,
}) {
return initial?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<Product> products)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) {
return initial(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) {
return initial?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (initial != null) {
return initial(this);
}
return orElse();
}
}
abstract class _Initial implements LocalProductState {
const factory _Initial() = _$InitialImpl;
}
/// @nodoc
abstract class _$$LoadingImplCopyWith<$Res> {
factory _$$LoadingImplCopyWith(
_$LoadingImpl value, $Res Function(_$LoadingImpl) then) =
__$$LoadingImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LoadingImplCopyWithImpl<$Res>
extends _$LocalProductStateCopyWithImpl<$Res, _$LoadingImpl>
implements _$$LoadingImplCopyWith<$Res> {
__$$LoadingImplCopyWithImpl(
_$LoadingImpl _value, $Res Function(_$LoadingImpl) _then)
: super(_value, _then);
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LoadingImpl implements _Loading {
const _$LoadingImpl();
@override
String toString() {
return 'LocalProductState.loading()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$LoadingImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<Product> products) loaded,
required TResult Function(String message) error,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<Product> products)? loaded,
TResult? Function(String message)? error,
}) {
return loading?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<Product> products)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) {
return loading(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) {
return loading?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (loading != null) {
return loading(this);
}
return orElse();
}
}
abstract class _Loading implements LocalProductState {
const factory _Loading() = _$LoadingImpl;
}
/// @nodoc
abstract class _$$LoadedImplCopyWith<$Res> {
factory _$$LoadedImplCopyWith(
_$LoadedImpl value, $Res Function(_$LoadedImpl) then) =
__$$LoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({List<Product> products});
}
/// @nodoc
class __$$LoadedImplCopyWithImpl<$Res>
extends _$LocalProductStateCopyWithImpl<$Res, _$LoadedImpl>
implements _$$LoadedImplCopyWith<$Res> {
__$$LoadedImplCopyWithImpl(
_$LoadedImpl _value, $Res Function(_$LoadedImpl) _then)
: super(_value, _then);
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? products = null,
}) {
return _then(_$LoadedImpl(
null == products
? _value._products
: products // ignore: cast_nullable_to_non_nullable
as List<Product>,
));
}
}
/// @nodoc
class _$LoadedImpl implements _Loaded {
const _$LoadedImpl(final List<Product> products) : _products = products;
final List<Product> _products;
@override
List<Product> get products {
if (_products is EqualUnmodifiableListView) return _products;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_products);
}
@override
String toString() {
return 'LocalProductState.loaded(products: $products)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LoadedImpl &&
const DeepCollectionEquality().equals(other._products, _products));
}
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(_products));
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LoadedImplCopyWith<_$LoadedImpl> get copyWith =>
__$$LoadedImplCopyWithImpl<_$LoadedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<Product> products) loaded,
required TResult Function(String message) error,
}) {
return loaded(products);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<Product> products)? loaded,
TResult? Function(String message)? error,
}) {
return loaded?.call(products);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<Product> products)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(products);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) {
return loaded(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) {
return loaded?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(this);
}
return orElse();
}
}
abstract class _Loaded implements LocalProductState {
const factory _Loaded(final List<Product> products) = _$LoadedImpl;
List<Product> get products;
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LoadedImplCopyWith<_$LoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$ErrorImplCopyWith<$Res> {
factory _$$ErrorImplCopyWith(
_$ErrorImpl value, $Res Function(_$ErrorImpl) then) =
__$$ErrorImplCopyWithImpl<$Res>;
@useResult
$Res call({String message});
}
/// @nodoc
class __$$ErrorImplCopyWithImpl<$Res>
extends _$LocalProductStateCopyWithImpl<$Res, _$ErrorImpl>
implements _$$ErrorImplCopyWith<$Res> {
__$$ErrorImplCopyWithImpl(
_$ErrorImpl _value, $Res Function(_$ErrorImpl) _then)
: super(_value, _then);
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? message = null,
}) {
return _then(_$ErrorImpl(
null == message
? _value.message
: message // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$ErrorImpl implements _Error {
const _$ErrorImpl(this.message);
@override
final String message;
@override
String toString() {
return 'LocalProductState.error(message: $message)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ErrorImpl &&
(identical(other.message, message) || other.message == message));
}
@override
int get hashCode => Object.hash(runtimeType, message);
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
__$$ErrorImplCopyWithImpl<_$ErrorImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<Product> products) loaded,
required TResult Function(String message) error,
}) {
return error(message);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<Product> products)? loaded,
TResult? Function(String message)? error,
}) {
return error?.call(message);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<Product> products)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(message);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) {
return error(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) {
return error?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(this);
}
return orElse();
}
}
abstract class _Error implements LocalProductState {
const factory _Error(final String message) = _$ErrorImpl;
String get message;
/// Create a copy of LocalProductState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -1,7 +0,0 @@
part of 'local_product_bloc.dart';
@freezed
class LocalProductEvent with _$LocalProductEvent {
const factory LocalProductEvent.started() = _Started;
const factory LocalProductEvent.getLocalProduct() = _GetLocalProduct;
}

View File

@ -1,9 +0,0 @@
part of 'local_product_bloc.dart';
@freezed
class LocalProductState with _$LocalProductState {
const factory LocalProductState.initial() = _Initial;
const factory LocalProductState.loading() = _Loading;
const factory LocalProductState.loaded(List<Product> products) = _Loaded;
const factory LocalProductState.error(String message) = _Error;
}

View File

@ -5,7 +5,6 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import '../../models/order_model.dart';
import '../../models/product_quantity.dart';
@ -78,13 +77,13 @@ class OrderBloc extends Bloc<OrderEvent, OrderState> {
value = false;
}
int id = 0;
if (value) {
id = await ProductLocalDatasource.instance
.saveOrder(dataInput.copyWith(isSync: 1));
} else {
id = await ProductLocalDatasource.instance
.saveOrder(dataInput.copyWith(isSync: 1));
}
// if (value) {
// id = await ProductLocalDatasource.instance
// .saveOrder(dataInput.copyWith(isSync: 1));
// } else {
// id = await ProductLocalDatasource.instance
// .saveOrder(dataInput.copyWith(isSync: 1));
// }
emit(_Loaded(
dataInput,

View File

@ -1,19 +0,0 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'status_table_event.dart';
part 'status_table_state.dart';
part 'status_table_bloc.freezed.dart';
class StatusTableBloc extends Bloc<StatusTableEvent, StatusTableState> {
final ProductLocalDatasource datasource;
StatusTableBloc(this.datasource) : super(StatusTableState.initial()) {
on<_StatusTable>((event, emit) async {
emit(_Loading());
await datasource.updateStatusTable(event.table);
emit(_Success());
});
}
}

View File

@ -1,725 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'status_table_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$StatusTableEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(TableModel table) statusTabel,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(TableModel table)? statusTabel,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(TableModel table)? statusTabel,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_StatusTable value) statusTabel,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_StatusTable value)? statusTabel,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_StatusTable value)? statusTabel,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $StatusTableEventCopyWith<$Res> {
factory $StatusTableEventCopyWith(
StatusTableEvent value, $Res Function(StatusTableEvent) then) =
_$StatusTableEventCopyWithImpl<$Res, StatusTableEvent>;
}
/// @nodoc
class _$StatusTableEventCopyWithImpl<$Res, $Val extends StatusTableEvent>
implements $StatusTableEventCopyWith<$Res> {
_$StatusTableEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of StatusTableEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$StartedImplCopyWith<$Res> {
factory _$$StartedImplCopyWith(
_$StartedImpl value, $Res Function(_$StartedImpl) then) =
__$$StartedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$StartedImplCopyWithImpl<$Res>
extends _$StatusTableEventCopyWithImpl<$Res, _$StartedImpl>
implements _$$StartedImplCopyWith<$Res> {
__$$StartedImplCopyWithImpl(
_$StartedImpl _value, $Res Function(_$StartedImpl) _then)
: super(_value, _then);
/// Create a copy of StatusTableEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$StartedImpl implements _Started {
const _$StartedImpl();
@override
String toString() {
return 'StatusTableEvent.started()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$StartedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(TableModel table) statusTabel,
}) {
return started();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(TableModel table)? statusTabel,
}) {
return started?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(TableModel table)? statusTabel,
required TResult orElse(),
}) {
if (started != null) {
return started();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_StatusTable value) statusTabel,
}) {
return started(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_StatusTable value)? statusTabel,
}) {
return started?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_StatusTable value)? statusTabel,
required TResult orElse(),
}) {
if (started != null) {
return started(this);
}
return orElse();
}
}
abstract class _Started implements StatusTableEvent {
const factory _Started() = _$StartedImpl;
}
/// @nodoc
abstract class _$$StatusTableImplCopyWith<$Res> {
factory _$$StatusTableImplCopyWith(
_$StatusTableImpl value, $Res Function(_$StatusTableImpl) then) =
__$$StatusTableImplCopyWithImpl<$Res>;
@useResult
$Res call({TableModel table});
}
/// @nodoc
class __$$StatusTableImplCopyWithImpl<$Res>
extends _$StatusTableEventCopyWithImpl<$Res, _$StatusTableImpl>
implements _$$StatusTableImplCopyWith<$Res> {
__$$StatusTableImplCopyWithImpl(
_$StatusTableImpl _value, $Res Function(_$StatusTableImpl) _then)
: super(_value, _then);
/// Create a copy of StatusTableEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? table = null,
}) {
return _then(_$StatusTableImpl(
null == table
? _value.table
: table // ignore: cast_nullable_to_non_nullable
as TableModel,
));
}
}
/// @nodoc
class _$StatusTableImpl implements _StatusTable {
const _$StatusTableImpl(this.table);
@override
final TableModel table;
@override
String toString() {
return 'StatusTableEvent.statusTabel(table: $table)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$StatusTableImpl &&
(identical(other.table, table) || other.table == table));
}
@override
int get hashCode => Object.hash(runtimeType, table);
/// Create a copy of StatusTableEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$StatusTableImplCopyWith<_$StatusTableImpl> get copyWith =>
__$$StatusTableImplCopyWithImpl<_$StatusTableImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(TableModel table) statusTabel,
}) {
return statusTabel(table);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(TableModel table)? statusTabel,
}) {
return statusTabel?.call(table);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(TableModel table)? statusTabel,
required TResult orElse(),
}) {
if (statusTabel != null) {
return statusTabel(table);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_StatusTable value) statusTabel,
}) {
return statusTabel(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_StatusTable value)? statusTabel,
}) {
return statusTabel?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_StatusTable value)? statusTabel,
required TResult orElse(),
}) {
if (statusTabel != null) {
return statusTabel(this);
}
return orElse();
}
}
abstract class _StatusTable implements StatusTableEvent {
const factory _StatusTable(final TableModel table) = _$StatusTableImpl;
TableModel get table;
/// Create a copy of StatusTableEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$StatusTableImplCopyWith<_$StatusTableImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$StatusTableState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $StatusTableStateCopyWith<$Res> {
factory $StatusTableStateCopyWith(
StatusTableState value, $Res Function(StatusTableState) then) =
_$StatusTableStateCopyWithImpl<$Res, StatusTableState>;
}
/// @nodoc
class _$StatusTableStateCopyWithImpl<$Res, $Val extends StatusTableState>
implements $StatusTableStateCopyWith<$Res> {
_$StatusTableStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of StatusTableState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$InitialImplCopyWith<$Res> {
factory _$$InitialImplCopyWith(
_$InitialImpl value, $Res Function(_$InitialImpl) then) =
__$$InitialImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$InitialImplCopyWithImpl<$Res>
extends _$StatusTableStateCopyWithImpl<$Res, _$InitialImpl>
implements _$$InitialImplCopyWith<$Res> {
__$$InitialImplCopyWithImpl(
_$InitialImpl _value, $Res Function(_$InitialImpl) _then)
: super(_value, _then);
/// Create a copy of StatusTableState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$InitialImpl implements _Initial {
const _$InitialImpl();
@override
String toString() {
return 'StatusTableState.initial()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$InitialImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() success,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? success,
}) {
return initial?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? success,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) {
return initial(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return initial?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) {
if (initial != null) {
return initial(this);
}
return orElse();
}
}
abstract class _Initial implements StatusTableState {
const factory _Initial() = _$InitialImpl;
}
/// @nodoc
abstract class _$$LoadingImplCopyWith<$Res> {
factory _$$LoadingImplCopyWith(
_$LoadingImpl value, $Res Function(_$LoadingImpl) then) =
__$$LoadingImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LoadingImplCopyWithImpl<$Res>
extends _$StatusTableStateCopyWithImpl<$Res, _$LoadingImpl>
implements _$$LoadingImplCopyWith<$Res> {
__$$LoadingImplCopyWithImpl(
_$LoadingImpl _value, $Res Function(_$LoadingImpl) _then)
: super(_value, _then);
/// Create a copy of StatusTableState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LoadingImpl implements _Loading {
const _$LoadingImpl();
@override
String toString() {
return 'StatusTableState.loading()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$LoadingImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() success,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? success,
}) {
return loading?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? success,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) {
return loading(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return loading?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) {
if (loading != null) {
return loading(this);
}
return orElse();
}
}
abstract class _Loading implements StatusTableState {
const factory _Loading() = _$LoadingImpl;
}
/// @nodoc
abstract class _$$SuccessImplCopyWith<$Res> {
factory _$$SuccessImplCopyWith(
_$SuccessImpl value, $Res Function(_$SuccessImpl) then) =
__$$SuccessImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$SuccessImplCopyWithImpl<$Res>
extends _$StatusTableStateCopyWithImpl<$Res, _$SuccessImpl>
implements _$$SuccessImplCopyWith<$Res> {
__$$SuccessImplCopyWithImpl(
_$SuccessImpl _value, $Res Function(_$SuccessImpl) _then)
: super(_value, _then);
/// Create a copy of StatusTableState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$SuccessImpl implements _Success {
const _$SuccessImpl();
@override
String toString() {
return 'StatusTableState.success()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$SuccessImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() success,
}) {
return success();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? success,
}) {
return success?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? success,
required TResult orElse(),
}) {
if (success != null) {
return success();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) {
return success(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return success?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) {
if (success != null) {
return success(this);
}
return orElse();
}
}
abstract class _Success implements StatusTableState {
const factory _Success() = _$SuccessImpl;
}

View File

@ -1,9 +0,0 @@
part of 'status_table_bloc.dart';
@freezed
class StatusTableEvent with _$StatusTableEvent {
const factory StatusTableEvent.started() = _Started;
const factory StatusTableEvent.statusTabel(
TableModel table,
) = _StatusTable;
}

View File

@ -1,8 +0,0 @@
part of 'status_table_bloc.dart';
@freezed
class StatusTableState with _$StatusTableState {
const factory StatusTableState.initial() = _Initial;
const factory StatusTableState.loading() = _Loading;
const factory StatusTableState.success() = _Success;
}

View File

@ -2,12 +2,12 @@
import 'dart:async';
import 'dart:developer';
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/data/dataoutputs/print_dataoutputs.dart';
import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart';
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
import 'package:enaklo_pos/presentation/home/models/order_type.dart';
import 'package:intl/intl.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
@ -18,8 +18,6 @@ import 'package:enaklo_pos/core/utils/printer_service.dart';
import '../../../core/components/spaces.dart';
import '../../../core/constants/colors.dart';
import '../bloc/order/order_bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
class PaymentQrisDialog extends StatefulWidget {
final List<ProductQuantity> items;
@ -236,7 +234,7 @@ class _PaymentQrisDialogState extends State<PaymentQrisDialog> {
widget.price, bytes!, int.parse(sizeReceipt));
// Get the receipt printer to print QRIS
final receiptPrinter = await ProductLocalDatasource
final receiptPrinter = await PrinterLocalDatasource
.instance
.getPrinterByCode('receipt');

View File

@ -16,7 +16,6 @@ import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart';
import 'package:enaklo_pos/presentation/auth/login_page.dart';
import 'package:enaklo_pos/presentation/report/pages/report_page.dart';
import 'package:enaklo_pos/presentation/setting/bloc/sync_order/sync_order_bloc.dart';
import '../../../core/assets/assets.gen.dart';
import '../../auth/bloc/logout/logout_bloc.dart';
@ -155,10 +154,6 @@ class _DashboardPageState extends State<DashboardPage> {
),
),
online: () {
log("🌐 Dashboard: Internet connection detected, triggering sync");
context.read<SyncOrderBloc>().add(
const SyncOrderEvent.syncOrder(),
);
return Container(
width: 40,
margin:

View File

@ -1,23 +0,0 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/presentation/home/models/order_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'last_order_table_event.dart';
part 'last_order_table_state.dart';
part 'last_order_table_bloc.freezed.dart';
class LastOrderTableBloc
extends Bloc<LastOrderTableEvent, LastOrderTableState> {
final ProductLocalDatasource datasource;
LastOrderTableBloc(this.datasource)
: super(const LastOrderTableState.initial()) {
on<_LastOrderTable>((event, emit) async {
emit(_Loading());
final order = await datasource.getLastOrderTable(event.tableNumber);
emit(_Success(order));
});
}
}

View File

@ -1,762 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'last_order_table_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$LastOrderTableEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(int tableNumber) lastOrderTable,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(int tableNumber)? lastOrderTable,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(int tableNumber)? lastOrderTable,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_LastOrderTable value) lastOrderTable,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_LastOrderTable value)? lastOrderTable,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_LastOrderTable value)? lastOrderTable,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LastOrderTableEventCopyWith<$Res> {
factory $LastOrderTableEventCopyWith(
LastOrderTableEvent value, $Res Function(LastOrderTableEvent) then) =
_$LastOrderTableEventCopyWithImpl<$Res, LastOrderTableEvent>;
}
/// @nodoc
class _$LastOrderTableEventCopyWithImpl<$Res, $Val extends LastOrderTableEvent>
implements $LastOrderTableEventCopyWith<$Res> {
_$LastOrderTableEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LastOrderTableEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$StartedImplCopyWith<$Res> {
factory _$$StartedImplCopyWith(
_$StartedImpl value, $Res Function(_$StartedImpl) then) =
__$$StartedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$StartedImplCopyWithImpl<$Res>
extends _$LastOrderTableEventCopyWithImpl<$Res, _$StartedImpl>
implements _$$StartedImplCopyWith<$Res> {
__$$StartedImplCopyWithImpl(
_$StartedImpl _value, $Res Function(_$StartedImpl) _then)
: super(_value, _then);
/// Create a copy of LastOrderTableEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$StartedImpl implements _Started {
const _$StartedImpl();
@override
String toString() {
return 'LastOrderTableEvent.started()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$StartedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(int tableNumber) lastOrderTable,
}) {
return started();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(int tableNumber)? lastOrderTable,
}) {
return started?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(int tableNumber)? lastOrderTable,
required TResult orElse(),
}) {
if (started != null) {
return started();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_LastOrderTable value) lastOrderTable,
}) {
return started(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_LastOrderTable value)? lastOrderTable,
}) {
return started?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_LastOrderTable value)? lastOrderTable,
required TResult orElse(),
}) {
if (started != null) {
return started(this);
}
return orElse();
}
}
abstract class _Started implements LastOrderTableEvent {
const factory _Started() = _$StartedImpl;
}
/// @nodoc
abstract class _$$LastOrderTableImplCopyWith<$Res> {
factory _$$LastOrderTableImplCopyWith(_$LastOrderTableImpl value,
$Res Function(_$LastOrderTableImpl) then) =
__$$LastOrderTableImplCopyWithImpl<$Res>;
@useResult
$Res call({int tableNumber});
}
/// @nodoc
class __$$LastOrderTableImplCopyWithImpl<$Res>
extends _$LastOrderTableEventCopyWithImpl<$Res, _$LastOrderTableImpl>
implements _$$LastOrderTableImplCopyWith<$Res> {
__$$LastOrderTableImplCopyWithImpl(
_$LastOrderTableImpl _value, $Res Function(_$LastOrderTableImpl) _then)
: super(_value, _then);
/// Create a copy of LastOrderTableEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? tableNumber = null,
}) {
return _then(_$LastOrderTableImpl(
null == tableNumber
? _value.tableNumber
: tableNumber // ignore: cast_nullable_to_non_nullable
as int,
));
}
}
/// @nodoc
class _$LastOrderTableImpl implements _LastOrderTable {
const _$LastOrderTableImpl(this.tableNumber);
@override
final int tableNumber;
@override
String toString() {
return 'LastOrderTableEvent.lastOrderTable(tableNumber: $tableNumber)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LastOrderTableImpl &&
(identical(other.tableNumber, tableNumber) ||
other.tableNumber == tableNumber));
}
@override
int get hashCode => Object.hash(runtimeType, tableNumber);
/// Create a copy of LastOrderTableEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LastOrderTableImplCopyWith<_$LastOrderTableImpl> get copyWith =>
__$$LastOrderTableImplCopyWithImpl<_$LastOrderTableImpl>(
this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(int tableNumber) lastOrderTable,
}) {
return lastOrderTable(tableNumber);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(int tableNumber)? lastOrderTable,
}) {
return lastOrderTable?.call(tableNumber);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(int tableNumber)? lastOrderTable,
required TResult orElse(),
}) {
if (lastOrderTable != null) {
return lastOrderTable(tableNumber);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_LastOrderTable value) lastOrderTable,
}) {
return lastOrderTable(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_LastOrderTable value)? lastOrderTable,
}) {
return lastOrderTable?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_LastOrderTable value)? lastOrderTable,
required TResult orElse(),
}) {
if (lastOrderTable != null) {
return lastOrderTable(this);
}
return orElse();
}
}
abstract class _LastOrderTable implements LastOrderTableEvent {
const factory _LastOrderTable(final int tableNumber) = _$LastOrderTableImpl;
int get tableNumber;
/// Create a copy of LastOrderTableEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LastOrderTableImplCopyWith<_$LastOrderTableImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$LastOrderTableState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(OrderModel? order) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(OrderModel? order)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(OrderModel? order)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LastOrderTableStateCopyWith<$Res> {
factory $LastOrderTableStateCopyWith(
LastOrderTableState value, $Res Function(LastOrderTableState) then) =
_$LastOrderTableStateCopyWithImpl<$Res, LastOrderTableState>;
}
/// @nodoc
class _$LastOrderTableStateCopyWithImpl<$Res, $Val extends LastOrderTableState>
implements $LastOrderTableStateCopyWith<$Res> {
_$LastOrderTableStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LastOrderTableState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$InitialImplCopyWith<$Res> {
factory _$$InitialImplCopyWith(
_$InitialImpl value, $Res Function(_$InitialImpl) then) =
__$$InitialImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$InitialImplCopyWithImpl<$Res>
extends _$LastOrderTableStateCopyWithImpl<$Res, _$InitialImpl>
implements _$$InitialImplCopyWith<$Res> {
__$$InitialImplCopyWithImpl(
_$InitialImpl _value, $Res Function(_$InitialImpl) _then)
: super(_value, _then);
/// Create a copy of LastOrderTableState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$InitialImpl implements _Initial {
const _$InitialImpl();
@override
String toString() {
return 'LastOrderTableState.initial()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$InitialImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(OrderModel? order) success,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(OrderModel? order)? success,
}) {
return initial?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(OrderModel? order)? success,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) {
return initial(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return initial?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) {
if (initial != null) {
return initial(this);
}
return orElse();
}
}
abstract class _Initial implements LastOrderTableState {
const factory _Initial() = _$InitialImpl;
}
/// @nodoc
abstract class _$$LoadingImplCopyWith<$Res> {
factory _$$LoadingImplCopyWith(
_$LoadingImpl value, $Res Function(_$LoadingImpl) then) =
__$$LoadingImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LoadingImplCopyWithImpl<$Res>
extends _$LastOrderTableStateCopyWithImpl<$Res, _$LoadingImpl>
implements _$$LoadingImplCopyWith<$Res> {
__$$LoadingImplCopyWithImpl(
_$LoadingImpl _value, $Res Function(_$LoadingImpl) _then)
: super(_value, _then);
/// Create a copy of LastOrderTableState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LoadingImpl implements _Loading {
const _$LoadingImpl();
@override
String toString() {
return 'LastOrderTableState.loading()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$LoadingImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(OrderModel? order) success,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(OrderModel? order)? success,
}) {
return loading?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(OrderModel? order)? success,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) {
return loading(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return loading?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) {
if (loading != null) {
return loading(this);
}
return orElse();
}
}
abstract class _Loading implements LastOrderTableState {
const factory _Loading() = _$LoadingImpl;
}
/// @nodoc
abstract class _$$SuccessImplCopyWith<$Res> {
factory _$$SuccessImplCopyWith(
_$SuccessImpl value, $Res Function(_$SuccessImpl) then) =
__$$SuccessImplCopyWithImpl<$Res>;
@useResult
$Res call({OrderModel? order});
}
/// @nodoc
class __$$SuccessImplCopyWithImpl<$Res>
extends _$LastOrderTableStateCopyWithImpl<$Res, _$SuccessImpl>
implements _$$SuccessImplCopyWith<$Res> {
__$$SuccessImplCopyWithImpl(
_$SuccessImpl _value, $Res Function(_$SuccessImpl) _then)
: super(_value, _then);
/// Create a copy of LastOrderTableState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? order = freezed,
}) {
return _then(_$SuccessImpl(
freezed == order
? _value.order
: order // ignore: cast_nullable_to_non_nullable
as OrderModel?,
));
}
}
/// @nodoc
class _$SuccessImpl implements _Success {
const _$SuccessImpl(this.order);
@override
final OrderModel? order;
@override
String toString() {
return 'LastOrderTableState.success(order: $order)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SuccessImpl &&
(identical(other.order, order) || other.order == order));
}
@override
int get hashCode => Object.hash(runtimeType, order);
/// Create a copy of LastOrderTableState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
__$$SuccessImplCopyWithImpl<_$SuccessImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(OrderModel? order) success,
}) {
return success(order);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(OrderModel? order)? success,
}) {
return success?.call(order);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(OrderModel? order)? success,
required TResult orElse(),
}) {
if (success != null) {
return success(order);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) {
return success(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return success?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) {
if (success != null) {
return success(this);
}
return orElse();
}
}
abstract class _Success implements LastOrderTableState {
const factory _Success(final OrderModel? order) = _$SuccessImpl;
OrderModel? get order;
/// Create a copy of LastOrderTableState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -1,8 +0,0 @@
part of 'last_order_table_bloc.dart';
@freezed
class LastOrderTableEvent with _$LastOrderTableEvent {
const factory LastOrderTableEvent.started() = _Started;
const factory LastOrderTableEvent.lastOrderTable(int tableNumber) =
_LastOrderTable;
}

View File

@ -1,8 +0,0 @@
part of 'last_order_table_bloc.dart';
@freezed
class LastOrderTableState with _$LastOrderTableState {
const factory LastOrderTableState.initial() = _Initial;
const factory LastOrderTableState.loading() = _Loading;
const factory LastOrderTableState.success(OrderModel? order) = _Success;
}

View File

@ -1,25 +0,0 @@
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/presentation/home/models/order_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'day_sales_event.dart';
part 'day_sales_state.dart';
part 'day_sales_bloc.freezed.dart';
class DaySalesBloc extends Bloc<DaySalesEvent, DaySalesState> {
final ProductLocalDatasource datasource;
DaySalesBloc(this.datasource) : super(const _Initial()) {
on<_GetDaySales>((event, emit) async {
emit(const _Loading());
final result = await datasource.getAllOrder(event.date);
emit(_Loaded(result));
});
on<_GetRangeDateSales>((event, emit) async {
emit(const _Loading());
final result =
await datasource.getAllOrderByRange(event.startDate, event.endDate);
emit(_Loaded(result));
});
}
}

View File

@ -1,947 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'day_sales_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$DaySalesEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(DateTime date) getDaySales,
required TResult Function(DateTime startDate, DateTime endDate)
getRangeDateSales,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(DateTime date)? getDaySales,
TResult? Function(DateTime startDate, DateTime endDate)? getRangeDateSales,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(DateTime date)? getDaySales,
TResult Function(DateTime startDate, DateTime endDate)? getRangeDateSales,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_GetDaySales value) getDaySales,
required TResult Function(_GetRangeDateSales value) getRangeDateSales,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_GetDaySales value)? getDaySales,
TResult? Function(_GetRangeDateSales value)? getRangeDateSales,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_GetDaySales value)? getDaySales,
TResult Function(_GetRangeDateSales value)? getRangeDateSales,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $DaySalesEventCopyWith<$Res> {
factory $DaySalesEventCopyWith(
DaySalesEvent value, $Res Function(DaySalesEvent) then) =
_$DaySalesEventCopyWithImpl<$Res, DaySalesEvent>;
}
/// @nodoc
class _$DaySalesEventCopyWithImpl<$Res, $Val extends DaySalesEvent>
implements $DaySalesEventCopyWith<$Res> {
_$DaySalesEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of DaySalesEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$StartedImplCopyWith<$Res> {
factory _$$StartedImplCopyWith(
_$StartedImpl value, $Res Function(_$StartedImpl) then) =
__$$StartedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$StartedImplCopyWithImpl<$Res>
extends _$DaySalesEventCopyWithImpl<$Res, _$StartedImpl>
implements _$$StartedImplCopyWith<$Res> {
__$$StartedImplCopyWithImpl(
_$StartedImpl _value, $Res Function(_$StartedImpl) _then)
: super(_value, _then);
/// Create a copy of DaySalesEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$StartedImpl implements _Started {
const _$StartedImpl();
@override
String toString() {
return 'DaySalesEvent.started()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$StartedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(DateTime date) getDaySales,
required TResult Function(DateTime startDate, DateTime endDate)
getRangeDateSales,
}) {
return started();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(DateTime date)? getDaySales,
TResult? Function(DateTime startDate, DateTime endDate)? getRangeDateSales,
}) {
return started?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(DateTime date)? getDaySales,
TResult Function(DateTime startDate, DateTime endDate)? getRangeDateSales,
required TResult orElse(),
}) {
if (started != null) {
return started();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_GetDaySales value) getDaySales,
required TResult Function(_GetRangeDateSales value) getRangeDateSales,
}) {
return started(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_GetDaySales value)? getDaySales,
TResult? Function(_GetRangeDateSales value)? getRangeDateSales,
}) {
return started?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_GetDaySales value)? getDaySales,
TResult Function(_GetRangeDateSales value)? getRangeDateSales,
required TResult orElse(),
}) {
if (started != null) {
return started(this);
}
return orElse();
}
}
abstract class _Started implements DaySalesEvent {
const factory _Started() = _$StartedImpl;
}
/// @nodoc
abstract class _$$GetDaySalesImplCopyWith<$Res> {
factory _$$GetDaySalesImplCopyWith(
_$GetDaySalesImpl value, $Res Function(_$GetDaySalesImpl) then) =
__$$GetDaySalesImplCopyWithImpl<$Res>;
@useResult
$Res call({DateTime date});
}
/// @nodoc
class __$$GetDaySalesImplCopyWithImpl<$Res>
extends _$DaySalesEventCopyWithImpl<$Res, _$GetDaySalesImpl>
implements _$$GetDaySalesImplCopyWith<$Res> {
__$$GetDaySalesImplCopyWithImpl(
_$GetDaySalesImpl _value, $Res Function(_$GetDaySalesImpl) _then)
: super(_value, _then);
/// Create a copy of DaySalesEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? date = null,
}) {
return _then(_$GetDaySalesImpl(
null == date
? _value.date
: date // ignore: cast_nullable_to_non_nullable
as DateTime,
));
}
}
/// @nodoc
class _$GetDaySalesImpl implements _GetDaySales {
const _$GetDaySalesImpl(this.date);
@override
final DateTime date;
@override
String toString() {
return 'DaySalesEvent.getDaySales(date: $date)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$GetDaySalesImpl &&
(identical(other.date, date) || other.date == date));
}
@override
int get hashCode => Object.hash(runtimeType, date);
/// Create a copy of DaySalesEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$GetDaySalesImplCopyWith<_$GetDaySalesImpl> get copyWith =>
__$$GetDaySalesImplCopyWithImpl<_$GetDaySalesImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(DateTime date) getDaySales,
required TResult Function(DateTime startDate, DateTime endDate)
getRangeDateSales,
}) {
return getDaySales(date);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(DateTime date)? getDaySales,
TResult? Function(DateTime startDate, DateTime endDate)? getRangeDateSales,
}) {
return getDaySales?.call(date);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(DateTime date)? getDaySales,
TResult Function(DateTime startDate, DateTime endDate)? getRangeDateSales,
required TResult orElse(),
}) {
if (getDaySales != null) {
return getDaySales(date);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_GetDaySales value) getDaySales,
required TResult Function(_GetRangeDateSales value) getRangeDateSales,
}) {
return getDaySales(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_GetDaySales value)? getDaySales,
TResult? Function(_GetRangeDateSales value)? getRangeDateSales,
}) {
return getDaySales?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_GetDaySales value)? getDaySales,
TResult Function(_GetRangeDateSales value)? getRangeDateSales,
required TResult orElse(),
}) {
if (getDaySales != null) {
return getDaySales(this);
}
return orElse();
}
}
abstract class _GetDaySales implements DaySalesEvent {
const factory _GetDaySales(final DateTime date) = _$GetDaySalesImpl;
DateTime get date;
/// Create a copy of DaySalesEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$GetDaySalesImplCopyWith<_$GetDaySalesImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$GetRangeDateSalesImplCopyWith<$Res> {
factory _$$GetRangeDateSalesImplCopyWith(_$GetRangeDateSalesImpl value,
$Res Function(_$GetRangeDateSalesImpl) then) =
__$$GetRangeDateSalesImplCopyWithImpl<$Res>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$GetRangeDateSalesImplCopyWithImpl<$Res>
extends _$DaySalesEventCopyWithImpl<$Res, _$GetRangeDateSalesImpl>
implements _$$GetRangeDateSalesImplCopyWith<$Res> {
__$$GetRangeDateSalesImplCopyWithImpl(_$GetRangeDateSalesImpl _value,
$Res Function(_$GetRangeDateSalesImpl) _then)
: super(_value, _then);
/// Create a copy of DaySalesEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? startDate = null,
Object? endDate = null,
}) {
return _then(_$GetRangeDateSalesImpl(
null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
));
}
}
/// @nodoc
class _$GetRangeDateSalesImpl implements _GetRangeDateSales {
const _$GetRangeDateSalesImpl(this.startDate, this.endDate);
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'DaySalesEvent.getRangeDateSales(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$GetRangeDateSalesImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of DaySalesEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$GetRangeDateSalesImplCopyWith<_$GetRangeDateSalesImpl> get copyWith =>
__$$GetRangeDateSalesImplCopyWithImpl<_$GetRangeDateSalesImpl>(
this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(DateTime date) getDaySales,
required TResult Function(DateTime startDate, DateTime endDate)
getRangeDateSales,
}) {
return getRangeDateSales(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(DateTime date)? getDaySales,
TResult? Function(DateTime startDate, DateTime endDate)? getRangeDateSales,
}) {
return getRangeDateSales?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(DateTime date)? getDaySales,
TResult Function(DateTime startDate, DateTime endDate)? getRangeDateSales,
required TResult orElse(),
}) {
if (getRangeDateSales != null) {
return getRangeDateSales(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_GetDaySales value) getDaySales,
required TResult Function(_GetRangeDateSales value) getRangeDateSales,
}) {
return getRangeDateSales(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_GetDaySales value)? getDaySales,
TResult? Function(_GetRangeDateSales value)? getRangeDateSales,
}) {
return getRangeDateSales?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_GetDaySales value)? getDaySales,
TResult Function(_GetRangeDateSales value)? getRangeDateSales,
required TResult orElse(),
}) {
if (getRangeDateSales != null) {
return getRangeDateSales(this);
}
return orElse();
}
}
abstract class _GetRangeDateSales implements DaySalesEvent {
const factory _GetRangeDateSales(
final DateTime startDate, final DateTime endDate) =
_$GetRangeDateSalesImpl;
DateTime get startDate;
DateTime get endDate;
/// Create a copy of DaySalesEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$GetRangeDateSalesImplCopyWith<_$GetRangeDateSalesImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$DaySalesState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<OrderModel> orders) loaded,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<OrderModel> orders)? loaded,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<OrderModel> orders)? loaded,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $DaySalesStateCopyWith<$Res> {
factory $DaySalesStateCopyWith(
DaySalesState value, $Res Function(DaySalesState) then) =
_$DaySalesStateCopyWithImpl<$Res, DaySalesState>;
}
/// @nodoc
class _$DaySalesStateCopyWithImpl<$Res, $Val extends DaySalesState>
implements $DaySalesStateCopyWith<$Res> {
_$DaySalesStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of DaySalesState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$InitialImplCopyWith<$Res> {
factory _$$InitialImplCopyWith(
_$InitialImpl value, $Res Function(_$InitialImpl) then) =
__$$InitialImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$InitialImplCopyWithImpl<$Res>
extends _$DaySalesStateCopyWithImpl<$Res, _$InitialImpl>
implements _$$InitialImplCopyWith<$Res> {
__$$InitialImplCopyWithImpl(
_$InitialImpl _value, $Res Function(_$InitialImpl) _then)
: super(_value, _then);
/// Create a copy of DaySalesState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$InitialImpl implements _Initial {
const _$InitialImpl();
@override
String toString() {
return 'DaySalesState.initial()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$InitialImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<OrderModel> orders) loaded,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<OrderModel> orders)? loaded,
}) {
return initial?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<OrderModel> orders)? loaded,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
}) {
return initial(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
}) {
return initial?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
required TResult orElse(),
}) {
if (initial != null) {
return initial(this);
}
return orElse();
}
}
abstract class _Initial implements DaySalesState {
const factory _Initial() = _$InitialImpl;
}
/// @nodoc
abstract class _$$LoadingImplCopyWith<$Res> {
factory _$$LoadingImplCopyWith(
_$LoadingImpl value, $Res Function(_$LoadingImpl) then) =
__$$LoadingImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LoadingImplCopyWithImpl<$Res>
extends _$DaySalesStateCopyWithImpl<$Res, _$LoadingImpl>
implements _$$LoadingImplCopyWith<$Res> {
__$$LoadingImplCopyWithImpl(
_$LoadingImpl _value, $Res Function(_$LoadingImpl) _then)
: super(_value, _then);
/// Create a copy of DaySalesState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LoadingImpl implements _Loading {
const _$LoadingImpl();
@override
String toString() {
return 'DaySalesState.loading()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$LoadingImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<OrderModel> orders) loaded,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<OrderModel> orders)? loaded,
}) {
return loading?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<OrderModel> orders)? loaded,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
}) {
return loading(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
}) {
return loading?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
required TResult orElse(),
}) {
if (loading != null) {
return loading(this);
}
return orElse();
}
}
abstract class _Loading implements DaySalesState {
const factory _Loading() = _$LoadingImpl;
}
/// @nodoc
abstract class _$$LoadedImplCopyWith<$Res> {
factory _$$LoadedImplCopyWith(
_$LoadedImpl value, $Res Function(_$LoadedImpl) then) =
__$$LoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({List<OrderModel> orders});
}
/// @nodoc
class __$$LoadedImplCopyWithImpl<$Res>
extends _$DaySalesStateCopyWithImpl<$Res, _$LoadedImpl>
implements _$$LoadedImplCopyWith<$Res> {
__$$LoadedImplCopyWithImpl(
_$LoadedImpl _value, $Res Function(_$LoadedImpl) _then)
: super(_value, _then);
/// Create a copy of DaySalesState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? orders = null,
}) {
return _then(_$LoadedImpl(
null == orders
? _value._orders
: orders // ignore: cast_nullable_to_non_nullable
as List<OrderModel>,
));
}
}
/// @nodoc
class _$LoadedImpl implements _Loaded {
const _$LoadedImpl(final List<OrderModel> orders) : _orders = orders;
final List<OrderModel> _orders;
@override
List<OrderModel> get orders {
if (_orders is EqualUnmodifiableListView) return _orders;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_orders);
}
@override
String toString() {
return 'DaySalesState.loaded(orders: $orders)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LoadedImpl &&
const DeepCollectionEquality().equals(other._orders, _orders));
}
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(_orders));
/// Create a copy of DaySalesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LoadedImplCopyWith<_$LoadedImpl> get copyWith =>
__$$LoadedImplCopyWithImpl<_$LoadedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<OrderModel> orders) loaded,
}) {
return loaded(orders);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<OrderModel> orders)? loaded,
}) {
return loaded?.call(orders);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<OrderModel> orders)? loaded,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(orders);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
}) {
return loaded(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
}) {
return loaded?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(this);
}
return orElse();
}
}
abstract class _Loaded implements DaySalesState {
const factory _Loaded(final List<OrderModel> orders) = _$LoadedImpl;
List<OrderModel> get orders;
/// Create a copy of DaySalesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LoadedImplCopyWith<_$LoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -1,13 +0,0 @@
part of 'day_sales_bloc.dart';
@freezed
class DaySalesEvent with _$DaySalesEvent {
const factory DaySalesEvent.started() = _Started;
const factory DaySalesEvent.getDaySales(
DateTime date,
) = _GetDaySales;
const factory DaySalesEvent.getRangeDateSales(
DateTime startDate,
DateTime endDate,
) = _GetRangeDateSales;
}

View File

@ -1,8 +0,0 @@
part of 'day_sales_bloc.dart';
@freezed
class DaySalesState with _$DaySalesState {
const factory DaySalesState.initial() = _Initial;
const factory DaySalesState.loading() = _Loading;
const factory DaySalesState.loaded(List<OrderModel> orders) = _Loaded;
}

View File

@ -1,7 +1,5 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -13,10 +11,10 @@ class CreatePrinterBloc extends Bloc<CreatePrinterEvent, CreatePrinterState> {
CreatePrinterBloc() : super(_Initial()) {
on<_CreatePrinter>((event, emit) async {
emit(_Loading());
await ProductLocalDatasource.instance.createPrinter(
await PrinterLocalDatasource.instance.createPrinter(
event.print,
);
emit(_Success('Create Table Success'));
emit(_Success('Create Printer Success'));
});
}
}

View File

@ -1,6 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -13,7 +12,7 @@ class GetPrinterBarBloc extends Bloc<GetPrinterBarEvent, GetPrinterBarState> {
on<_Get>((event, emit) async {
emit(_Loading());
final result =
await ProductLocalDatasource.instance.getPrinterByCode('bar');
await PrinterLocalDatasource.instance.getPrinterByCode('bar');
emit(_Success(result));
});
}

View File

@ -1,9 +1,8 @@
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../../../data/datasources/product_local_datasource.dart';
part 'get_printer_checker_event.dart';
part 'get_printer_checker_state.dart';
part 'get_printer_checker_bloc.freezed.dart';
@ -14,7 +13,7 @@ class GetPrinterCheckerBloc
on<_Get>((event, emit) async {
emit(_Loading());
final result =
await ProductLocalDatasource.instance.getPrinterByCode('checker');
await PrinterLocalDatasource.instance.getPrinterByCode('checker');
emit(_Success(result));
});
}

View File

@ -1,5 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -13,7 +13,7 @@ class GetPrinterKitchenBloc
on<_Get>((event, emit) async {
emit(_Loading());
final result =
await ProductLocalDatasource.instance.getPrinterByCode('kitchen');
await PrinterLocalDatasource.instance.getPrinterByCode('kitchen');
emit(_Success(result));
});
}

View File

@ -1,5 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -13,7 +13,7 @@ class GetPrinterReceiptBloc
on<_Get>((event, emit) async {
emit(_Loading());
final result =
await ProductLocalDatasource.instance.getPrinterByCode('receipt');
await PrinterLocalDatasource.instance.getPrinterByCode('receipt');
emit(_Success(result));
});
}

View File

@ -1,5 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -13,7 +13,7 @@ class GetPrinterTicketBloc
on<_Get>((event, emit) async {
emit(_Loading());
final result =
await ProductLocalDatasource.instance.getPrinterByCode('ticket');
await PrinterLocalDatasource.instance.getPrinterByCode('ticket');
emit(_Success(result));
});
}

View File

@ -1,42 +0,0 @@
import 'dart:developer';
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart';
part 'sync_order_bloc.freezed.dart';
part 'sync_order_event.dart';
part 'sync_order_state.dart';
class SyncOrderBloc extends Bloc<SyncOrderEvent, SyncOrderState> {
final OrderRemoteDatasource orderRemoteDatasource;
SyncOrderBloc(
this.orderRemoteDatasource,
) : super(const _Initial()) {
on<_SyncOrder>((event, emit) async {
emit(const _Loading());
log("🔄 SyncOrderBloc: Starting sync process");
final dataOrderNotSynced =
await ProductLocalDatasource.instance.getOrderByIsNotSync();
log("🔄 SyncOrderBloc: Found ${dataOrderNotSynced.length} orders to sync");
for (var order in dataOrderNotSynced) {
final orderItem = await ProductLocalDatasource.instance
.getOrderItemByOrderId(order.id!);
final newOrder = order.copyWith(orderItems: orderItem);
log("🔄 SyncOrderBloc: Syncing order ${order.id} to API");
log("Order: ${newOrder.toMap()}");
final result = await orderRemoteDatasource.saveOrder(newOrder);
if (result) {
await ProductLocalDatasource.instance.updateOrderIsSync(order.id!);
} else {
emit(const _Error('Sync Order Failed'));
return;
}
}
emit(const _Loaded());
});
}
}

View File

@ -1,866 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'sync_order_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$SyncOrderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function() syncOrder,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function()? syncOrder,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function()? syncOrder,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_SyncOrder value) syncOrder,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_SyncOrder value)? syncOrder,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_SyncOrder value)? syncOrder,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $SyncOrderEventCopyWith<$Res> {
factory $SyncOrderEventCopyWith(
SyncOrderEvent value, $Res Function(SyncOrderEvent) then) =
_$SyncOrderEventCopyWithImpl<$Res, SyncOrderEvent>;
}
/// @nodoc
class _$SyncOrderEventCopyWithImpl<$Res, $Val extends SyncOrderEvent>
implements $SyncOrderEventCopyWith<$Res> {
_$SyncOrderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of SyncOrderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$StartedImplCopyWith<$Res> {
factory _$$StartedImplCopyWith(
_$StartedImpl value, $Res Function(_$StartedImpl) then) =
__$$StartedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$StartedImplCopyWithImpl<$Res>
extends _$SyncOrderEventCopyWithImpl<$Res, _$StartedImpl>
implements _$$StartedImplCopyWith<$Res> {
__$$StartedImplCopyWithImpl(
_$StartedImpl _value, $Res Function(_$StartedImpl) _then)
: super(_value, _then);
/// Create a copy of SyncOrderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$StartedImpl implements _Started {
const _$StartedImpl();
@override
String toString() {
return 'SyncOrderEvent.started()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$StartedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function() syncOrder,
}) {
return started();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function()? syncOrder,
}) {
return started?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function()? syncOrder,
required TResult orElse(),
}) {
if (started != null) {
return started();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_SyncOrder value) syncOrder,
}) {
return started(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_SyncOrder value)? syncOrder,
}) {
return started?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_SyncOrder value)? syncOrder,
required TResult orElse(),
}) {
if (started != null) {
return started(this);
}
return orElse();
}
}
abstract class _Started implements SyncOrderEvent {
const factory _Started() = _$StartedImpl;
}
/// @nodoc
abstract class _$$SyncOrderImplCopyWith<$Res> {
factory _$$SyncOrderImplCopyWith(
_$SyncOrderImpl value, $Res Function(_$SyncOrderImpl) then) =
__$$SyncOrderImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$SyncOrderImplCopyWithImpl<$Res>
extends _$SyncOrderEventCopyWithImpl<$Res, _$SyncOrderImpl>
implements _$$SyncOrderImplCopyWith<$Res> {
__$$SyncOrderImplCopyWithImpl(
_$SyncOrderImpl _value, $Res Function(_$SyncOrderImpl) _then)
: super(_value, _then);
/// Create a copy of SyncOrderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$SyncOrderImpl implements _SyncOrder {
const _$SyncOrderImpl();
@override
String toString() {
return 'SyncOrderEvent.syncOrder()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$SyncOrderImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function() syncOrder,
}) {
return syncOrder();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function()? syncOrder,
}) {
return syncOrder?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function()? syncOrder,
required TResult orElse(),
}) {
if (syncOrder != null) {
return syncOrder();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Started value) started,
required TResult Function(_SyncOrder value) syncOrder,
}) {
return syncOrder(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Started value)? started,
TResult? Function(_SyncOrder value)? syncOrder,
}) {
return syncOrder?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Started value)? started,
TResult Function(_SyncOrder value)? syncOrder,
required TResult orElse(),
}) {
if (syncOrder != null) {
return syncOrder(this);
}
return orElse();
}
}
abstract class _SyncOrder implements SyncOrderEvent {
const factory _SyncOrder() = _$SyncOrderImpl;
}
/// @nodoc
mixin _$SyncOrderState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() loaded,
required TResult Function(String message) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? loaded,
TResult? Function(String message)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $SyncOrderStateCopyWith<$Res> {
factory $SyncOrderStateCopyWith(
SyncOrderState value, $Res Function(SyncOrderState) then) =
_$SyncOrderStateCopyWithImpl<$Res, SyncOrderState>;
}
/// @nodoc
class _$SyncOrderStateCopyWithImpl<$Res, $Val extends SyncOrderState>
implements $SyncOrderStateCopyWith<$Res> {
_$SyncOrderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of SyncOrderState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$InitialImplCopyWith<$Res> {
factory _$$InitialImplCopyWith(
_$InitialImpl value, $Res Function(_$InitialImpl) then) =
__$$InitialImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$InitialImplCopyWithImpl<$Res>
extends _$SyncOrderStateCopyWithImpl<$Res, _$InitialImpl>
implements _$$InitialImplCopyWith<$Res> {
__$$InitialImplCopyWithImpl(
_$InitialImpl _value, $Res Function(_$InitialImpl) _then)
: super(_value, _then);
/// Create a copy of SyncOrderState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$InitialImpl implements _Initial {
const _$InitialImpl();
@override
String toString() {
return 'SyncOrderState.initial()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$InitialImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() loaded,
required TResult Function(String message) error,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? loaded,
TResult? Function(String message)? error,
}) {
return initial?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) {
return initial(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) {
return initial?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (initial != null) {
return initial(this);
}
return orElse();
}
}
abstract class _Initial implements SyncOrderState {
const factory _Initial() = _$InitialImpl;
}
/// @nodoc
abstract class _$$LoadingImplCopyWith<$Res> {
factory _$$LoadingImplCopyWith(
_$LoadingImpl value, $Res Function(_$LoadingImpl) then) =
__$$LoadingImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LoadingImplCopyWithImpl<$Res>
extends _$SyncOrderStateCopyWithImpl<$Res, _$LoadingImpl>
implements _$$LoadingImplCopyWith<$Res> {
__$$LoadingImplCopyWithImpl(
_$LoadingImpl _value, $Res Function(_$LoadingImpl) _then)
: super(_value, _then);
/// Create a copy of SyncOrderState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LoadingImpl implements _Loading {
const _$LoadingImpl();
@override
String toString() {
return 'SyncOrderState.loading()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$LoadingImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() loaded,
required TResult Function(String message) error,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? loaded,
TResult? Function(String message)? error,
}) {
return loading?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) {
return loading(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) {
return loading?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (loading != null) {
return loading(this);
}
return orElse();
}
}
abstract class _Loading implements SyncOrderState {
const factory _Loading() = _$LoadingImpl;
}
/// @nodoc
abstract class _$$LoadedImplCopyWith<$Res> {
factory _$$LoadedImplCopyWith(
_$LoadedImpl value, $Res Function(_$LoadedImpl) then) =
__$$LoadedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LoadedImplCopyWithImpl<$Res>
extends _$SyncOrderStateCopyWithImpl<$Res, _$LoadedImpl>
implements _$$LoadedImplCopyWith<$Res> {
__$$LoadedImplCopyWithImpl(
_$LoadedImpl _value, $Res Function(_$LoadedImpl) _then)
: super(_value, _then);
/// Create a copy of SyncOrderState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LoadedImpl implements _Loaded {
const _$LoadedImpl();
@override
String toString() {
return 'SyncOrderState.loaded()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$LoadedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() loaded,
required TResult Function(String message) error,
}) {
return loaded();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? loaded,
TResult? Function(String message)? error,
}) {
return loaded?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) {
return loaded(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) {
return loaded?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(this);
}
return orElse();
}
}
abstract class _Loaded implements SyncOrderState {
const factory _Loaded() = _$LoadedImpl;
}
/// @nodoc
abstract class _$$ErrorImplCopyWith<$Res> {
factory _$$ErrorImplCopyWith(
_$ErrorImpl value, $Res Function(_$ErrorImpl) then) =
__$$ErrorImplCopyWithImpl<$Res>;
@useResult
$Res call({String message});
}
/// @nodoc
class __$$ErrorImplCopyWithImpl<$Res>
extends _$SyncOrderStateCopyWithImpl<$Res, _$ErrorImpl>
implements _$$ErrorImplCopyWith<$Res> {
__$$ErrorImplCopyWithImpl(
_$ErrorImpl _value, $Res Function(_$ErrorImpl) _then)
: super(_value, _then);
/// Create a copy of SyncOrderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? message = null,
}) {
return _then(_$ErrorImpl(
null == message
? _value.message
: message // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$ErrorImpl implements _Error {
const _$ErrorImpl(this.message);
@override
final String message;
@override
String toString() {
return 'SyncOrderState.error(message: $message)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ErrorImpl &&
(identical(other.message, message) || other.message == message));
}
@override
int get hashCode => Object.hash(runtimeType, message);
/// Create a copy of SyncOrderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
__$$ErrorImplCopyWithImpl<_$ErrorImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function() loaded,
required TResult Function(String message) error,
}) {
return error(message);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function()? loaded,
TResult? Function(String message)? error,
}) {
return error?.call(message);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function()? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(message);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Loaded value) loaded,
required TResult Function(_Error value) error,
}) {
return error(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Loaded value)? loaded,
TResult? Function(_Error value)? error,
}) {
return error?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Loaded value)? loaded,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(this);
}
return orElse();
}
}
abstract class _Error implements SyncOrderState {
const factory _Error(final String message) = _$ErrorImpl;
String get message;
/// Create a copy of SyncOrderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -1,7 +0,0 @@
part of 'sync_order_bloc.dart';
@freezed
class SyncOrderEvent with _$SyncOrderEvent {
const factory SyncOrderEvent.started() = _Started;
const factory SyncOrderEvent.syncOrder() = _SyncOrder;
}

View File

@ -1,10 +0,0 @@
part of 'sync_order_bloc.dart';
@freezed
class SyncOrderState with _$SyncOrderState {
const factory SyncOrderState.initial() = _Initial;
const factory SyncOrderState.loading() = _Loading;
const factory SyncOrderState.loaded() =
_Loaded;
const factory SyncOrderState.error(String message) = _Error;
}

View File

@ -1,5 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -11,7 +11,7 @@ class UpdatePrinterBloc extends Bloc<UpdatePrinterEvent, UpdatePrinterState> {
UpdatePrinterBloc() : super(_Initial()) {
on<_UpdatePrinter>((event, emit) async {
emit(_Loading());
await ProductLocalDatasource.instance.updatePrinter(
await PrinterLocalDatasource.instance.updatePrinter(
event.print,
event.print.id!,
);

View File

@ -17,15 +17,144 @@ enum PrinterType {
}
class PrinterModel {
final int? id;
final String code;
final String name;
final String ipAddress;
final String size;
final PrinterType type;
final DateTime? createdAt;
final DateTime? updatedAt;
PrinterModel({
this.id,
required this.code,
required this.name,
required this.ipAddress,
required this.size,
required this.type,
this.createdAt,
this.updatedAt,
});
// Factory constructor to create PrinterModel from database map
factory PrinterModel.fromMap(Map<String, dynamic> map) {
return PrinterModel(
id: map['id'] as int?,
code: map['code'] as String,
name: map['name'] as String,
ipAddress: map['ip_address'] as String,
size: map['size'] as String,
type: PrinterType.fromValue(map['type'] as String),
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'] as String)
: null,
updatedAt: map['updated_at'] != null
? DateTime.parse(map['updated_at'] as String)
: null,
);
}
// Convert to map for database insertion (excluding id, including timestamps)
Map<String, dynamic> toMapForInsert() {
final now = DateTime.now().toIso8601String();
return {
'code': code,
'name': name,
'ip_address': ipAddress,
'size': size,
'type': type.value,
'created_at': now,
'updated_at': now,
};
}
// Convert to map for database update (excluding id and created_at)
Map<String, dynamic> toMapForUpdate() {
return {
'code': code,
'name': name,
'ip_address': ipAddress,
'size': size,
'type': type.value,
'updated_at': DateTime.now().toIso8601String(),
};
}
// Convert to complete map (including id)
Map<String, dynamic> toMap() {
return {
'id': id,
'code': code,
'name': name,
'ip_address': ipAddress,
'size': size,
'type': type.value,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
};
}
// Copy with method for creating modified instances
PrinterModel copyWith({
int? id,
String? code,
String? name,
String? ipAddress,
String? size,
PrinterType? type,
DateTime? createdAt,
DateTime? updatedAt,
}) {
return PrinterModel(
id: id ?? this.id,
code: code ?? this.code,
name: name ?? this.name,
ipAddress: ipAddress ?? this.ipAddress,
size: size ?? this.size,
type: type ?? this.type,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
}
// Equality and hashCode for comparing instances
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is PrinterModel &&
other.id == id &&
other.code == code &&
other.name == name &&
other.ipAddress == ipAddress &&
other.size == size &&
other.type == type;
}
@override
int get hashCode {
return Object.hash(id, code, name, ipAddress, size, type);
}
// String representation for debugging
@override
String toString() {
return 'PrinterModel(id: $id, code: $code, name: $name, ipAddress: $ipAddress, size: $size, type: ${type.value}, createdAt: $createdAt, updatedAt: $updatedAt)';
}
// Validation methods
bool get isValid {
return code.isNotEmpty &&
name.isNotEmpty &&
ipAddress.isNotEmpty &&
size.isNotEmpty;
}
String? get validationError {
if (code.isEmpty) return 'Printer code cannot be empty';
if (name.isEmpty) return 'Printer name cannot be empty';
if (ipAddress.isEmpty) return 'IP address cannot be empty';
if (size.isEmpty) return 'Printer size cannot be empty';
return null;
}
}

View File

@ -4,8 +4,6 @@ import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/presentation/setting/widgets/settings_title.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/presentation/setting/bloc/sync_order/sync_order_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/sync_product/sync_product_bloc.dart';
class SyncDataPage extends StatefulWidget {
@ -114,53 +112,53 @@ class _SyncDataPageState extends State<SyncDataPage> {
fontWeight: FontWeight.w500,
),
),
BlocConsumer<SyncOrderBloc, SyncOrderState>(
listener: (context, state) {
state.maybeWhen(
orElse: () {},
error: (message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: Colors.red,
),
);
},
loaded: () {
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(
// content: Text('Sync Order Success'),
// backgroundColor: Colors.green,
// ),
// );
},
);
},
builder: (context, state) {
return state.maybeWhen(
orElse: () {
return Button.filled(
width: 100,
height: 40,
onPressed: () {
log("🔘 Sync Order button pressed");
log("🔘 SyncOrderBloc instance: ${context.read<SyncOrderBloc>()}");
context
.read<SyncOrderBloc>()
.add(const SyncOrderEvent.syncOrder());
log("🔘 SyncOrderEvent.syncOrder dispatched");
},
label: 'Sinkronasikan',
);
},
loading: () {
return const Center(
child: CircularProgressIndicator(),
);
},
);
},
)
// BlocConsumer<SyncOrderBloc, SyncOrderState>(
// listener: (context, state) {
// state.maybeWhen(
// orElse: () {},
// error: (message) {
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(
// content: Text(message),
// backgroundColor: Colors.red,
// ),
// );
// },
// loaded: () {
// // ScaffoldMessenger.of(context).showSnackBar(
// // const SnackBar(
// // content: Text('Sync Order Success'),
// // backgroundColor: Colors.green,
// // ),
// // );
// },
// );
// },
// builder: (context, state) {
// return state.maybeWhen(
// orElse: () {
// return Button.filled(
// width: 100,
// height: 40,
// onPressed: () {
// log("🔘 Sync Order button pressed");
// log("🔘 SyncOrderBloc instance: ${context.read<SyncOrderBloc>()}");
// context
// .read<SyncOrderBloc>()
// .add(const SyncOrderEvent.syncOrder());
// log("🔘 SyncOrderEvent.syncOrder dispatched");
// },
// label: 'Sinkronasikan',
// );
// },
// loading: () {
// return const Center(
// child: CircularProgressIndicator(),
// );
// },
// );
// },
// )
],
),
),

View File

@ -1,6 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'generate_table_event.dart';

View File

@ -1,6 +1,5 @@
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

View File

@ -1,7 +1,6 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -13,9 +12,6 @@ class UpdateTableBloc extends Bloc<UpdateTableEvent, UpdateTableState> {
UpdateTableBloc() : super(_Initial()) {
on<_UpdateTable>((event, emit) async {
emit(_Loading());
await ProductLocalDatasource.instance.updateTable(
event.table,
);
emit(_Success('Update Table Success'));
});
}

File diff suppressed because it is too large Load Diff

View File

@ -1,95 +0,0 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/material.dart';
import 'package:enaklo_pos/core/components/components.dart';
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/dialogs/form_table_dialog.dart';
import 'package:enaklo_pos/presentation/table/widgets/card_table_widget.dart';
class TablePage extends StatefulWidget {
const TablePage({super.key});
@override
State<TablePage> createState() => _TablePageState();
}
class _TablePageState extends State<TablePage> {
@override
void initState() {
context.read<GetTableBloc>().add(const GetTableEvent.getTables());
super.initState();
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(24),
child: ListView(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Table Management",
style: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.bold,
color: AppColors.primary,
),
),
Button.filled(
onPressed: () {
showDialog(
context: context,
builder: (context) => FormTableDialog(),
);
},
label: 'Generate Table',
height: 48.0,
width: 200.0,
),
],
),
SpaceHeight(24.0),
BlocBuilder<GetTableBloc, GetTableState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () {
return SizedBox.shrink();
},
loading: () {
return const CircularProgressIndicator();
},
success: (tables) {
if (tables.isEmpty) {
return const Center(
child: Text('No table available'),
);
}
return GridView.builder(
padding: EdgeInsets.zero,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 1.0,
crossAxisCount: 4,
mainAxisSpacing: 16,
crossAxisSpacing: 16,
),
itemCount: tables.length,
shrinkWrap: true,
physics: const ScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return CardTableWidget(
table: tables[index],
);
},
);
},
);
},
),
],
),
);
}
}

View File

@ -1,113 +0,0 @@
import 'dart:developer';
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter/material.dart';
import 'package:enaklo_pos/core/components/components.dart';
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/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/status_table/status_table_bloc.dart';
import 'package:enaklo_pos/presentation/home/pages/home_page.dart';
import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/models/draft_order_model.dart';
import 'package:enaklo_pos/presentation/table/pages/payment_table_page.dart.old';
class CardTableWidget extends StatefulWidget {
final TableModel table;
final List<ProductQuantity> items;
const CardTableWidget({
super.key,
required this.table,
required this.items,
});
@override
State<CardTableWidget> createState() => _CardTableWidgetState();
}
class _CardTableWidgetState extends State<CardTableWidget> {
DraftOrderModel? data;
@override
void initState() {
loadData();
super.initState();
}
loadData() async {
if (widget.table.status != 'available') {
// data = await ProductLocalDatasource.instance
// .getDraftOrderById(widget.table.orderId);
}
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16.0),
height: 200,
width: 200,
decoration: BoxDecoration(
border: Border.all(
color: widget.table.status == 'available'
? AppColors.primary
: AppColors.red,
width: 2),
borderRadius: BorderRadius.circular(16),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Table ${widget.table.tableName}',
style: TextStyle(
color: AppColors.black,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
Text(
// widget.table.status == 'available'
// ? widget.table.status
// : "${widget.table.status} - ${DateTime.parse(widget.table.startTime).toFormattedTime()}",
"",
style: TextStyle(
color: AppColors.black,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
Button.filled(
color: widget.table.status == 'available'
? AppColors.primary
: AppColors.red,
onPressed: () async {
if (widget.table.status == 'available') {
context.push(HomePage(
isTable: true,
table: widget.table,
items: widget.items,
));
} else {
context.read<CheckoutBloc>().add(
CheckoutEvent.loadDraftOrder(data!),
);
log("Data Draft Order: ${data!.toMap()}");
context.push(PaymentTablePage(
table: widget.table,
draftOrder: data!,
));
}
},
label: widget.table.status == 'available' ? 'Open' : 'Close')
],
),
);
}
}

View File

@ -1,399 +0,0 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/core/components/buttons.dart';
import 'package:enaklo_pos/core/components/custom_text_field.dart';
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/core/utils/date_formatter.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/status_table/status_table_bloc.dart';
import 'package:enaklo_pos/presentation/home/pages/dashboard_page.dart';
import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/blocs/update_table/update_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/models/draft_order_model.dart';
import '../pages/payment_table_page.dart';
class TableWidget extends StatefulWidget {
final TableModel table;
const TableWidget({
super.key,
required this.table,
});
@override
State<TableWidget> createState() => _TableWidgetState();
}
class _TableWidgetState extends State<TableWidget> {
TextEditingController? tableNameController;
DraftOrderModel? data;
@override
void initState() {
super.initState();
loadData();
tableNameController = TextEditingController(text: widget.table.tableName);
}
@override
void dispose() {
tableNameController!.dispose();
super.dispose();
}
loadData() async {
if (widget.table.status != 'available') {
// data = await ProductLocalDatasource.instance
// .getDraftOrderById(widget.table.orderId);
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () async {
if (widget.table.status == 'available') {
context.push(DashboardPage(
table: widget.table,
));
} else {
// Handle occupied table click - load draft order and navigate to payment
context.read<CheckoutBloc>().add(
CheckoutEvent.loadDraftOrder(data!),
);
log("Data Draft Order: ${data!.toMap()}");
context.push(PaymentTablePage(
table: widget.table,
draftOrder: data!,
));
}
},
onLongPress: () {
// dialog info table
showDialog(
context: context,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16)),
title: Row(
children: [
Icon(Icons.table_bar, color: AppColors.primary),
SizedBox(width: 8),
Text('Table ${widget.table.tableName}'),
Spacer(),
BlocListener<UpdateTableBloc, UpdateTableState>(
listener: (context, state) {
state.maybeWhen(
orElse: () {},
success: (message) {
context
.read<GetTableBloc>()
.add(const GetTableEvent.getTables());
context.pop();
});
},
child: IconButton(
onPressed: () {
// show dialaog adn input table name
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('Update Table'),
content: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 180,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CustomTextField(
controller: tableNameController!,
label: 'Table Name',
),
SpaceHeight(16),
Row(
children: [
Expanded(
child: Button.outlined(
onPressed: () {
context.pop();
},
label: 'close',
),
),
SpaceWidth(16),
Expanded(
child: Button.filled(
onPressed: () {
// final newData =
// TableModel(
// id: widget.table.id,
// tableName:
// tableNameController!
// .text,
// status:
// widget.table.status,
// startTime: widget
// .table.startTime,
// orderId: widget
// .table.orderId,
// paymentAmount: widget
// .table
// .paymentAmount,
// position: widget
// .table.position,
// );
// context
// .read<
// UpdateTableBloc>()
// .add(
// UpdateTableEvent
// .updateTable(
// newData,
// ),
// );
context
.pop(); // close dialog after adding
},
label: 'Update',
),
)
],
)
],
),
),
),
actions: []);
});
},
icon: Icon(Icons.edit)),
),
],
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildInfoRow(
'Status:',
widget.table.status == 'available'
? 'Available'
: 'Occupied',
color: widget.table.status == 'available'
? Colors.green
: Colors.red),
// widget.table.status == 'available'
// ? SizedBox.shrink()
// : _buildInfoRow(
// 'Start Time:',
// DateFormatter.formatDateTime2(
// widget.table.startTime)),
// widget.table.status == 'available'
// ? SizedBox.shrink()
// : _buildInfoRow(
// 'Order ID:', widget.table.orderId.toString()),
widget.table.status == 'available'
? SizedBox.shrink()
: SpaceHeight(16),
widget.table.status == 'available'
? SizedBox.shrink()
: Row(
children: [
Expanded(
child: Button.outlined(
onPressed: () {
// Show void confirmation dialog
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Row(
children: [
Icon(Icons.warning,
color: AppColors.red),
SizedBox(width: 8),
Text('Void Order?'),
],
),
content: Text(
'Apakah anda yakin ingin membatalkan pesanan untuk meja ${widget.table.tableName}?\n\nPesanan akan dihapus secara permanen.'),
actions: [
TextButton(
onPressed: () =>
Navigator.pop(context),
child: Text('Tidak',
style: TextStyle(
color: AppColors.primary)),
),
BlocListener<StatusTableBloc,
StatusTableState>(
listener: (context, state) {
state.maybeWhen(
orElse: () {},
success: () {
context
.read<GetTableBloc>()
.add(const GetTableEvent
.getTables());
Navigator.pop(
context); // Close void dialog
Navigator.pop(
context); // Close table info dialog
ScaffoldMessenger.of(context)
.showSnackBar(
const SnackBar(
content: Text(
'Pesanan berhasil dibatalkan'),
backgroundColor:
AppColors.primary,
),
);
},
);
},
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.red,
),
onPressed: () {
// // Void the order
// final newTable = TableModel(
// id: widget.table.id,
// tableName:
// widget.table.tableName,
// status: 'available',
// orderId: 0,
// paymentAmount: 0,
// startTime: DateTime.now()
// .toIso8601String(),
// position: widget.table.position,
// );
// context
// .read<StatusTableBloc>()
// .add(
// StatusTableEvent
// .statusTabel(newTable),
// );
// // Remove draft order from local storage
// ProductLocalDatasource.instance
// .removeDraftOrderById(
// widget.table.orderId);
// log("Voided order for table: ${widget.table.tableName}");
},
child: const Text(
"Ya, Batalkan",
style: TextStyle(
color: Colors.white),
),
),
),
],
),
);
},
label: 'Void Order',
color: AppColors.red,
textColor: AppColors.red,
),
),
SizedBox(width: 12),
Expanded(
child: BlocConsumer<StatusTableBloc,
StatusTableState>(
listener: (context, state) {
state.maybeWhen(
orElse: () {},
success: () {
context.read<GetTableBloc>().add(
const GetTableEvent.getTables());
context.pop();
});
},
builder: (context, state) {
return Button.filled(
onPressed: () {
context.pop();
context.read<CheckoutBloc>().add(
CheckoutEvent.loadDraftOrder(
data!),
);
context.push(PaymentTablePage(
table: widget.table,
draftOrder: data!,
));
},
label: 'Selesai');
},
),
),
],
),
],
),
actions: [
TextButton(
child:
Text('Close', style: TextStyle(color: AppColors.primary)),
onPressed: () => Navigator.of(context).pop(),
),
],
);
},
);
},
child: Container(
padding: const EdgeInsets.all(16.0),
alignment: Alignment.center,
decoration: BoxDecoration(
color: widget.table.status == 'available'
? AppColors.primary
: AppColors.red,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10),
),
child: Text('${widget.table.tableName}',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600,
)),
),
);
}
Widget _buildInfoRow(String label, String value, {Color? color}) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Row(
children: [
Text(
label,
style: TextStyle(fontWeight: FontWeight.w600),
),
SizedBox(width: 8),
Expanded(
child: Text(
value,
style: TextStyle(
color: color ?? Colors.black87,
),
),
),
],
),
);
}
}