Skip to content

Commit

Permalink
fixing issue with getting an index of a player score (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkieres authored Nov 18, 2023
1 parent 803e4fb commit ee94a9f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class EditPlaythroughPageState extends State<EditPlaythroughPage> with EnterScor
Future<double> _editPlayerScore(PlayerScore playerScore, BuildContext context) async {
final viewModel = EnterScoreViewModel(playerScore);
await showEnterScoreDialog(context, viewModel);
widget.viewModel.updatePlayerScore(playerScore, viewModel.score);
widget.viewModel.updatePlayerScore(playerScore.id!, viewModel.score);
return viewModel.score;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,23 @@ abstract class _EditPlaythoughViewModel with Store {
}

@action
void updatePlayerScore(PlayerScore playerScore, double newScore) {
if (playerScore.score.hasScore && playerScore.score.score == newScore) {
void updatePlayerScore(String playerScoreId, double newScore) {
var playerScoreIndex = 0;
final playerScore = playerScores.firstWhereIndexedOrNull((index, ps) {
if (ps.id == playerScoreId) {
playerScoreIndex = index;
return true;
}

return false;
});

if (playerScore == null ||
(playerScore.score.hasScore && playerScore.score.score == newScore)) {
return;
}

final scoreGameResult = playerScore.score.scoreGameResult ?? const ScoreGameResult();

final playerScoreIndex = playerScores.indexOf(playerScore);
final updatedPlayerScore = playerScore.copyWith(
score: playerScore.score.copyWith(
scoreGameResult: scoreGameResult.copyWith(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void main() {
.firstWhereOrNull((element) => element.id == mockEmptyPlayerScoreId);
const newScore = 10.0;

editPlaythrouhgViewModel.updatePlayerScore(playerScoreToUpdate!, newScore);
editPlaythrouhgViewModel.updatePlayerScore(playerScoreToUpdate!.id!, newScore);

final updatedPlayerScore = editPlaythrouhgViewModel.playerScores
.firstWhereOrNull((element) => element.id == playerScoreToUpdate.id);
Expand Down

0 comments on commit ee94a9f

Please sign in to comment.