Skip to content

Commit

Permalink
Bug fixes (#8)
Browse files Browse the repository at this point in the history
* Dismiss penalty dialogue

* Fix Status of injured player

* Add team name on the score board

* WIP -Implement Abandon match case

* center align team name

---------

Co-authored-by: sidhdhi canopas <[email protected]>
  • Loading branch information
cp-sneha-s and cp-sidhdhi-p authored Apr 11, 2024
1 parent 98fa046 commit c9350b9
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Khelo is an open-source Flutter project written in Dart using Firestore database

## Download App

<img src="./cta/google play.png" width="200" ></img> <a href="https://apps.apple.com/us/app/khelo/id6480175424"><img src="./cta/app store.png" width="200"></img>
<a href= "https://play.google.com/store/apps/details?id=com.canopas.khelo"><img src="./cta/google play.png" width="200" ></img> <a href="https://apps.apple.com/us/app/khelo/id6480175424"><img src="./cta/app store.png" width="200"></img>

## Screenshots
<table>
Expand Down
3 changes: 2 additions & 1 deletion data/lib/api/match/match_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ enum PitchType {
enum MatchStatus {
yetToStart(1),
running(2),
finish(3);
finish(3),
abandoned(4);

final int value;

Expand Down
1 change: 1 addition & 0 deletions data/lib/api/match/match_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
}
}
},
"score_board_end_of_match_title": "End Match",
"score_board_choose_fielder_title": "choose Fielder",
"score_board_injured_tag_title": "Injured",
"score_board_who_on_strike_title": "Who's on Strike?",
Expand All @@ -310,6 +311,8 @@
"score_board_pause_title": "Pause",
"score_board_more_options_title": "More Options",
"score_board_pause_scoring_description_text": "are you sure you want to pause scoring?",
"score_board_end_match_title": "End Match",
"score_board_end_match_description_text": "are you sure you want to end match?",
"score_board_need_run_text": "Need {run} in {ball}",
"@score_board_need_run_text": {
"description": "Need {run} in {ball}",
Expand Down Expand Up @@ -347,6 +350,7 @@
"match_status_yet_to_start_title": "Yet to start",
"match_status_running_title": "Running",
"match_status_finish_title": "Finish",
"match_status_abandoned_title": "Abandoned",

"wicket_type_bowled_title": "Bowled",
"wicket_type_caught_title": "Caught",
Expand Down
4 changes: 4 additions & 0 deletions khelo/lib/domain/extensions/enum_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ extension MatchStatusString on MatchStatus {
return context.l10n.match_status_running_title;
case MatchStatus.finish:
return context.l10n.match_status_finish_title;
case MatchStatus.abandoned:
return context.l10n.match_status_abandoned_title;
}
}

