Skip to content

Commit

Permalink
refactor and implement injured player flow
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sidhdhi-p committed Apr 8, 2024
1 parent 2358ba6 commit 4b371a0
Show file tree
Hide file tree
Showing 42 changed files with 1,935 additions and 1,627 deletions.
1 change: 1 addition & 0 deletions data/lib/api/ball_score/ball_score_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BallScoreModel with _$BallScoreModel {
required int ball_number,
required String bowler_id,
required String batsman_id,
required String non_striker_id,
int? runs_scored,
ExtrasType? extras_type,
int? extras_awarded,
Expand Down
24 changes: 23 additions & 1 deletion data/lib/api/ball_score/ball_score_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mixin _$BallScoreModel {
int get ball_number => throw _privateConstructorUsedError;
String get bowler_id => throw _privateConstructorUsedError;
String get batsman_id => throw _privateConstructorUsedError;
String get non_striker_id => throw _privateConstructorUsedError;
int? get runs_scored => throw _privateConstructorUsedError;
ExtrasType? get extras_type => throw _privateConstructorUsedError;
int? get extras_awarded => throw _privateConstructorUsedError;
Expand Down Expand Up @@ -55,6 +56,7 @@ abstract class $BallScoreModelCopyWith<$Res> {
int ball_number,
String bowler_id,
String batsman_id,
String non_striker_id,
int? runs_scored,
ExtrasType? extras_type,
int? extras_awarded,
Expand Down Expand Up @@ -85,6 +87,7 @@ class _$BallScoreModelCopyWithImpl<$Res, $Val extends BallScoreModel>
Object? ball_number = null,
Object? bowler_id = null,
Object? batsman_id = null,
Object? non_striker_id = null,
Object? runs_scored = freezed,
Object? extras_type = freezed,
Object? extras_awarded = freezed,
Expand Down Expand Up @@ -120,6 +123,10 @@ class _$BallScoreModelCopyWithImpl<$Res, $Val extends BallScoreModel>
? _value.batsman_id
: batsman_id // ignore: cast_nullable_to_non_nullable
as String,
non_striker_id: null == non_striker_id
? _value.non_striker_id
: non_striker_id // ignore: cast_nullable_to_non_nullable
as String,
runs_scored: freezed == runs_scored
? _value.runs_scored
: runs_scored // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -175,6 +182,7 @@ abstract class _$$BallScoreModelImplCopyWith<$Res>
int ball_number,
String bowler_id,
String batsman_id,
String non_striker_id,
int? runs_scored,
ExtrasType? extras_type,
int? extras_awarded,
Expand Down Expand Up @@ -203,6 +211,7 @@ class __$$BallScoreModelImplCopyWithImpl<$Res>
Object? ball_number = null,
Object? bowler_id = null,
Object? batsman_id = null,
Object? non_striker_id = null,
Object? runs_scored = freezed,
Object? extras_type = freezed,
Object? extras_awarded = freezed,
Expand Down Expand Up @@ -238,6 +247,10 @@ class __$$BallScoreModelImplCopyWithImpl<$Res>
? _value.batsman_id
: batsman_id // ignore: cast_nullable_to_non_nullable
as String,
non_striker_id: null == non_striker_id
? _value.non_striker_id
: non_striker_id // ignore: cast_nullable_to_non_nullable
as String,
runs_scored: freezed == runs_scored
? _value.runs_scored
: runs_scored // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -288,6 +301,7 @@ class _$BallScoreModelImpl implements _BallScoreModel {
required this.ball_number,
required this.bowler_id,
required this.batsman_id,
required this.non_striker_id,
this.runs_scored,
this.extras_type,
this.extras_awarded,
Expand All @@ -314,6 +328,8 @@ class _$BallScoreModelImpl implements _BallScoreModel {
@override
final String batsman_id;
@override
final String non_striker_id;
@override
final int? runs_scored;
@override
final ExtrasType? extras_type;
Expand All @@ -334,7 +350,7 @@ class _$BallScoreModelImpl implements _BallScoreModel {

@override
String toString() {
return 'BallScoreModel(id: $id, inning_id: $inning_id, over_number: $over_number, ball_number: $ball_number, bowler_id: $bowler_id, batsman_id: $batsman_id, runs_scored: $runs_scored, extras_type: $extras_type, extras_awarded: $extras_awarded, wicket_type: $wicket_type, player_out_id: $player_out_id, wicket_taker_id: $wicket_taker_id, is_four: $is_four, is_six: $is_six, time: $time)';
return 'BallScoreModel(id: $id, inning_id: $inning_id, over_number: $over_number, ball_number: $ball_number, bowler_id: $bowler_id, batsman_id: $batsman_id, non_striker_id: $non_striker_id, runs_scored: $runs_scored, extras_type: $extras_type, extras_awarded: $extras_awarded, wicket_type: $wicket_type, player_out_id: $player_out_id, wicket_taker_id: $wicket_taker_id, is_four: $is_four, is_six: $is_six, time: $time)';
}

@override
Expand All @@ -353,6 +369,8 @@ class _$BallScoreModelImpl implements _BallScoreModel {
other.bowler_id == bowler_id) &&
(identical(other.batsman_id, batsman_id) ||
other.batsman_id == batsman_id) &&
(identical(other.non_striker_id, non_striker_id) ||
other.non_striker_id == non_striker_id) &&
(identical(other.runs_scored, runs_scored) ||
other.runs_scored == runs_scored) &&
(identical(other.extras_type, extras_type) ||
Expand Down Expand Up @@ -380,6 +398,7 @@ class _$BallScoreModelImpl implements _BallScoreModel {
ball_number,
bowler_id,
batsman_id,
non_striker_id,
runs_scored,
extras_type,
extras_awarded,
Expand Down Expand Up @@ -413,6 +432,7 @@ abstract class _BallScoreModel implements BallScoreModel {
required final int ball_number,
required final String bowler_id,
required final String batsman_id,
required final String non_striker_id,
final int? runs_scored,
final ExtrasType? extras_type,
final int? extras_awarded,
Expand All @@ -439,6 +459,8 @@ abstract class _BallScoreModel implements BallScoreModel {
@override
String get batsman_id;
@override
String get non_striker_id;
@override
int? get runs_scored;
@override
ExtrasType? get extras_type;
Expand Down
2 changes: 2 additions & 0 deletions data/lib/api/ball_score/ball_score_model.g.dart

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

6 changes: 3 additions & 3 deletions data/lib/service/team/team_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class TeamService {
TeamService(this._currentUserId, this._firestore, this._userService);

Future<String> updateTeam(AddTeamRequestModel team) async {
DocumentReference teamRef =
_firestore.collection(_collectionName).doc(team.id);
DocumentReference teamRef = _firestore.collection(_collectionName).doc(team.id);
WriteBatch batch = _firestore.batch();

batch.set(teamRef, team.toJson(), SetOptions(merge: true));
Expand Down Expand Up @@ -129,7 +128,8 @@ class TeamService {
DocumentReference teamRef =
_firestore.collection(_collectionName).doc(teamId);

await teamRef.update({'players': FieldValue.arrayUnion(players)});
await teamRef.set(
{'players': FieldValue.arrayUnion(players)}, SetOptions(merge: true));
}

Future<void> removePlayersFromTeam(
Expand Down
22 changes: 16 additions & 6 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"common_next_title": "Next",
"common_yes_title": "Yes",
"common_no_title": "No",
"common_runs_dot_title": " Runs.",
"common_wickets_dot_title": " Wickets.",
"common_wicket_taken_title": " Wicket taken",
"common_not_specified_title": "Not Specified",
"common_obscure_phone_number_text": "{countryCode} ***** ***{lastDigits}",
Expand Down Expand Up @@ -258,6 +260,7 @@
"score_board_match_complete_title": "Match Complete",
"score_board_end_match_title": "End Match",
"score_board_start_next_inning_title": "Start Next Inning",
"score_board_end_inning_title": "End Inning",
"score_board_current_team_title": "Current Team",
"score_board_team_title": "Team",
"score_board_r_title": "R",
Expand All @@ -266,7 +269,16 @@
"score_board_won_by_title": " Won By ",
"score_board_select_player_title": "Select Player",
"score_board_select_title": "select",
"score_board_choose_batsman_title": "choose Batsman",
"score_board_choose_batsman_title": "choose Batsman at position {pos}",
"@score_board_choose_bowler_for_over_title": {
"description": "choose Batsman at position {pos}",
"placeholders": {
"pos": {
"type": "int"
}
}
},
"score_board_choose_opening_batsmen_title": "choose opening Batsmen",
"score_board_choose_bowler_for_over_title": "choose Bowler for over {over}",
"@score_board_choose_bowler_for_over_title": {
"description": "choose Bowler for over {over}",
Expand All @@ -280,23 +292,21 @@
"score_board_injured_tag_title": "Injured",
"score_board_who_on_strike_title": "Who's on Strike?",
"score_board_who_got_out_title": "Who got out",
"score_board_runs_dot_title": " Runs.",
"score_board_wickets_dot_title": " Wickets.",
"score_board_end_of_over_title": "End Of Over ",
"score_board_start_next_over_title": "Start Next Over",
"score_board_batsman_title": "batsMan",
"score_board_bowler_title": "bowler",
"score_board_change_striker_title": "Change striker",
"score_board_change_striker_title": "Change Striker",
"score_board_add_substitute_title": "Add substitute",
"score_board_pause_scoring_title": "Pause scoring",
"score_board_by_title": " by ",
"score_board_can_undo_till_running_over_title": "Undo is only allowed till running over",
"score_board_undo_last_ball_title": "Undo Last Ball",
"score_board_undo_last_ball_description_text": "are you sure you want to undo last ball?",
"score_board_pause_scoring_title": "Pause Scoring",
"score_board_penalty_run_title": "Penalty Run",
"score_board_continue_with_injured_player_title": "Continue With Injured Player",
"score_board_pause_title": "Pause",
"score_board_power_play_title": "Power-Play ",
"score_board_more_options_title": "More Options",
"score_board_pause_scoring_description_text": "are you sure you want to pause scoring?",
"score_board_need_run_text": "Need {run} in {ball}",
"@score_board_need_run_text": {
Expand Down
37 changes: 37 additions & 0 deletions khelo/lib/components/won_by_message_text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/cupertino.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

class WonByMessageText extends StatelessWidget {
final String teamName;
final int difference;
final String trailingText;

const WonByMessageText({
super.key,
required this.teamName,
required this.difference,
required this.trailingText,
});

@override
Widget build(BuildContext context) {
return Text.rich(TextSpan(
text: teamName,
style:
AppTextStyle.header4.copyWith(color: context.colorScheme.primary),
children: [
TextSpan(
text: context.l10n.score_board_won_by_title,
style: AppTextStyle.subtitle2
.copyWith(color: context.colorScheme.textSecondary)),
TextSpan(
text: "$difference",
),
TextSpan(
text: trailingText,
),
]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:data/api/ball_score/ball_score_model.dart';

extension BallScoreModelBoolean on BallScoreModel? {
bool? isLegalDelivery() {
if (this == null) {
return null;
}
return this!.extras_type != ExtrasType.penaltyRun &&
this!.extras_type != ExtrasType.noBall &&
this!.extras_type != ExtrasType.wide &&
this!.wicket_type != WicketType.timedOut &&
this!.wicket_type != WicketType.retired &&
this!.wicket_type != WicketType.retiredHurt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:data/api/match/match_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';

extension MatchModelString on MatchModel {
({String teamName, int difference, String wonByText})? getWinnerSummary(
BuildContext context) {
if (match_status != MatchStatus.finish) {
return null;
}

final firstTeam = toss_decision == TossDecision.bat
? teams.firstWhere((element) => element.team.id == toss_winner_id)
: teams.firstWhere((element) => element.team.id != toss_winner_id);
final secondTeam =
teams.firstWhere((element) => element.team.id != firstTeam.team.id);

if (firstTeam.run! > secondTeam.run!) {
// first batting team won
final teamName = firstTeam.team.name;

final runDifference = firstTeam.run! - secondTeam.run!;

return (
teamName: teamName,
difference: runDifference,
wonByText: context.l10n.common_runs_dot_title,
);
} else {
// second batting team won
final teamName = secondTeam.team.name;

final wicketDifference =
secondTeam.squad.length - (firstTeam.wicket ?? 0);

return (
teamName: teamName,
difference: wicketDifference,
wonByText: context.l10n.common_wickets_dot_title,
);
}
}
}
2 changes: 1 addition & 1 deletion khelo/lib/ui/flow/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class HomeScreen extends ConsumerWidget {
.copyWith(color: context.colorScheme.textPrimary, fontSize: 24),
children: [
TextSpan(
text: " (${((team.over ?? 1) - 1).toStringAsFixed(1)})",
text: " (${team.over ?? 0})",
style: AppTextStyle.body1
.copyWith(color: context.colorScheme.textPrimary))
])),
Expand Down
2 changes: 1 addition & 1 deletion khelo/lib/ui/flow/home/home_view_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ part of 'home_view_model.dart';
T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');

/// @nodoc
mixin _$HomeViewState {
Expand Down
Loading

0 comments on commit 4b371a0

Please sign in to comment.