Skip to content

Commit

Permalink
Mr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-mayank committed Nov 7, 2024
1 parent 78699f1 commit fc6ec28
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 145 deletions.
2 changes: 1 addition & 1 deletion data/lib/api/match/match_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ extension TeamStatExtension on List<MatchModel> {
wickets += team.wicket;

battingAverageTotal +=
opponentTeam.wicket > 0 ? team.run / opponentTeam.wicket : 0;
team.wicket > 0 ? team.run / team.wicket : team.run;
if (team.wicket > 0) {
bowlingAverageTotal += opponentTeam.run / team.wicket;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/enum_extensions.dart';
import 'package:khelo/ui/flow/matches/add_match/add_match_view_model.dart';
import 'package:khelo/ui/flow/matches/add_match/components/section_title.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';
import 'package:style/button/chip_button.dart';
import 'package:data/api/match/match_model.dart';

class PitchSelectionView extends StatelessWidget {
Expand All @@ -31,47 +29,18 @@ class PitchSelectionView extends StatelessWidget {
padding: const EdgeInsets.only(left: 16, right: 8),
child: Row(
children: PitchType.values
.map((type) => _capsuleCell(
context: context,
title: type.getString(context),
isSelected: state.pitchType == type,
onTap: () => notifier.onPitchTypeSelection(type),
.map((type) => Padding(
padding: const EdgeInsets.only(right: 8),
child: ChipButton(
title: type.getString(context),
isSelected: state.pitchType == type,
onTap: () => notifier.onPitchTypeSelection(type),
),
))
.toList(),
)),
],
),
);
}

Widget _capsuleCell({
required BuildContext context,
required String title,
required bool isSelected,
required VoidCallback onTap,
}) {
return Padding(
padding: const EdgeInsets.only(right: 8),
child: OnTapScale(
onTap: () => onTap(),
child: Chip(
label: Text(
title,
style: AppTextStyle.body2.copyWith(
color: isSelected
? context.colorScheme.onPrimary
: context.colorScheme.textDisabled),
),
backgroundColor: isSelected
? context.colorScheme.primary
: context.colorScheme.containerLowOnSurface,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
side: const BorderSide(color: Colors.transparent),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/enum_extensions.dart';
import 'package:khelo/ui/flow/score_board/components/bottom_sheet_wrapper.dart';
import 'package:khelo/ui/flow/score_board/score_board_view_model.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/button/chip_button.dart';
import 'package:style/button/primary_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

class SelectWicketTypeSheet extends ConsumerStatefulWidget {
static Future<T?> show<T>(BuildContext context) {
Expand Down Expand Up @@ -64,26 +63,10 @@ class _SelectWicketTypeSheetState extends ConsumerState<SelectWicketTypeSheet> {
children: WicketType.values.map(
(element) {
final isSelected = selectedType == element;
return OnTapScale(
return ChipButton(
isSelected: isSelected,
title: element.getString(context),
onTap: () => setState(() => selectedType = element),
child: Chip(
label: Text(
element.getString(context),
style: AppTextStyle.body2.copyWith(
color: isSelected
? context.colorScheme.onPrimary
: context.colorScheme.textSecondary,
),
),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
side: const BorderSide(color: Colors.transparent),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
backgroundColor: isSelected
? context.colorScheme.primary
: context.colorScheme.containerLowOnSurface,
),
);
},
).toList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import 'package:data/api/match/match_model.dart';
import 'package:data/api/tournament/tournament_model.dart';
import 'package:data/api/user/user_models.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/enum_extensions.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/button/chip_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

Expand Down Expand Up @@ -198,6 +199,7 @@ class TournamentDetailStatsTab extends ConsumerWidget {
required Function(KeyStatFilterTag) onTap,
KeyStatFilterTag? selectedTag,
}) async {
HapticFeedback.mediumImpact();
return await showModalBottomSheet(
context: context,
showDragHandle: true,
Expand All @@ -216,31 +218,13 @@ class TournamentDetailStatsTab extends ConsumerWidget {
runSpacing: 8,
children: KeyStatFilterTag.values.map(
(element) {
final isSelected = selectedTag == element;
return OnTapScale(
return ChipButton(
title: element.getString(context),
isSelected: selectedTag == element,
onTap: () {
context.pop();
onTap(element);
},
child: Chip(
label: Text(
element.getString(context),
style: AppTextStyle.body2.copyWith(
color: isSelected
? context.colorScheme.onPrimary
: context.colorScheme.textSecondary,
),
),
padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
side: const BorderSide(color: Colors.transparent),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
backgroundColor: isSelected
? context.colorScheme.primary
: context.colorScheme.containerLowOnSurface,
),
);
},
).toList(),
Expand Down
113 changes: 51 additions & 62 deletions khelo/lib/ui/flow/tournament/detail/tournament_detail_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,68 +121,57 @@ class TournamentDetailStateViewNotifier

var filteredStats = state.tournament!.keyStats;

switch (tag) {
case KeyStatFilterTag.runs:
filteredStats = filteredStats
.where((element) => (element.stats.battingStat?.runScored ?? 0) > 0)
.toList();
break;
case KeyStatFilterTag.wickets:
filteredStats = filteredStats
.where((element) =>
(element.stats.bowlingStat?.wicketTaken ?? 0.0) > 0.0)
.toList();
break;
case KeyStatFilterTag.battingAverage:
filteredStats = filteredStats
.where(
(element) => (element.stats.battingStat?.average ?? 0.0) > 0.0)
.toList();
break;
case KeyStatFilterTag.bowlingAverage:
filteredStats = filteredStats
.where(
(element) => (element.stats.bowlingStat?.average ?? 0.0) > 0.0)
.toList();
break;
case KeyStatFilterTag.mostHundreds:
filteredStats = filteredStats
.where((e) => (e.stats.battingStat?.hundreds ?? 0) > 0)
.toList()
..sort((a, b) => (b.stats.battingStat?.hundreds ?? 0)
.compareTo(a.stats.battingStat?.hundreds ?? 0));
break;
case KeyStatFilterTag.mostFifties:
filteredStats = filteredStats
.where((e) => (e.stats.battingStat?.fifties ?? 0) > 0)
.toList()
..sort((a, b) => (b.stats.battingStat?.fifties ?? 0)
.compareTo(a.stats.battingStat?.fifties ?? 0));
break;
case KeyStatFilterTag.sixes:
filteredStats = filteredStats
.where((e) => (e.stats.battingStat?.sixes ?? 0) > 0)
.toList();
break;
case KeyStatFilterTag.fours:
filteredStats = filteredStats
.where((e) => (e.stats.battingStat?.fours ?? 0) > 0)
.toList();
break;
case KeyStatFilterTag.boundaries:
filteredStats = filteredStats
.where((e) =>
(e.stats.battingStat?.fours ?? 0) +
(e.stats.battingStat?.sixes ?? 0) >
0)
.toList()
..sort((a, b) => ((b.stats.battingStat?.fours ?? 0) +
(b.stats.battingStat?.sixes ?? 0))
.compareTo((a.stats.battingStat?.fours ?? 0) +
(a.stats.battingStat?.sixes ?? 0)));
break;
case null:
break;
filteredStats = filteredStats.where((e) {
switch (tag) {
case KeyStatFilterTag.runs:
return (e.stats.battingStat?.runScored ?? 0) > 0;
case KeyStatFilterTag.wickets:
return (e.stats.bowlingStat?.wicketTaken ?? 0.0) > 0.0;
case KeyStatFilterTag.battingAverage:
return (e.stats.battingStat?.average ?? 0.0) > 0.0;
case KeyStatFilterTag.bowlingAverage:
return (e.stats.bowlingStat?.average ?? 0.0) > 0.0;
case KeyStatFilterTag.mostHundreds:
return (e.stats.battingStat?.hundreds ?? 0) > 0;
case KeyStatFilterTag.mostFifties:
return (e.stats.battingStat?.fifties ?? 0) > 0;
case KeyStatFilterTag.sixes:
return (e.stats.battingStat?.sixes ?? 0) > 0;
case KeyStatFilterTag.fours:
return (e.stats.battingStat?.fours ?? 0) > 0;
case KeyStatFilterTag.boundaries:
return (e.stats.battingStat?.fours ?? 0) +
(e.stats.battingStat?.sixes ?? 0) >
0;
case null:
return false;
}
}).toList();

if (tag == KeyStatFilterTag.mostHundreds ||
tag == KeyStatFilterTag.mostFifties ||
tag == KeyStatFilterTag.boundaries) {
filteredStats.sort((a, b) {
int compareByTag(PlayerKeyStat x, PlayerKeyStat y) {
switch (tag) {
case KeyStatFilterTag.mostHundreds:
return (y.stats.battingStat?.hundreds ?? 0)
.compareTo(x.stats.battingStat?.hundreds ?? 0);
case KeyStatFilterTag.mostFifties:
return (y.stats.battingStat?.fifties ?? 0)
.compareTo(x.stats.battingStat?.fifties ?? 0);
case KeyStatFilterTag.boundaries:
return ((y.stats.battingStat?.fours ?? 0) +
(y.stats.battingStat?.sixes ?? 0))
.compareTo((x.stats.battingStat?.fours ?? 0) +
(x.stats.battingStat?.sixes ?? 0));
default:
return 0;
}
}

return compareByTag(a, b);
});
}

state = state.copyWith(
Expand Down
43 changes: 43 additions & 0 deletions style/lib/button/chip_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:style/extensions/context_extensions.dart';

import '../animations/on_tap_scale.dart';
import '../text/app_text_style.dart';

class ChipButton extends StatelessWidget {
final bool isSelected;
final String title;
final VoidCallback? onTap;

const ChipButton({
super.key,
this.isSelected = false,
required this.title,
this.onTap,
});

@override
Widget build(BuildContext context) {
return OnTapScale(
onTap: onTap,
child: Chip(
label: Text(
title,
style: AppTextStyle.body2.copyWith(
color: isSelected
? context.colorScheme.onPrimary
: context.colorScheme.textSecondary,
),
),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
side: const BorderSide(color: Colors.transparent),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
backgroundColor: isSelected
? context.colorScheme.primary
: context.colorScheme.containerLowOnSurface,
),
);
}
}

0 comments on commit fc6ec28

Please sign in to comment.