From 4a8a07d39cbf9f516cd8308ed927096eeb44b885 Mon Sep 17 00:00:00 2001 From: sidhdhi canopas <122426509+cp-sidhdhi-p@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:16:49 +0530 Subject: [PATCH] fix team detail not updating (#58) --- .../matches/add_match/add_match_screen.dart | 2 +- .../flow/team/add_team/add_team_screen.dart | 2 +- .../flow/team/detail/team_detail_screen.dart | 30 ++++++++++++++----- .../team/detail/team_detail_view_model.dart | 11 +++++-- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/khelo/lib/ui/flow/matches/add_match/add_match_screen.dart b/khelo/lib/ui/flow/matches/add_match/add_match_screen.dart index c6aeddec..28fb7785 100644 --- a/khelo/lib/ui/flow/matches/add_match/add_match_screen.dart +++ b/khelo/lib/ui/flow/matches/add_match/add_match_screen.dart @@ -468,7 +468,7 @@ class _AddMatchScreenState extends ConsumerState { ref.listen(addMatchViewStateProvider.select((value) => value.pop), (previous, next) { if (next != null && next) { - context.pop(); + context.pop(true); } }); } diff --git a/khelo/lib/ui/flow/team/add_team/add_team_screen.dart b/khelo/lib/ui/flow/team/add_team/add_team_screen.dart index 46b7f414..c3978430 100644 --- a/khelo/lib/ui/flow/team/add_team/add_team_screen.dart +++ b/khelo/lib/ui/flow/team/add_team/add_team_screen.dart @@ -296,7 +296,7 @@ class _AddTeamScreenState extends ConsumerState { addTeamStateProvider.select((value) => value.isPop), (previous, current) async { if (current && context.mounted) { - context.pop(); + context.pop(current); } }, ); diff --git a/khelo/lib/ui/flow/team/detail/team_detail_screen.dart b/khelo/lib/ui/flow/team/detail/team_detail_screen.dart index 29de9af2..bc9ca9df 100644 --- a/khelo/lib/ui/flow/team/detail/team_detail_screen.dart +++ b/khelo/lib/ui/flow/team/detail/team_detail_screen.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:data/api/user/user_models.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; @@ -70,7 +71,7 @@ class _TeamDetailScreenState extends ConsumerState { ? Icons.more_horiz_rounded : Icons.more_vert_rounded, color: context.colorScheme.textPrimary), - onPressed: () => _moreActionButton(context, state), + onPressed: () => _moreActionButton(context, notifier, state), ), ] : null, @@ -185,32 +186,45 @@ class _TeamDetailScreenState extends ConsumerState { void _moreActionButton( BuildContext context, + TeamDetailViewNotifier notifier, TeamDetailState state, ) async { return showActionBottomSheet(context: context, items: [ BottomSheetAction( title: context.l10n.common_edit_team_title, - onTap: () { + onTap: () async { context.pop(); - AppRoute.addTeam(team: state.team).push(context); + bool? isUpdated = + await AppRoute.addTeam(team: state.team).push(context); + if (isUpdated == true && context.mounted) { + notifier.loadTeamById(); + } }, ), BottomSheetAction( title: context.l10n.add_match_screen_title, - onTap: () { + onTap: () async { context.pop(); - AppRoute.addMatch( + bool? isUpdated = await AppRoute.addMatch( defaultTeam: (state.team?.players?.length ?? 0) >= 2 ? state.team : null) - .push(context); + .push(context); + if (isUpdated == true && context.mounted) { + notifier.loadTeamById(); + } }, ), BottomSheetAction( title: context.l10n.team_list_add_members_title, - onTap: () { + onTap: () async { context.pop(); - AppRoute.addTeamMember(team: state.team!).push(context); + List? memberList = + await AppRoute.addTeamMember(team: state.team!) + .push>(context); + if (memberList != null && context.mounted) { + notifier.updateTeamMember(memberList); + } }, ), ]); diff --git a/khelo/lib/ui/flow/team/detail/team_detail_view_model.dart b/khelo/lib/ui/flow/team/detail/team_detail_view_model.dart index a5914796..f196e123 100644 --- a/khelo/lib/ui/flow/team/detail/team_detail_view_model.dart +++ b/khelo/lib/ui/flow/team/detail/team_detail_view_model.dart @@ -1,5 +1,6 @@ import 'package:data/api/match/match_model.dart'; import 'package:data/api/team/team_model.dart'; +import 'package:data/api/user/user_models.dart'; import 'package:data/service/match/match_service.dart'; import 'package:data/service/team/team_service.dart'; import 'package:data/storage/app_preferences.dart'; @@ -36,7 +37,7 @@ class TeamDetailViewNotifier extends StateNotifier { } try { - state = state.copyWith(loading: true); + state = state.copyWith(loading: state.team == null); final team = await _teamService.getTeamById(teamId!); state = state.copyWith(team: team, loading: false); @@ -53,7 +54,7 @@ class TeamDetailViewNotifier extends StateNotifier { return; } try { - state = state.copyWith(loading: true); + state = state.copyWith(loading: state.matches == null); final matches = await _matchService .getMatchesByTeamId(state.team!.id ?? "INVALID ID"); final teamStat = _calculateTeamStat(matches); @@ -187,6 +188,12 @@ class TeamDetailViewNotifier extends StateNotifier { ); } + void updateTeamMember(List members) { + state = state.copyWith( + team: state.team + ?.copyWith(players: [...state.team?.players ?? [], ...members])); + } + void onTabChange(int tab) { if (state.selectedTab != tab) { state = state.copyWith(selectedTab: tab);