fix: reformat code / code improvements
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../models/payment_method.dart';
|
||||
import '../models/bar_tab.dart';
|
||||
import '../models/product.dart';
|
||||
import '../models/tab_item.dart';
|
||||
@@ -33,7 +34,8 @@ class BarScreenViewModel extends ChangeNotifier {
|
||||
|
||||
try {
|
||||
return _tabs.firstWhere((tab) => tab.id == _selectedTabId);
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('BarScreenViewModel: error finding selected tab: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +60,8 @@ class BarScreenViewModel extends ChangeNotifier {
|
||||
!_tabs.any((tab) => tab.id == _selectedTabId)) {
|
||||
_selectedTabId = _tabs.isEmpty ? null : _tabs.first.id;
|
||||
}
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('BarScreenViewModel: load error: $e');
|
||||
_errorMessage = 'Could not load bar screen.';
|
||||
} finally {
|
||||
_hasLoaded = true;
|
||||
@@ -115,7 +118,7 @@ class BarScreenViewModel extends ChangeNotifier {
|
||||
await _reloadTabs();
|
||||
}
|
||||
|
||||
Future<void> closeSelectedTab({String paymentMethod = 'cash'}) async {
|
||||
Future<void> closeSelectedTab({PaymentMethod paymentMethod = PaymentMethod.cash}) async {
|
||||
final tab = selectedTab;
|
||||
|
||||
if (tab == null) return;
|
||||
@@ -125,7 +128,7 @@ class BarScreenViewModel extends ChangeNotifier {
|
||||
await _reloadTabs();
|
||||
}
|
||||
|
||||
Future<void> closeTab(String tabId, {String paymentMethod = 'cash'}) async {
|
||||
Future<void> closeTab(String tabId, {PaymentMethod paymentMethod = PaymentMethod.cash}) async {
|
||||
await barTabService.closeTab(tabId, paymentMethod: paymentMethod);
|
||||
|
||||
await _reloadTabs();
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:kooltab2/database/app_database.dart';
|
||||
import 'package:kooltab2/services/bar_tab_service.dart';
|
||||
import 'package:kooltab2/models/payment_method.dart';
|
||||
import 'package:kooltab2/services/pin_lock_service.dart';
|
||||
import 'package:kooltab2/services/product_service.dart';
|
||||
import 'package:kooltab2/services/settings_service.dart';
|
||||
@@ -275,7 +276,7 @@ class DevMenuViewModel extends ChangeNotifier {
|
||||
'Sam', 'Tina', 'Umar', 'Vera', 'Wes', 'Xena',
|
||||
'Yves', 'Zara',
|
||||
];
|
||||
const paymentMethods = ['cash', 'payconiq'];
|
||||
const paymentMethods = [PaymentMethod.cash, PaymentMethod.payconiq];
|
||||
|
||||
await database.transaction(() async {
|
||||
for (var i = 0; i < count; i++) {
|
||||
@@ -297,7 +298,7 @@ class DevMenuViewModel extends ChangeNotifier {
|
||||
originalTabId: uuid.v4(),
|
||||
customerName: customer,
|
||||
closedAt: closedAt,
|
||||
paymentMethod: Value(paymentMethods[(i * 3) % paymentMethods.length]),
|
||||
paymentMethod: Value(paymentMethods[(i * 3) % paymentMethods.length].value),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ class HistoryViewModel extends ChangeNotifier {
|
||||
_totalCount = results[1] as int;
|
||||
_customerNames = results[2] as List<String>;
|
||||
_offset = _closedTabs.length;
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('HistoryViewModel: load error: $e');
|
||||
_errorMessage = 'Could not load tab history.';
|
||||
} finally {
|
||||
_hasLoaded = true;
|
||||
@@ -92,7 +93,8 @@ class HistoryViewModel extends ChangeNotifier {
|
||||
final more = await _fetchPage(offset: _offset);
|
||||
_closedTabs = [..._closedTabs, ...more];
|
||||
_offset = _closedTabs.length;
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('HistoryViewModel: loadMore error: $e');
|
||||
_errorMessage = 'Could not load more tabs.';
|
||||
} finally {
|
||||
_isLoadingMore = false;
|
||||
|
||||
@@ -56,7 +56,8 @@ class PinLockViewModel extends ChangeNotifier {
|
||||
final settings = await svc.getSettings();
|
||||
_pinRequired = settings.pinRequired;
|
||||
}
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('PinLockViewModel: load error: $e');
|
||||
_errorMessage = 'Could not check PIN status.';
|
||||
} finally {
|
||||
_hasLoaded = true;
|
||||
@@ -85,7 +86,8 @@ class PinLockViewModel extends ChangeNotifier {
|
||||
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('PinLockViewModel: setPin error: $e');
|
||||
_errorMessage = 'Could not save PIN.';
|
||||
notifyListeners();
|
||||
return false;
|
||||
@@ -108,7 +110,8 @@ class PinLockViewModel extends ChangeNotifier {
|
||||
_errorMessage = 'Incorrect PIN.';
|
||||
notifyListeners();
|
||||
return false;
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('PinLockViewModel: verify error: $e');
|
||||
_errorMessage = 'Could not verify PIN.';
|
||||
notifyListeners();
|
||||
return false;
|
||||
|
||||
@@ -48,27 +48,14 @@ class ProductListViewModel extends ChangeNotifier {
|
||||
|
||||
try {
|
||||
await inventory.load();
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('ProductListViewModel: load error: $e');
|
||||
_errorMessage = 'Could not load products.';
|
||||
} finally {
|
||||
_hasLoaded = true;
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// try {
|
||||
// _products = await productService.getProducts();
|
||||
//
|
||||
// debugPrint(
|
||||
// _products.map((p) => '${p.name}: ${p.stockQuantity}').join('\n'),
|
||||
// );
|
||||
// } catch (_) {
|
||||
// _errorMessage = 'Could not load products.';
|
||||
// } finally {
|
||||
// _hasLoaded = true;
|
||||
// _isLoading = false;
|
||||
// notifyListeners();
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> addProduct({
|
||||
|
||||
@@ -44,7 +44,8 @@ class SettingsViewModel extends ChangeNotifier {
|
||||
|
||||
try {
|
||||
_settings = await settingsService.getSettings();
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('SettingsViewModel: load error: $e');
|
||||
_errorMessage = 'Could not load settings.';
|
||||
} finally {
|
||||
_hasLoaded = true;
|
||||
@@ -118,7 +119,8 @@ class SettingsViewModel extends ChangeNotifier {
|
||||
|
||||
try {
|
||||
await settingsService.saveSettings(updated);
|
||||
} catch (_) {
|
||||
} catch (e) {
|
||||
debugPrint('SettingsViewModel: save error: $e');
|
||||
_settings = previous;
|
||||
_errorMessage = 'Could not save settings.';
|
||||
notifyListeners();
|
||||
|
||||
Reference in New Issue
Block a user