Expand All @@ -160,6 +162,8 @@ extension MatchStatusString on MatchStatus {
return context.colorScheme.alert;
case MatchStatus.finish:
return context.colorScheme.positive;
case MatchStatus.abandoned:
return context.colorScheme.secondary;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AddPenaltyRunDialog extends ConsumerStatefulWidget {
BuildContext context,
) {
return showDialog(
barrierDismissible: false,
barrierDismissible: true,
context: context,
builder: (context) {
return const AddPenaltyRunDialog();
Expand All @@ -39,27 +39,31 @@ class _AddPenaltyRunDialogState extends ConsumerState<AddPenaltyRunDialog> {
@override
Widget build(BuildContext context) {
final state = ref.watch(scoreBoardStateProvider);
return AlertDialog(
backgroundColor: context.colorScheme.containerLowOnSurface,
title: Text(
context.l10n.score_board_penalty_run_title,
style: AppTextStyle.subtitle1
.copyWith(color: context.colorScheme.textPrimary),
),
content: _addPenaltyContent(context, state),
actionsAlignment: MainAxisAlignment.spaceAround,
actions: [
PrimaryButton(
context.l10n.common_okay_title,
enabled: isButtonEnable,
onPressed: () {
context.pop((
teamId: selectedTeamId,
runs: int.parse(runController.text),
));
},
return Material(
type: MaterialType.transparency,
color: Colors.transparent,
child: AlertDialog.adaptive(
backgroundColor: context.colorScheme.containerLowOnSurface,
title: Text(
context.l10n.score_board_penalty_run_title,
style: AppTextStyle.subtitle1
.copyWith(color: context.colorScheme.textPrimary),
),
],
content: _addPenaltyContent(context, state),
actionsAlignment: MainAxisAlignment.spaceAround,
actions: [
PrimaryButton(
context.l10n.common_okay_title,
enabled: isButtonEnable,
onPressed: () {
context.pop((
teamId: selectedTeamId,
runs: int.parse(runController.text),
));
},
),
],
),
);
}

Expand Down
37 changes: 34 additions & 3 deletions khelo/lib/ui/flow/score_board/components/score_display_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class ScoreDisplayView extends ConsumerWidget {
return Expanded(
child: ListView(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: _teamName(context, state, true),
),
_matchScoreView(context, state),
const SizedBox(
height: 24,
Expand All @@ -29,6 +33,28 @@ class ScoreDisplayView extends ConsumerWidget {
);
}

Widget _teamName(
BuildContext context, ScoreBoardViewState state, bool batting) {
final String? battingTeam = state.match?.teams
.firstWhere(
(element) => element.team.id == state.currentInning?.team_id)
.team
.name;
final String? bowlingTeam = state.match?.teams
.firstWhere((element) => element.team.id == state.otherInning?.team_id)
.team
.name;

return Text(
(batting ? battingTeam : bowlingTeam) ?? "",
textAlign: TextAlign.center,
style: AppTextStyle.header1.copyWith(
color: batting
? context.colorScheme.primary
: context.colorScheme.textInversePrimary),
);
}

Widget _matchScoreView(
BuildContext context,
ScoreBoardViewState state,
Expand Down Expand Up @@ -223,6 +249,10 @@ class ScoreDisplayView extends ConsumerWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_teamName(context, state, false),
const SizedBox(
height: 8,
),
_bowlerNameView(
context,
state.bowler?.player.name ??
Expand All @@ -241,10 +271,11 @@ class ScoreDisplayView extends ConsumerWidget {
TextSpan(
children: [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Icon(
Icons.sports_baseball_outlined,
color: context.colorScheme.surface,
)),
Icons.sports_baseball_outlined,
color: context.colorScheme.surface,
)),
TextSpan(
text: ' $name',
style: TextStyle(
Expand Down
20 changes: 18 additions & 2 deletions khelo/lib/ui/flow/score_board/score_board_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import 'package:khelo/ui/flow/score_board/components/select_wicket_taker_sheet.d
import 'package:khelo/ui/flow/score_board/components/select_wicket_type_sheet.dart';
import 'package:khelo/ui/flow/score_board/components/striker_selection_dialog.dart';
import 'package:khelo/ui/flow/score_board/score_board_view_model.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/indicator/progress_indicator.dart';

import 'components/inning_complete_dialog.dart';
Expand Down Expand Up @@ -285,6 +284,22 @@ class _ScoreBoardScreenState extends ConsumerState<ScoreBoardScreen> {
});
}

void _observeEndMatchDialogue(BuildContext context, WidgetRef ref) {
ref.listen(
scoreBoardStateProvider.select(
(value) => value.showEndMatchDialog), (previous, next) {
if (next != null) {
ConfirmActionDialog.show(
context,
title: context.l10n.score_board_end_match_title,
description: context.l10n.score_board_end_match_description_text,
primaryButtonText: context.l10n.common_okay_title,
onConfirmation:notifier.abandonMatch,
);
}
});
}

void _observeInvalidUndoToast(BuildContext context, WidgetRef ref) {
ref.listen(
scoreBoardStateProvider.select((value) => value.invalidUndoToast),
Expand Down Expand Up @@ -334,6 +349,7 @@ class _ScoreBoardScreenState extends ConsumerState<ScoreBoardScreen> {
_observePop(context, ref);
_observeShowPauseScoringDialog(context, ref);
_observeShowAddPenaltyRunDialog(context, ref);
_observeEndMatchDialogue(context, ref);
_observeInvalidUndoToast(context, ref);

return PopScope(
Expand All @@ -343,7 +359,7 @@ class _ScoreBoardScreenState extends ConsumerState<ScoreBoardScreen> {
actions: [_moreOptionButton(context, notifier, state)],
automaticallyImplyLeading: false,
body: Padding(
padding: context.mediaQueryPadding,
padding: const EdgeInsets.symmetric(vertical: 16),
child: _body(context, notifier, state),
),
),
Expand Down
38 changes: 31 additions & 7 deletions khelo/lib/ui/flow/score_board/score_board_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
state = state.copyWith(showPauseScoringDialog: DateTime.now());
case MatchOption.penaltyRun:
state = state.copyWith(showAddPenaltyRunDialog: DateTime.now());
case MatchOption.endMatch:
state = state.copyWith(showEndMatchDialog: DateTime.now());
default:
return;
}
Expand Down Expand Up @@ -776,11 +778,22 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
showSelectPlayerSheet: DateTime.now());
}

Future<void> endMatch() async {
Future<void> abandonMatch() async {
await _updateInningAndTeamScore();
state = state.copyWith(pop: true);
}

Future<void> endMatch({bool isComplete = true}) async {
List<MatchPlayer> batsMan = [];
if (state.batsMans?.isNotEmpty ?? false) {
var batsMan = state.batsMans!
.map((e) => e.copyWith(status: PlayerStatus.played))
.toList();
if (isComplete) {
batsMan = state.batsMans!
.map((e) => e.copyWith(status: PlayerStatus.played))
.toList();
} else {
batsMan = state.batsMans!;
}

await _updateMatchPlayerStatus((
teamId: state.currentInning?.team_id ?? "INVALID ID",
players: batsMan
Expand Down Expand Up @@ -856,7 +869,9 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {
int batsManIndex = state.lastAssignedIndex + 1;

if (statusUpdatedSquad.elementAt(index).index == null ||
statusUpdatedSquad.elementAt(index).index == 0) {
statusUpdatedSquad.elementAt(index).index == 0 ||
statusUpdatedSquad.elementAt(index).status ==
PlayerStatus.injured) {
statusUpdatedSquad[index] = statusUpdatedSquad
.elementAt(index)
.copyWith(index: batsManIndex, status: PlayerStatus.playing);
Expand All @@ -879,7 +894,12 @@ class ScoreBoardViewNotifier extends StateNotifier<ScoreBoardViewState> {

if (!(state.batsMans?.map((e) => e.player.id).contains(state.strikerId) ??
false)) {
_showStrikerSelectionDialog();
if (batsMen != null && batsMen.length == 1) {
setOrSwitchStriker(batsMan: batsMen.first.player);
return;
} else {
_showStrikerSelectionDialog();
}
}
}
}
Expand Down Expand Up @@ -912,6 +932,7 @@ class ScoreBoardViewState with _$ScoreBoardViewState {
DateTime? showAddExtraDialogForFiveSeven,
DateTime? showPauseScoringDialog,
DateTime? showAddPenaltyRunDialog,
DateTime? showEndMatchDialog,
DateTime? invalidUndoToast,
@Default([]) List<BallScoreModel> currentScoresList,
@Default([]) List<BallScoreModel> previousScoresList,
Expand Down Expand Up @@ -977,7 +998,8 @@ enum MatchOption {
changeStriker,
penaltyRun,
pauseScoring,
continueWithInjuredPlayer;
continueWithInjuredPlayer,
endMatch;

String getTitle(BuildContext context) {
switch (this) {
Expand All @@ -989,6 +1011,8 @@ enum MatchOption {
return context.l10n.score_board_pause_scoring_title;
case MatchOption.continueWithInjuredPlayer:
return context.l10n.score_board_continue_with_injured_player_title;
case MatchOption.endMatch:
return context.l10n.score_board_end_of_match_title;
}
}
}
Loading

0 comments on commit c9350b9

Please sign in to comment.