fix: reformat code / code improvements
This commit is contained in:
+3
-10
@@ -1,4 +1,5 @@
|
||||
import 'tab_item.dart';
|
||||
import '../utils/collection_utils.dart';
|
||||
|
||||
class BarTab {
|
||||
final String id;
|
||||
@@ -40,7 +41,7 @@ class BarTab {
|
||||
status == other.status &&
|
||||
openedAt == other.openedAt &&
|
||||
closedAt == other.closedAt &&
|
||||
_listEquals(items, other.items);
|
||||
listEquals(items, other.items);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
@@ -53,12 +54,4 @@ class BarTab {
|
||||
);
|
||||
}
|
||||
|
||||
bool _listEquals<T>(List<T>? a, List<T>? b) {
|
||||
if (identical(a, b)) return true;
|
||||
if (a == null || b == null) return a == b;
|
||||
if (a.length != b.length) return false;
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
if (a[i] != b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// _listEquals moved to utils/collection_utils.dart
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'closed_tab_item.dart';
|
||||
import 'payment_method.dart';
|
||||
import '../utils/collection_utils.dart';
|
||||
|
||||
class ClosedTab {
|
||||
final String id;
|
||||
final String originalTabId;
|
||||
final String customerName;
|
||||
final DateTime closedAt;
|
||||
final String paymentMethod;
|
||||
final List<ClosedTabItem> items;
|
||||
final PaymentMethod paymentMethod;
|
||||
|
||||
ClosedTab({
|
||||
final List<ClosedTabItem> items;
|
||||
const ClosedTab({
|
||||
required this.id,
|
||||
required this.originalTabId,
|
||||
required this.customerName,
|
||||
@@ -27,13 +29,7 @@ class ClosedTab {
|
||||
String get formattedTotal =>
|
||||
NumberFormat.simpleCurrency().format(totalInCents / 100);
|
||||
|
||||
String get formattedPaymentMethod {
|
||||
return switch (paymentMethod) {
|
||||
'cash' => 'Cash',
|
||||
'payconiq' => 'Payconiq',
|
||||
_ => 'Cash',
|
||||
};
|
||||
}
|
||||
String get formattedPaymentMethod => paymentMethod.label;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
@@ -44,7 +40,7 @@ class ClosedTab {
|
||||
customerName == other.customerName &&
|
||||
closedAt == other.closedAt &&
|
||||
paymentMethod == other.paymentMethod &&
|
||||
_listEquals(items, other.items);
|
||||
listEquals(items, other.items);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
@@ -57,12 +53,4 @@ class ClosedTab {
|
||||
);
|
||||
}
|
||||
|
||||
bool _listEquals<T>(List<T>? a, List<T>? b) {
|
||||
if (identical(a, b)) return true;
|
||||
if (a == null || b == null) return a == b;
|
||||
if (a.length != b.length) return false;
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
if (a[i] != b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// _listEquals moved to utils/collection_utils.dart
|
||||
@@ -0,0 +1,15 @@
|
||||
enum PaymentMethod {
|
||||
cash('cash', 'Cash', 'Cash payment'),
|
||||
payconiq('payconiq', 'Payconiq', 'Payconiq QR payment');
|
||||
|
||||
final String value;
|
||||
final String label;
|
||||
final String description;
|
||||
|
||||
const PaymentMethod(this.value, this.label, this.description);
|
||||
|
||||
static PaymentMethod fromValue(String value) => PaymentMethod.values.firstWhere(
|
||||
(e) => e.value == value,
|
||||
orElse: () => PaymentMethod.cash,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user