From 4cd3df3b6c64f4bec558c21cafc1307cfff24bf1 Mon Sep 17 00:00:00 2001 From: Mayank Variya Date: Wed, 27 Nov 2024 14:22:30 +0530 Subject: [PATCH] Minor changes --- data/lib/api/ball_score/ball_score_model.dart | 13 +++---------- .../ui/flow/score_board/score_board_view_model.dart | 11 +++++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/data/lib/api/ball_score/ball_score_model.dart b/data/lib/api/ball_score/ball_score_model.dart index 9a172b25..c10e6643 100644 --- a/data/lib/api/ball_score/ball_score_model.dart +++ b/data/lib/api/ball_score/ball_score_model.dart @@ -640,26 +640,19 @@ extension BallScoreList on List { String currentUserId, { UserStat? oldUserStats, UserStatType? type, + bool isMatchComplete = false, }) { final newBattingStat = calculateBattingStats(currentUserId); final newBowlingStat = calculateBowlingStats(currentUserId); final newFieldingStat = calculateFieldingStats(currentUserId); - final uniqueMatches = where( - (ball) => - ball.batsman_id == currentUserId || - ball.non_striker_id == currentUserId || - ball.bowler_id == currentUserId || - ball.player_out_id == currentUserId || - ball.wicket_taker_id == currentUserId, - ).map((ball) => ball.match_id).toSet(); - final newUserStats = UserStat( - matches: uniqueMatches.length, + matches: isMatchComplete ? 1 : 0, type: type, batting: newBattingStat, bowling: newBowlingStat, fielding: newFieldingStat, + ); return oldUserStats?.updateStat(newUserStats) ?? newUserStats; diff --git a/khelo/lib/ui/flow/score_board/score_board_view_model.dart b/khelo/lib/ui/flow/score_board/score_board_view_model.dart index 40ce74bc..18d3bd5f 100644 --- a/khelo/lib/ui/flow/score_board/score_board_view_model.dart +++ b/khelo/lib/ui/flow/score_board/score_board_view_model.dart @@ -772,7 +772,7 @@ class ScoreBoardViewNotifier extends StateNotifier { } } - void _addPlayerStats() async { + void _addPlayerStats({bool isMatchComplete = false}) async { try { final userStatType = state.match?.match_type == MatchType.testMatch ? UserStatType.test @@ -787,8 +787,11 @@ class ScoreBoardViewNotifier extends StateNotifier { element.wicket_taker_id == player, ) .toList() - .calculateUserStats(player, - oldUserStats: oldStats, type: userStatType); + .calculateUserStats( + player, + oldUserStats: oldStats, + type: userStatType, + ); await _userService.updateUserStats(player, newState); } } catch (e) { @@ -1200,7 +1203,7 @@ class ScoreBoardViewNotifier extends StateNotifier { } try { state = state.copyWith(actionError: null, isActionInProgress: true); - _addPlayerStats(); + _addPlayerStats(isMatchComplete: true); List batsMan = []; if (state.batsMans?.isNotEmpty ?? false) { batsMan = state.batsMans!