Skip to content

Commit

Permalink
Merge pull request #124 from canopas/Mayank/implement-tournament-deta…
Browse files Browse the repository at this point in the history
…il-stats-tab

Implement tournament detail stats tab
  • Loading branch information
cp-mayank authored Oct 28, 2024
2 parents f962fb7 + 7ea61bb commit b63f57a
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 103 deletions.
5 changes: 3 additions & 2 deletions data/lib/service/tournament/tournament_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ class TournamentService {
}
}
}

return playerStatsList.getTopKeyStats()
final keyStats = playerStatsList.getTopKeyStats()
..sort((a, b) => b.value?.compareTo(a.value ?? 0) ?? 0);

return keyStats.where((element) => element.player.isActive).toList();
}

Future<void> updateTeamIds(
Expand Down
9 changes: 9 additions & 0 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@
"tournament_detail_key_stat_most_fours_title": "Most Fours",
"tournament_detail_key_stat_most_sixes_title": "Most Sixes",

"tournament_detail_stats_empty_title": "No stats available yet!",
"tournament_detail_stats_empty_description": "The players are warming up! Stay tuned for exciting stats as the team progresses.",
"tournament_detail_stats_empty_filter_title": "No Stats Found",
"tournament_detail_stats_empty_filter_description": "Please try a different filter.",
"tournament_detail_stats_player_title": "Player",
"tournament_detail_stats_m_title": "M",
"tournament_detail_stats_avg_title": "Avg",
"tournament_detail_stats_runs_title": "Runs",

"@_TOURNAMENT_TYPE":{
},
"tournament_type_knock_out": "Knockout",
Expand Down
15 changes: 15 additions & 0 deletions khelo/lib/components/action_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/extensions/column_extensions.dart';
import 'package:style/text/app_text_style.dart';

import '../gen/assets.gen.dart';

Future<T?> showActionBottomSheet<T>({
required BuildContext context,
required List<BottomSheetAction> items,
Expand Down Expand Up @@ -60,13 +63,15 @@ class BottomSheetAction extends StatelessWidget {
final Widget? child;
final bool enabled;
final String? subTitle;
final bool showCheck;
final VoidCallback? onTap;

const BottomSheetAction({
super.key,
this.icon,
required this.title,
this.enabled = true,
this.showCheck = false,
this.child,
this.subTitle,
this.onTap,
Expand Down Expand Up @@ -107,6 +112,16 @@ class BottomSheetAction extends StatelessWidget {
],
),
),
Visibility(
visible: showCheck,
child: SvgPicture.asset(
Assets.images.icCheck,
colorFilter: ColorFilter.mode(
context.colorScheme.primary,
BlendMode.srcATop,
),
),
),
Visibility(
visible: child != null,
child: child ?? const SizedBox(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:data/api/ball_score/ball_score_model.dart';
import 'package:data/api/match/match_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:khelo/components/action_bottom_sheet.dart';
import 'package:khelo/components/empty_screen.dart';
Expand All @@ -15,8 +14,6 @@ import 'package:style/extensions/context_extensions.dart';
import 'package:style/indicator/progress_indicator.dart';
import 'package:style/widgets/adaptive_outlined_tile.dart';

import '../../../../../gen/assets.gen.dart';

class MatchDetailHighlightView extends ConsumerWidget {
const MatchDetailHighlightView({super.key});

Expand Down Expand Up @@ -181,10 +178,7 @@ class MatchDetailHighlightView extends ConsumerWidget {
.map((option) => BottomSheetAction(
title: option.getString(context),
enabled: highlightFilterOption != option,
child: _checkWidget(
context,
isShowCheck: highlightFilterOption == option,
),
showCheck: highlightFilterOption == option,
onTap: () {
context.pop();
onTap(option);
Expand All @@ -205,10 +199,7 @@ class MatchDetailHighlightView extends ConsumerWidget {
?.map((match) => BottomSheetAction(
title: match.team.name,
enabled: highlightTeamId != match.team.id,
child: _checkWidget(
context,
isShowCheck: highlightTeamId == match.team.id,
),
showCheck: highlightTeamId == match.team.id,
onTap: () {
context.pop();
onTap(match.team.id);
Expand All @@ -218,18 +209,4 @@ class MatchDetailHighlightView extends ConsumerWidget {
[],
);
}

Widget? _checkWidget(
BuildContext context, {
required bool isShowCheck,
}) =>
isShowCheck
? SvgPicture.asset(
Assets.images.icCheck,
colorFilter: ColorFilter.mode(
context.colorScheme.primary,
BlendMode.srcATop,
),
)
: null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

import '../../../../../gen/assets.gen.dart';

class FilterTabView extends StatelessWidget {
final String title;
final String filterValue;
final VoidCallback onFilter;

const FilterTabView({
super.key,
required this.title,
required this.onFilter,
required this.filterValue,
});

@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: AppTextStyle.header4.copyWith(
color: context.colorScheme.textPrimary,
),
),
TextButton.icon(
iconAlignment: IconAlignment.end,
onPressed: onFilter,
label: Text(
filterValue,
style: AppTextStyle.body2.copyWith(
color: context.colorScheme.primary,
),
),
icon: SvgPicture.asset(
Assets.images.icArrowDown,
height: 18,
width: 18,
colorFilter: ColorFilter.mode(
context.colorScheme.primary,
BlendMode.srcATop,
),
),
),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,34 @@ import 'package:data/api/match/match_model.dart';
import 'package:data/api/team/team_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:khelo/components/match_detail_cell.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/ui/app_route.dart';
import 'package:khelo/ui/flow/tournament/detail/components/filter_tab_view.dart';
import 'package:style/button/bottom_sticky_overlay.dart';
import 'package:style/button/primary_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

import '../../../../../components/action_bottom_sheet.dart';
import '../../../../../components/empty_screen.dart';
import '../../../../../gen/assets.gen.dart';
import '../tournament_detail_view_model.dart';

class TournamentDetailMatchesTab extends ConsumerWidget {
final List<TeamModel> teams;
final List<MatchModel> filteredMatches;
final Function(String) onMatchFilter;
final Function(List<MatchModel>) onSelected;

const TournamentDetailMatchesTab({
super.key,
required this.teams,
required this.filteredMatches,
required this.onMatchFilter,
required this.onSelected,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(tournamentDetailStateProvider);
if (filteredMatches.isEmpty) {

if (state.filteredMatches.isEmpty) {
return Stack(
children: [
EmptyScreen(
Expand All @@ -52,8 +47,18 @@ class TournamentDetailMatchesTab extends ConsumerWidget {
padding: context.mediaQueryPadding.copyWith(top: 0) +
EdgeInsets.all(16).copyWith(bottom: 24),
children: [
_filterView(context, state),
...filteredMatches.map(
FilterTabView(
title: context.l10n.tournament_detail_matches_filter_by_teams_title,
onFilter: () => showFilterOptionSelectionSheet(
context,
matchFilter: state.matchFilter,
teams: state.tournament!.teams,
onTap: onMatchFilter,
),
filterValue: state.matchFilter ??
context.l10n.tournament_detail_matches_filter_all_teams_option,
),
...state.filteredMatches.map(
(match) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
Expand All @@ -70,48 +75,11 @@ class TournamentDetailMatchesTab extends ConsumerWidget {
);
}

Widget _filterView(BuildContext context, TournamentDetailState state) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
context.l10n.tournament_detail_matches_filter_by_teams_title,
style: AppTextStyle.header4.copyWith(
color: context.colorScheme.textPrimary,
),
),
TextButton.icon(
iconAlignment: IconAlignment.end,
onPressed: () => showFilterOptionSelectionSheet(
context,
matchFilter: state.matchFilter,
onTap: onMatchFilter,
),
label: Text(
state.matchFilter ??
context.l10n.tournament_detail_matches_filter_all_teams_option,
style: AppTextStyle.body2.copyWith(
color: context.colorScheme.primary,
),
),
icon: SvgPicture.asset(
Assets.images.icArrowDown,
height: 18,
width: 18,
colorFilter: ColorFilter.mode(
context.colorScheme.primary,
BlendMode.srcATop,
),
),
),
],
);
}

void showFilterOptionSelectionSheet(
BuildContext context, {
required Function(String) onTap,
String? matchFilter,
required List<TeamModel> teams,
}) async {
final filterOptions = [
context.l10n.tournament_detail_matches_filter_all_teams_option,
Expand All @@ -124,10 +92,7 @@ class TournamentDetailMatchesTab extends ConsumerWidget {
.map((option) => BottomSheetAction(
title: option,
enabled: matchFiltered != option,
child: _checkWidget(
context,
isShowCheck: matchFiltered == option,
),
showCheck: matchFiltered == option,
onTap: () {
context.pop();
onTap(option);
Expand All @@ -136,20 +101,6 @@ class TournamentDetailMatchesTab extends ConsumerWidget {
.toList());
}

Widget? _checkWidget(
BuildContext context, {
required bool isShowCheck,
}) =>
isShowCheck
? SvgPicture.asset(
Assets.images.icCheck,
colorFilter: ColorFilter.mode(
context.colorScheme.primary,
BlendMode.srcATop,
),
)
: null;

Widget _stickyButton(BuildContext context) {
return BottomStickyOverlay(
child: PrimaryButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import '../../../../../components/image_avatar.dart';

class TournamentDetailOverviewTab extends ConsumerStatefulWidget {
final TournamentModel tournament;
final PageController controller;

const TournamentDetailOverviewTab({
super.key,
required this.tournament,
required this.controller,
});

@override
Expand Down Expand Up @@ -234,6 +236,7 @@ class _TournamentDetailOverviewTabState
style: AppTextStyle.caption.copyWith(
color: context.colorScheme.textDisabled,
),
overflow: TextOverflow.ellipsis,
)
],
),
Expand Down
Loading

0 comments on commit b63f57a

Please sign in to comment.