Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix score board state
Browse files Browse the repository at this point in the history
cp-sneha-s committed Apr 9, 2024
1 parent a7d52a9 commit 09d90b9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions khelo/lib/ui/flow/score_board/score_board_view_model.dart
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/data_model_extensions/ball_score_model_extension.dart';

import 'package:collection/collection.dart';
part 'score_board_view_model.freezed.dart';

final scoreBoardStateProvider = StateNotifierProvider.autoDispose<
@@ -410,7 +410,7 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
final outPlayer = state.batsMans
?.where((element) => element.player.id == playerOutId)
.firstOrNull;

print("OUT PLAYER: $outPlayer");
final batsMans = state.batsMans?.toList();
batsMans?.removeWhere((element) => element.player.id == playerOutId);
state = state.copyWith(batsMans: batsMans);
@@ -423,6 +423,7 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
status: wicketType == WicketType.retiredHurt
? PlayerStatus.injured
: PlayerStatus.played);

await _updateMatchPlayerStatus((
teamId: state.currentInning?.team_id ?? "INVALID ID",
players: [updatedPlayer]
@@ -695,15 +696,14 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
state.match?.id ?? "INVALID ID",
teamRequest,
);

final matchTeams = state.match!.teams.toList();

matchTeams.updateWhere(
final matches= matchTeams.updateWhere(
where: (element) => team.teamId == element.team.id,
updated: (oldElement) {
final teamSquadList = oldElement.squad.toList();
final newSquadList = team.players;
teamSquadList.updateWhere(
final teams= teamSquadList.updateWhere(
where: (element) =>
newSquadList.map((e) => e.player.id).contains(element.player.id),
updated: (oldElement) {
@@ -712,11 +712,11 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
},
);

return oldElement.copyWith(squad: teamSquadList);
return oldElement.copyWith(squad: teams);
},
);

state = state.copyWith(match: state.match?.copyWith(teams: matchTeams));
state = state.copyWith(match: state.match?.copyWith(teams: matches));
}

Future<void> startNextOver() async {

0 comments on commit 09d90b9

Please sign in to comment.