update
This commit is contained in:
1 parent
97c10c8d12
commit
212410f716
10 files changed
+1061
-32
No files matched your search
@@ -1,11 +1,20 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../../data/repositories/match_repository.dart';
|
||||
import '../../../../data/services/match_data_service.dart';
|
||||
import '../../../../domain/models/hockey_game.dart';
|
||||
|
||||
class MatchResultsViewModel extends ChangeNotifier {
|
||||
MatchResultsViewModel({required this.repository});
|
||||
MatchResultsViewModel({
|
||||
required MatchRepository repository,
|
||||
Duration updateInterval = const Duration(seconds: 1),
|
||||
}) : _dataService = MatchDataService(
|
||||
repository: repository,
|
||||
updateInterval: updateInterval,
|
||||
);
|
||||
|
||||
final MatchRepository repository;
|
||||
final MatchDataService _dataService;
|
||||
List<Match> _matches = [];
|
||||
bool _isLoading = false;
|
||||
String? _errorMessage;
|
||||
@@ -14,13 +23,31 @@ class MatchResultsViewModel extends ChangeNotifier {
|
||||
bool get isLoading => _isLoading;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
Future<void> removeMatch(Match match) async {
|
||||
try {
|
||||
await _dataService.removeMatch(match);
|
||||
} catch (_) {
|
||||
_errorMessage = 'Unable to save match results.';
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadMatches() async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
_matches = await repository.loadMatches();
|
||||
await _dataService.start(
|
||||
onMatchesChanged: (matches) {
|
||||
_matches = matches;
|
||||
notifyListeners();
|
||||
},
|
||||
onError: (_) {
|
||||
_errorMessage = 'Unable to save match results.';
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
_errorMessage = 'Unable to load match results.';
|
||||
} finally {
|
||||
@@ -28,4 +55,10 @@ class MatchResultsViewModel extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_dataService.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user