-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Achievement model blocked by achievementTracker\
- Loading branch information
Showing
3 changed files
with
56 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:game/api/game_api.dart'; | ||
import 'package:game/api/game_client_dto.dart'; | ||
|
||
/** | ||
* This file represents the model for the achievements. Whenever a achievement is updated, added or deleted from the backend, the model is updated and notifies the Consumer so that the front end can be modified. | ||
*/ | ||
class AchievementModel extends ChangeNotifier { | ||
Map<String, AchievementDto> _achievementsById = {}; | ||
ApiClient _client; | ||
|
||
AchievementModel(ApiClient client) : _client = client { | ||
/** | ||
* Stream that listens to updates on the achievements. | ||
*/ | ||
client.clientApi.updateAchievementDataStream.listen((event) { | ||
if (event.deleted) { | ||
_achievementsById.remove(event.achievement.id); | ||
} else { | ||
_achievementsById[event.achievement.id] = event.achievement; | ||
} | ||
notifyListeners(); | ||
}); | ||
|
||
client.clientApi.connectedStream.listen((event) { | ||
_achievementsById.clear(); | ||
notifyListeners(); | ||
}); | ||
} | ||
} |