fix theme / add history
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../models/closed_tab.dart';
|
||||
import '../services/bar_tab_service.dart';
|
||||
|
||||
class HistoryViewModel extends ChangeNotifier {
|
||||
final BarTabService barTabService;
|
||||
|
||||
HistoryViewModel({
|
||||
required this.barTabService,
|
||||
});
|
||||
|
||||
List<ClosedTab> _closedTabs = [];
|
||||
bool _isLoading = false;
|
||||
bool _hasLoaded = false;
|
||||
String? _errorMessage;
|
||||
String _searchQuery = '';
|
||||
|
||||
List<ClosedTab> get closedTabs {
|
||||
if (_searchQuery.isEmpty) return _closedTabs;
|
||||
|
||||
return _closedTabs
|
||||
.where((tab) =>
|
||||
tab.customerName.toLowerCase().contains(_searchQuery.toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
bool get hasLoaded => _hasLoaded;
|
||||
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
Future<void> ensureLoaded() async {
|
||||
if (_hasLoaded || _isLoading) return;
|
||||
|
||||
await load();
|
||||
}
|
||||
|
||||
Future<void> load() async {
|
||||
if (_isLoading) return;
|
||||
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
_closedTabs = await barTabService.getClosedTabs();
|
||||
} catch (_) {
|
||||
_errorMessage = 'Could not load tab history.';
|
||||
} finally {
|
||||
_hasLoaded = true;
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void search(String query) {
|
||||
_searchQuery = query;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user