From 98fa046ee99e9165f593266c5befdded95196353 Mon Sep 17 00:00:00 2001 From: sidhdhi canopas <122426509+cp-sidhdhi-p@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:46:13 +0530 Subject: [PATCH] Refactor score board (#7) * refactor and implement injured player flow * empty view in home screen running match * Fix score board state * pass value instead of state * remove force unwrap --------- Co-authored-by: cp-sneha-s --- data/lib/api/ball_score/ball_score_model.dart | 1 + .../ball_score/ball_score_model.freezed.dart | 24 +- .../api/ball_score/ball_score_model.g.dart | 2 + data/lib/service/team/team_service.dart | 6 +- khelo/assets/locales/app_en.arb | 24 +- khelo/lib/components/won_by_message_text.dart | 37 ++ .../ball_score_model_extension.dart | 15 + .../match_model_extension.dart | 43 ++ khelo/lib/ui/flow/home/home_screen.dart | 49 +- .../ui/flow/home/home_view_model.freezed.dart | 2 +- .../matches/add_match/add_match_screen.dart | 45 +- .../add_match_view_model.freezed.dart | 197 +++--- .../search_user_view_model.freezed.dart | 73 ++- .../ui/flow/matches/match_list_screen.dart | 81 +-- .../match_list_view_model.freezed.dart | 55 +- .../add_toss_detail_view_model.freezed.dart | 2 +- .../components/confirm_action_dialog.dart | 81 +++ .../components/inning_complete_dialog.dart | 30 +- .../components/match_complete_dialog.dart | 106 ++-- .../components/more_option_dialog.dart | 116 ++++ .../components/over_complete_dialog.dart | 2 +- .../components/score_display_view.dart | 323 ++++++++++ .../components/select_player_sheet.dart | 592 ++++++++++-------- .../flow/score_board/score_board_screen.dart | 550 ++++------------ .../score_board/score_board_view_model.dart | 476 ++++++++------ .../score_board_view_model.freezed.dart | 2 +- .../edit_profile_view_model.freezed.dart | 58 +- ...phone_verification_view_model.freezed.dart | 96 +-- ...sign_in_with_phone_view_model.freezed.dart | 76 +-- .../match_detail_stat_screen.dart | 4 +- .../match_detail_stat_view_model.freezed.dart | 74 +-- .../user_match/user_match_list_screen.dart | 90 +-- .../user_match_list_view_model.freezed.dart | 2 +- .../team/add_team/add_team_view_model.dart | 4 +- .../add_team/add_team_view_model.freezed.dart | 233 ++++--- .../add_team_member_screen.dart | 2 +- .../add_team_member_view_model.dart | 6 +- .../add_team_member_view_model.freezed.dart | 32 +- .../components/team_detail_match_content.dart | 5 +- .../team_detail_member_content.dart | 3 +- .../components/team_detail_stat_content.dart | 9 +- .../flow/team/detail/team_detail_screen.dart | 122 ++-- .../team_detail_view_model.freezed.dart | 2 +- .../search_team_view_model.freezed.dart | 88 +-- 44 files changed, 2130 insertions(+), 1710 deletions(-) create mode 100644 khelo/lib/components/won_by_message_text.dart create mode 100644 khelo/lib/domain/extensions/data_model_extensions/ball_score_model_extension.dart create mode 100644 khelo/lib/domain/extensions/data_model_extensions/match_model_extension.dart create mode 100644 khelo/lib/ui/flow/score_board/components/confirm_action_dialog.dart create mode 100644 khelo/lib/ui/flow/score_board/components/more_option_dialog.dart create mode 100644 khelo/lib/ui/flow/score_board/components/score_display_view.dart diff --git a/data/lib/api/ball_score/ball_score_model.dart b/data/lib/api/ball_score/ball_score_model.dart index 297cba08..21096bb6 100644 --- a/data/lib/api/ball_score/ball_score_model.dart +++ b/data/lib/api/ball_score/ball_score_model.dart @@ -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, diff --git a/data/lib/api/ball_score/ball_score_model.freezed.dart b/data/lib/api/ball_score/ball_score_model.freezed.dart index a60c98b4..6f06fba6 100644 --- a/data/lib/api/ball_score/ball_score_model.freezed.dart +++ b/data/lib/api/ball_score/ball_score_model.freezed.dart @@ -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; @@ -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, @@ -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, @@ -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 @@ -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, @@ -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, @@ -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 @@ -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, @@ -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; @@ -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 @@ -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) || @@ -380,6 +398,7 @@ class _$BallScoreModelImpl implements _BallScoreModel { ball_number, bowler_id, batsman_id, + non_striker_id, runs_scored, extras_type, extras_awarded, @@ -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, @@ -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; diff --git a/data/lib/api/ball_score/ball_score_model.g.dart b/data/lib/api/ball_score/ball_score_model.g.dart index e1ab442e..c2d5a039 100644 --- a/data/lib/api/ball_score/ball_score_model.g.dart +++ b/data/lib/api/ball_score/ball_score_model.g.dart @@ -14,6 +14,7 @@ _$BallScoreModelImpl _$$BallScoreModelImplFromJson(Map json) => ball_number: json['ball_number'] as int, bowler_id: json['bowler_id'] as String, batsman_id: json['batsman_id'] as String, + non_striker_id: json['non_striker_id'] as String, runs_scored: json['runs_scored'] as int?, extras_type: $enumDecodeNullable(_$ExtrasTypeEnumMap, json['extras_type']), @@ -36,6 +37,7 @@ Map _$$BallScoreModelImplToJson( 'ball_number': instance.ball_number, 'bowler_id': instance.bowler_id, 'batsman_id': instance.batsman_id, + 'non_striker_id': instance.non_striker_id, 'runs_scored': instance.runs_scored, 'extras_type': _$ExtrasTypeEnumMap[instance.extras_type], 'extras_awarded': instance.extras_awarded, diff --git a/data/lib/service/team/team_service.dart b/data/lib/service/team/team_service.dart index 78826758..89e32710 100644 --- a/data/lib/service/team/team_service.dart +++ b/data/lib/service/team/team_service.dart @@ -27,8 +27,7 @@ class TeamService { TeamService(this._currentUserId, this._firestore, this._userService); Future 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)); @@ -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 removePlayersFromTeam( diff --git a/khelo/assets/locales/app_en.arb b/khelo/assets/locales/app_en.arb index 48db90c9..94862381 100644 --- a/khelo/assets/locales/app_en.arb +++ b/khelo/assets/locales/app_en.arb @@ -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}", @@ -73,6 +75,8 @@ "edit_profile_save_title": "SAVE", "home_screen_title": "Home", + "home_screen_no_matches_title": "No matches are running currently", + "home_screen_no_matches_description_text": "Running matches will be shown here, Stay tuned for some intense matches.", "image_picker_choose_option_title": "Choose an option.", "image_picker_crop_image_title": "Crop Image", @@ -258,6 +262,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", @@ -266,7 +271,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}", @@ -280,23 +294,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": { diff --git a/khelo/lib/components/won_by_message_text.dart b/khelo/lib/components/won_by_message_text.dart new file mode 100644 index 00000000..c8ecc213 --- /dev/null +++ b/khelo/lib/components/won_by_message_text.dart @@ -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, + ), + ])); + } +} \ No newline at end of file diff --git a/khelo/lib/domain/extensions/data_model_extensions/ball_score_model_extension.dart b/khelo/lib/domain/extensions/data_model_extensions/ball_score_model_extension.dart new file mode 100644 index 00000000..2cbc47e4 --- /dev/null +++ b/khelo/lib/domain/extensions/data_model_extensions/ball_score_model_extension.dart @@ -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; + } +} \ No newline at end of file diff --git a/khelo/lib/domain/extensions/data_model_extensions/match_model_extension.dart b/khelo/lib/domain/extensions/data_model_extensions/match_model_extension.dart new file mode 100644 index 00000000..e1aa42ac --- /dev/null +++ b/khelo/lib/domain/extensions/data_model_extensions/match_model_extension.dart @@ -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 ?? 0) > (secondTeam.run ?? 0)) { + // first batting team won + final teamName = firstTeam.team.name; + + final runDifference = (firstTeam.run ?? 0) - (secondTeam.run ?? 0); + + 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, + ); + } + } +} \ No newline at end of file diff --git a/khelo/lib/ui/flow/home/home_screen.dart b/khelo/lib/ui/flow/home/home_screen.dart index 3cc43585..dd08a074 100644 --- a/khelo/lib/ui/flow/home/home_screen.dart +++ b/khelo/lib/ui/flow/home/home_screen.dart @@ -32,12 +32,16 @@ class HomeScreen extends ConsumerWidget { return const Center(child: AppProgressIndicator()); } - return ListView( - padding: context.mediaQueryPadding, - children: [ - _matchCardSlider(context, state), - ], - ); + if (state.matches.isNotEmpty) { + return ListView( + padding: context.mediaQueryPadding, + children: [ + _matchCardSlider(context, state), + ], + ); + } else { + return _emptyMatchView(context); + } } Widget _matchCardSlider( @@ -140,7 +144,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)) ])), @@ -172,4 +176,35 @@ class HomeScreen extends ConsumerWidget { ], ); } + + Widget _emptyMatchView(BuildContext context) { + return Container( + padding: const EdgeInsets.all(16), + margin: const EdgeInsets.all(16), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + border: Border.all(color: context.colorScheme.primary)), + child: IntrinsicHeight( + child: Column( + children: [ + Text( + context.l10n.home_screen_no_matches_title, + textAlign: TextAlign.center, + style: AppTextStyle.header2 + .copyWith(color: context.colorScheme.textPrimary), + ), + const SizedBox( + height: 8, + ), + Text( + context.l10n.home_screen_no_matches_description_text, + textAlign: TextAlign.center, + style: AppTextStyle.subtitle1 + .copyWith(color: context.colorScheme.textSecondary), + ), + ], + ), + ), + ); + } } diff --git a/khelo/lib/ui/flow/home/home_view_model.freezed.dart b/khelo/lib/ui/flow/home/home_view_model.freezed.dart index c2af0669..c492f9c9 100644 --- a/khelo/lib/ui/flow/home/home_view_model.freezed.dart +++ b/khelo/lib/ui/flow/home/home_view_model.freezed.dart @@ -12,7 +12,7 @@ part of 'home_view_model.dart'; T _$identity(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 { 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 6423111f..8eeab191 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 @@ -32,19 +32,19 @@ class AddMatchScreen extends ConsumerStatefulWidget { class _AddMatchScreenState extends ConsumerState { late AddMatchViewNotifier notifier; - void _observePushTossDetailScreen(BuildContext context, WidgetRef ref) { + void _observePushTossDetailScreen( + BuildContext context, + WidgetRef ref, + String? matchId, + ) { ref.listen( addMatchViewStateProvider.select((value) => value.pushTossDetailScreen), (previous, next) { if (next == true) { - AppRoute.addTossDetail( - matchId: ref.read(addMatchViewStateProvider.notifier).matchId ?? - "INVALID ID") + AppRoute.addTossDetail(matchId: ref.read(addMatchViewStateProvider.notifier).matchId ?? "INVALID ID") .pushReplacement(context); } else if (next == false) { - AppRoute.scoreBoard( - matchId: ref.read(addMatchViewStateProvider.notifier).matchId ?? - "INVALID ID") + AppRoute.scoreBoard(matchId: ref.read(addMatchViewStateProvider.notifier).matchId ?? "INVALID ID") .pushReplacement(context); } }); @@ -71,7 +71,7 @@ class _AddMatchScreenState extends ConsumerState { notifier = ref.watch(addMatchViewStateProvider.notifier); final state = ref.watch(addMatchViewStateProvider); - _observePushTossDetailScreen(context, ref); + _observePushTossDetailScreen(context, ref, notifier.matchId); _observePop(context, ref); return AppPage( @@ -80,8 +80,12 @@ class _AddMatchScreenState extends ConsumerState { : context.l10n.add_match_screen_title, actions: [ if (widget.matchId != null) - _deleteMatchButton(context, notifier, state), - _scheduleMatchButton(context, notifier, state), + _deleteMatchButton(context, onDelete: notifier.deleteMatch), + _scheduleMatchButton( + context, + isSaveBtnEnable: state.isSaveBtnEnable, + onSchedule: () => notifier.addMatch(), + ), ], body: Material( color: Colors.transparent, @@ -96,15 +100,15 @@ class _AddMatchScreenState extends ConsumerState { } Widget _scheduleMatchButton( - BuildContext context, - AddMatchViewNotifier notifier, - AddMatchViewState state, - ) { + BuildContext context, { + required bool isSaveBtnEnable, + required Function() onSchedule, + }) { return IconButton( - onPressed: state.isSaveBtnEnable ? () => notifier.addMatch() : null, + onPressed: isSaveBtnEnable ? onSchedule : null, icon: Icon( Icons.alarm, - color: state.isSaveBtnEnable + color: isSaveBtnEnable ? context.colorScheme.primary : context.colorScheme.textDisabled, ), @@ -112,14 +116,13 @@ class _AddMatchScreenState extends ConsumerState { } Widget _deleteMatchButton( - BuildContext context, - AddMatchViewNotifier notifier, - AddMatchViewState state, - ) { + BuildContext context, { + required Function() onDelete, + }) { return IconButton( onPressed: () => _showDeleteAlert( context, - onDelete: () => notifier.deleteMatch(), + onDelete: onDelete, ), icon: const Icon( Icons.delete_outline, diff --git a/khelo/lib/ui/flow/matches/add_match/add_match_view_model.freezed.dart b/khelo/lib/ui/flow/matches/add_match/add_match_view_model.freezed.dart index f32829b9..a546a6a4 100644 --- a/khelo/lib/ui/flow/matches/add_match/add_match_view_model.freezed.dart +++ b/khelo/lib/ui/flow/matches/add_match/add_match_view_model.freezed.dart @@ -12,7 +12,7 @@ part of 'add_match_view_model.dart'; T _$identity(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 _$AddMatchViewState { @@ -36,6 +36,9 @@ mixin _$AddMatchViewState { String? get teamAAdminId => throw _privateConstructorUsedError; String? get teamBAdminId => throw _privateConstructorUsedError; List get officials => throw _privateConstructorUsedError; + List? get firstPowerPlay => throw _privateConstructorUsedError; + List? get secondPowerPlay => throw _privateConstructorUsedError; + List? get thirdPowerPlay => throw _privateConstructorUsedError; PitchType get pitchType => throw _privateConstructorUsedError; MatchType get matchType => throw _privateConstructorUsedError; BallType get ballType => throw _privateConstructorUsedError; @@ -46,9 +49,6 @@ mixin _$AddMatchViewState { bool get isAddMatchInProgress => throw _privateConstructorUsedError; bool? get pushTossDetailScreen => throw _privateConstructorUsedError; bool? get pop => throw _privateConstructorUsedError; - List? get firstPowerPlay => throw _privateConstructorUsedError; - List? get secondPowerPlay => throw _privateConstructorUsedError; - List? get thirdPowerPlay => throw _privateConstructorUsedError; @JsonKey(ignore: true) $AddMatchViewStateCopyWith get copyWith => @@ -78,6 +78,9 @@ abstract class $AddMatchViewStateCopyWith<$Res> { String? teamAAdminId, String? teamBAdminId, List officials, + List? firstPowerPlay, + List? secondPowerPlay, + List? thirdPowerPlay, PitchType pitchType, MatchType matchType, BallType ballType, @@ -87,10 +90,7 @@ abstract class $AddMatchViewStateCopyWith<$Res> { bool isStartBtnEnable, bool isAddMatchInProgress, bool? pushTossDetailScreen, - bool? pop, - List? firstPowerPlay, - List? secondPowerPlay, - List? thirdPowerPlay}); + bool? pop}); $MatchModelCopyWith<$Res>? get match; $TeamModelCopyWith<$Res>? get teamA; @@ -126,6 +126,9 @@ class _$AddMatchViewStateCopyWithImpl<$Res, $Val extends AddMatchViewState> Object? teamAAdminId = freezed, Object? teamBAdminId = freezed, Object? officials = null, + Object? firstPowerPlay = freezed, + Object? secondPowerPlay = freezed, + Object? thirdPowerPlay = freezed, Object? pitchType = null, Object? matchType = null, Object? ballType = null, @@ -136,9 +139,6 @@ class _$AddMatchViewStateCopyWithImpl<$Res, $Val extends AddMatchViewState> Object? isAddMatchInProgress = null, Object? pushTossDetailScreen = freezed, Object? pop = freezed, - Object? firstPowerPlay = freezed, - Object? secondPowerPlay = freezed, - Object? thirdPowerPlay = freezed, }) { return _then(_value.copyWith( matchTime: null == matchTime @@ -202,6 +202,18 @@ class _$AddMatchViewStateCopyWithImpl<$Res, $Val extends AddMatchViewState> ? _value.officials : officials // ignore: cast_nullable_to_non_nullable as List, + firstPowerPlay: freezed == firstPowerPlay + ? _value.firstPowerPlay + : firstPowerPlay // ignore: cast_nullable_to_non_nullable + as List?, + secondPowerPlay: freezed == secondPowerPlay + ? _value.secondPowerPlay + : secondPowerPlay // ignore: cast_nullable_to_non_nullable + as List?, + thirdPowerPlay: freezed == thirdPowerPlay + ? _value.thirdPowerPlay + : thirdPowerPlay // ignore: cast_nullable_to_non_nullable + as List?, pitchType: null == pitchType ? _value.pitchType : pitchType // ignore: cast_nullable_to_non_nullable @@ -242,18 +254,6 @@ class _$AddMatchViewStateCopyWithImpl<$Res, $Val extends AddMatchViewState> ? _value.pop : pop // ignore: cast_nullable_to_non_nullable as bool?, - firstPowerPlay: freezed == firstPowerPlay - ? _value.firstPowerPlay - : firstPowerPlay // ignore: cast_nullable_to_non_nullable - as List?, - secondPowerPlay: freezed == secondPowerPlay - ? _value.secondPowerPlay - : secondPowerPlay // ignore: cast_nullable_to_non_nullable - as List?, - thirdPowerPlay: freezed == thirdPowerPlay - ? _value.thirdPowerPlay - : thirdPowerPlay // ignore: cast_nullable_to_non_nullable - as List?, ) as $Val); } @@ -319,6 +319,9 @@ abstract class _$$AddMatchViewStateImplCopyWith<$Res> String? teamAAdminId, String? teamBAdminId, List officials, + List? firstPowerPlay, + List? secondPowerPlay, + List? thirdPowerPlay, PitchType pitchType, MatchType matchType, BallType ballType, @@ -328,10 +331,7 @@ abstract class _$$AddMatchViewStateImplCopyWith<$Res> bool isStartBtnEnable, bool isAddMatchInProgress, bool? pushTossDetailScreen, - bool? pop, - List? firstPowerPlay, - List? secondPowerPlay, - List? thirdPowerPlay}); + bool? pop}); @override $MatchModelCopyWith<$Res>? get match; @@ -368,6 +368,9 @@ class __$$AddMatchViewStateImplCopyWithImpl<$Res> Object? teamAAdminId = freezed, Object? teamBAdminId = freezed, Object? officials = null, + Object? firstPowerPlay = freezed, + Object? secondPowerPlay = freezed, + Object? thirdPowerPlay = freezed, Object? pitchType = null, Object? matchType = null, Object? ballType = null, @@ -378,9 +381,6 @@ class __$$AddMatchViewStateImplCopyWithImpl<$Res> Object? isAddMatchInProgress = null, Object? pushTossDetailScreen = freezed, Object? pop = freezed, - Object? firstPowerPlay = freezed, - Object? secondPowerPlay = freezed, - Object? thirdPowerPlay = freezed, }) { return _then(_$AddMatchViewStateImpl( matchTime: null == matchTime @@ -444,6 +444,18 @@ class __$$AddMatchViewStateImplCopyWithImpl<$Res> ? _value._officials : officials // ignore: cast_nullable_to_non_nullable as List, + firstPowerPlay: freezed == firstPowerPlay + ? _value._firstPowerPlay + : firstPowerPlay // ignore: cast_nullable_to_non_nullable + as List?, + secondPowerPlay: freezed == secondPowerPlay + ? _value._secondPowerPlay + : secondPowerPlay // ignore: cast_nullable_to_non_nullable + as List?, + thirdPowerPlay: freezed == thirdPowerPlay + ? _value._thirdPowerPlay + : thirdPowerPlay // ignore: cast_nullable_to_non_nullable + as List?, pitchType: null == pitchType ? _value.pitchType : pitchType // ignore: cast_nullable_to_non_nullable @@ -484,18 +496,6 @@ class __$$AddMatchViewStateImplCopyWithImpl<$Res> ? _value.pop : pop // ignore: cast_nullable_to_non_nullable as bool?, - firstPowerPlay: freezed == firstPowerPlay - ? _value._firstPowerPlay - : firstPowerPlay // ignore: cast_nullable_to_non_nullable - as List?, - secondPowerPlay: freezed == secondPowerPlay - ? _value._secondPowerPlay - : secondPowerPlay // ignore: cast_nullable_to_non_nullable - as List?, - thirdPowerPlay: freezed == thirdPowerPlay - ? _value._thirdPowerPlay - : thirdPowerPlay // ignore: cast_nullable_to_non_nullable - as List?, )); } } @@ -520,6 +520,9 @@ class _$AddMatchViewStateImpl implements _AddMatchViewState { this.teamAAdminId, this.teamBAdminId, final List officials = const [], + final List? firstPowerPlay = const [], + final List? secondPowerPlay = const [], + final List? thirdPowerPlay = const [], this.pitchType = PitchType.rough, this.matchType = MatchType.limitedOvers, this.ballType = BallType.leather, @@ -529,10 +532,7 @@ class _$AddMatchViewStateImpl implements _AddMatchViewState { this.isStartBtnEnable = false, this.isAddMatchInProgress = false, this.pushTossDetailScreen = null, - this.pop = null, - final List? firstPowerPlay = const [], - final List? secondPowerPlay = const [], - final List? thirdPowerPlay = const []}) + this.pop = null}) : _squadA = squadA, _squadB = squadB, _officials = officials, @@ -595,36 +595,6 @@ class _$AddMatchViewStateImpl implements _AddMatchViewState { return EqualUnmodifiableListView(_officials); } - @override - @JsonKey() - final PitchType pitchType; - @override - @JsonKey() - final MatchType matchType; - @override - @JsonKey() - final BallType ballType; - @override - @JsonKey() - final bool loading; - @override - @JsonKey() - final bool isPowerPlayButtonEnable; - @override - @JsonKey() - final bool isSaveBtnEnable; - @override - @JsonKey() - final bool isStartBtnEnable; - @override - @JsonKey() - final bool isAddMatchInProgress; - @override - @JsonKey() - final bool? pushTossDetailScreen; - @override - @JsonKey() - final bool? pop; final List? _firstPowerPlay; @override @JsonKey() @@ -658,9 +628,40 @@ class _$AddMatchViewStateImpl implements _AddMatchViewState { return EqualUnmodifiableListView(value); } + @override + @JsonKey() + final PitchType pitchType; + @override + @JsonKey() + final MatchType matchType; + @override + @JsonKey() + final BallType ballType; + @override + @JsonKey() + final bool loading; + @override + @JsonKey() + final bool isPowerPlayButtonEnable; + @override + @JsonKey() + final bool isSaveBtnEnable; + @override + @JsonKey() + final bool isStartBtnEnable; + @override + @JsonKey() + final bool isAddMatchInProgress; + @override + @JsonKey() + final bool? pushTossDetailScreen; + @override + @JsonKey() + final bool? pop; + @override String toString() { - return 'AddMatchViewState(matchTime: $matchTime, totalOverController: $totalOverController, overPerBowlerController: $overPerBowlerController, cityController: $cityController, groundController: $groundController, error: $error, match: $match, teamA: $teamA, teamB: $teamB, squadA: $squadA, squadB: $squadB, teamACaptainId: $teamACaptainId, teamBCaptainId: $teamBCaptainId, teamAAdminId: $teamAAdminId, teamBAdminId: $teamBAdminId, officials: $officials, pitchType: $pitchType, matchType: $matchType, ballType: $ballType, loading: $loading, isPowerPlayButtonEnable: $isPowerPlayButtonEnable, isSaveBtnEnable: $isSaveBtnEnable, isStartBtnEnable: $isStartBtnEnable, isAddMatchInProgress: $isAddMatchInProgress, pushTossDetailScreen: $pushTossDetailScreen, pop: $pop, firstPowerPlay: $firstPowerPlay, secondPowerPlay: $secondPowerPlay, thirdPowerPlay: $thirdPowerPlay)'; + return 'AddMatchViewState(matchTime: $matchTime, totalOverController: $totalOverController, overPerBowlerController: $overPerBowlerController, cityController: $cityController, groundController: $groundController, error: $error, match: $match, teamA: $teamA, teamB: $teamB, squadA: $squadA, squadB: $squadB, teamACaptainId: $teamACaptainId, teamBCaptainId: $teamBCaptainId, teamAAdminId: $teamAAdminId, teamBAdminId: $teamBAdminId, officials: $officials, firstPowerPlay: $firstPowerPlay, secondPowerPlay: $secondPowerPlay, thirdPowerPlay: $thirdPowerPlay, pitchType: $pitchType, matchType: $matchType, ballType: $ballType, loading: $loading, isPowerPlayButtonEnable: $isPowerPlayButtonEnable, isSaveBtnEnable: $isSaveBtnEnable, isStartBtnEnable: $isStartBtnEnable, isAddMatchInProgress: $isAddMatchInProgress, pushTossDetailScreen: $pushTossDetailScreen, pop: $pop)'; } @override @@ -695,6 +696,12 @@ class _$AddMatchViewStateImpl implements _AddMatchViewState { other.teamBAdminId == teamBAdminId) && const DeepCollectionEquality() .equals(other._officials, _officials) && + const DeepCollectionEquality() + .equals(other._firstPowerPlay, _firstPowerPlay) && + const DeepCollectionEquality() + .equals(other._secondPowerPlay, _secondPowerPlay) && + const DeepCollectionEquality() + .equals(other._thirdPowerPlay, _thirdPowerPlay) && (identical(other.pitchType, pitchType) || other.pitchType == pitchType) && (identical(other.matchType, matchType) || @@ -713,13 +720,7 @@ class _$AddMatchViewStateImpl implements _AddMatchViewState { other.isAddMatchInProgress == isAddMatchInProgress) && (identical(other.pushTossDetailScreen, pushTossDetailScreen) || other.pushTossDetailScreen == pushTossDetailScreen) && - (identical(other.pop, pop) || other.pop == pop) && - const DeepCollectionEquality() - .equals(other._firstPowerPlay, _firstPowerPlay) && - const DeepCollectionEquality() - .equals(other._secondPowerPlay, _secondPowerPlay) && - const DeepCollectionEquality() - .equals(other._thirdPowerPlay, _thirdPowerPlay)); + (identical(other.pop, pop) || other.pop == pop)); } @override @@ -741,6 +742,9 @@ class _$AddMatchViewStateImpl implements _AddMatchViewState { teamAAdminId, teamBAdminId, const DeepCollectionEquality().hash(_officials), + const DeepCollectionEquality().hash(_firstPowerPlay), + const DeepCollectionEquality().hash(_secondPowerPlay), + const DeepCollectionEquality().hash(_thirdPowerPlay), pitchType, matchType, ballType, @@ -750,10 +754,7 @@ class _$AddMatchViewStateImpl implements _AddMatchViewState { isStartBtnEnable, isAddMatchInProgress, pushTossDetailScreen, - pop, - const DeepCollectionEquality().hash(_firstPowerPlay), - const DeepCollectionEquality().hash(_secondPowerPlay), - const DeepCollectionEquality().hash(_thirdPowerPlay) + pop ]); @JsonKey(ignore: true) @@ -782,6 +783,9 @@ abstract class _AddMatchViewState implements AddMatchViewState { final String? teamAAdminId, final String? teamBAdminId, final List officials, + final List? firstPowerPlay, + final List? secondPowerPlay, + final List? thirdPowerPlay, final PitchType pitchType, final MatchType matchType, final BallType ballType, @@ -791,10 +795,7 @@ abstract class _AddMatchViewState implements AddMatchViewState { final bool isStartBtnEnable, final bool isAddMatchInProgress, final bool? pushTossDetailScreen, - final bool? pop, - final List? firstPowerPlay, - final List? secondPowerPlay, - final List? thirdPowerPlay}) = _$AddMatchViewStateImpl; + final bool? pop}) = _$AddMatchViewStateImpl; @override DateTime get matchTime; @@ -829,6 +830,12 @@ abstract class _AddMatchViewState implements AddMatchViewState { @override List get officials; @override + List? get firstPowerPlay; + @override + List? get secondPowerPlay; + @override + List? get thirdPowerPlay; + @override PitchType get pitchType; @override MatchType get matchType; @@ -849,12 +856,6 @@ abstract class _AddMatchViewState implements AddMatchViewState { @override bool? get pop; @override - List? get firstPowerPlay; - @override - List? get secondPowerPlay; - @override - List? get thirdPowerPlay; - @override @JsonKey(ignore: true) _$$AddMatchViewStateImplCopyWith<_$AddMatchViewStateImpl> get copyWith => throw _privateConstructorUsedError; diff --git a/khelo/lib/ui/flow/matches/add_match/match_officials/components/search_user_view_model.freezed.dart b/khelo/lib/ui/flow/matches/add_match/match_officials/components/search_user_view_model.freezed.dart index 27865fe6..0acbb855 100644 --- a/khelo/lib/ui/flow/matches/add_match/match_officials/components/search_user_view_model.freezed.dart +++ b/khelo/lib/ui/flow/matches/add_match/match_officials/components/search_user_view_model.freezed.dart @@ -18,9 +18,9 @@ final _privateConstructorUsedError = UnsupportedError( mixin _$SearchUserViewState { TextEditingController get searchController => throw _privateConstructorUsedError; - List get searchedUsers => throw _privateConstructorUsedError; - UserModel? get selectedUser => throw _privateConstructorUsedError; Object? get error => throw _privateConstructorUsedError; + UserModel? get selectedUser => throw _privateConstructorUsedError; + List get searchedUsers => throw _privateConstructorUsedError; @JsonKey(ignore: true) $SearchUserViewStateCopyWith get copyWith => @@ -35,9 +35,9 @@ abstract class $SearchUserViewStateCopyWith<$Res> { @useResult $Res call( {TextEditingController searchController, - List searchedUsers, + Object? error, UserModel? selectedUser, - Object? error}); + List searchedUsers}); $UserModelCopyWith<$Res>? get selectedUser; } @@ -56,24 +56,24 @@ class _$SearchUserViewStateCopyWithImpl<$Res, $Val extends SearchUserViewState> @override $Res call({ Object? searchController = null, - Object? searchedUsers = null, - Object? selectedUser = freezed, Object? error = freezed, + Object? selectedUser = freezed, + Object? searchedUsers = null, }) { return _then(_value.copyWith( searchController: null == searchController ? _value.searchController : searchController // ignore: cast_nullable_to_non_nullable as TextEditingController, - searchedUsers: null == searchedUsers - ? _value.searchedUsers - : searchedUsers // ignore: cast_nullable_to_non_nullable - as List, + error: freezed == error ? _value.error : error, selectedUser: freezed == selectedUser ? _value.selectedUser : selectedUser // ignore: cast_nullable_to_non_nullable as UserModel?, - error: freezed == error ? _value.error : error, + searchedUsers: null == searchedUsers + ? _value.searchedUsers + : searchedUsers // ignore: cast_nullable_to_non_nullable + as List, ) as $Val); } @@ -100,9 +100,9 @@ abstract class _$$SearchUserViewStateImplCopyWith<$Res> @useResult $Res call( {TextEditingController searchController, - List searchedUsers, + Object? error, UserModel? selectedUser, - Object? error}); + List searchedUsers}); @override $UserModelCopyWith<$Res>? get selectedUser; @@ -120,24 +120,24 @@ class __$$SearchUserViewStateImplCopyWithImpl<$Res> @override $Res call({ Object? searchController = null, - Object? searchedUsers = null, - Object? selectedUser = freezed, Object? error = freezed, + Object? selectedUser = freezed, + Object? searchedUsers = null, }) { return _then(_$SearchUserViewStateImpl( searchController: null == searchController ? _value.searchController : searchController // ignore: cast_nullable_to_non_nullable as TextEditingController, - searchedUsers: null == searchedUsers - ? _value._searchedUsers - : searchedUsers // ignore: cast_nullable_to_non_nullable - as List, + error: freezed == error ? _value.error : error, selectedUser: freezed == selectedUser ? _value.selectedUser : selectedUser // ignore: cast_nullable_to_non_nullable as UserModel?, - error: freezed == error ? _value.error : error, + searchedUsers: null == searchedUsers + ? _value._searchedUsers + : searchedUsers // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -147,13 +147,17 @@ class __$$SearchUserViewStateImplCopyWithImpl<$Res> class _$SearchUserViewStateImpl implements _SearchUserViewState { const _$SearchUserViewStateImpl( {required this.searchController, - final List searchedUsers = const [], + this.error, this.selectedUser, - this.error}) + final List searchedUsers = const []}) : _searchedUsers = searchedUsers; @override final TextEditingController searchController; + @override + final Object? error; + @override + final UserModel? selectedUser; final List _searchedUsers; @override @JsonKey() @@ -163,14 +167,9 @@ class _$SearchUserViewStateImpl implements _SearchUserViewState { return EqualUnmodifiableListView(_searchedUsers); } - @override - final UserModel? selectedUser; - @override - final Object? error; - @override String toString() { - return 'SearchUserViewState(searchController: $searchController, searchedUsers: $searchedUsers, selectedUser: $selectedUser, error: $error)'; + return 'SearchUserViewState(searchController: $searchController, error: $error, selectedUser: $selectedUser, searchedUsers: $searchedUsers)'; } @override @@ -180,20 +179,20 @@ class _$SearchUserViewStateImpl implements _SearchUserViewState { other is _$SearchUserViewStateImpl && (identical(other.searchController, searchController) || other.searchController == searchController) && - const DeepCollectionEquality() - .equals(other._searchedUsers, _searchedUsers) && + const DeepCollectionEquality().equals(other.error, error) && (identical(other.selectedUser, selectedUser) || other.selectedUser == selectedUser) && - const DeepCollectionEquality().equals(other.error, error)); + const DeepCollectionEquality() + .equals(other._searchedUsers, _searchedUsers)); } @override int get hashCode => Object.hash( runtimeType, searchController, - const DeepCollectionEquality().hash(_searchedUsers), + const DeepCollectionEquality().hash(error), selectedUser, - const DeepCollectionEquality().hash(error)); + const DeepCollectionEquality().hash(_searchedUsers)); @JsonKey(ignore: true) @override @@ -206,18 +205,18 @@ class _$SearchUserViewStateImpl implements _SearchUserViewState { abstract class _SearchUserViewState implements SearchUserViewState { const factory _SearchUserViewState( {required final TextEditingController searchController, - final List searchedUsers, + final Object? error, final UserModel? selectedUser, - final Object? error}) = _$SearchUserViewStateImpl; + final List searchedUsers}) = _$SearchUserViewStateImpl; @override TextEditingController get searchController; @override - List get searchedUsers; + Object? get error; @override UserModel? get selectedUser; @override - Object? get error; + List get searchedUsers; @override @JsonKey(ignore: true) _$$SearchUserViewStateImplCopyWith<_$SearchUserViewStateImpl> get copyWith => diff --git a/khelo/lib/ui/flow/matches/match_list_screen.dart b/khelo/lib/ui/flow/matches/match_list_screen.dart index 6dc59101..ea29de73 100644 --- a/khelo/lib/ui/flow/matches/match_list_screen.dart +++ b/khelo/lib/ui/flow/matches/match_list_screen.dart @@ -2,7 +2,9 @@ import 'package:data/api/match/match_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:khelo/components/match_status_tag.dart'; +import 'package:khelo/components/won_by_message_text.dart'; import 'package:khelo/domain/extensions/context_extensions.dart'; +import 'package:khelo/domain/extensions/data_model_extensions/match_model_extension.dart'; import 'package:khelo/domain/extensions/enum_extensions.dart'; import 'package:khelo/domain/formatter/date_formatter.dart'; import 'package:khelo/ui/app_route.dart'; @@ -103,9 +105,7 @@ class MatchListScreen extends ConsumerWidget { children: [ _matchOtherDetail(context, match), _teamsAndStatusView(context, match), - if (match.match_status == MatchStatus.finish) ...[ - _winnerMessageText(context, match) - ] + _winnerMessageText(context, match) ], ), ); @@ -151,8 +151,13 @@ class MatchListScreen extends ConsumerWidget { if (match.match_status == MatchStatus.yetToStart) { AppRoute.addMatch(matchId: match.id).push(context); } else { - AppRoute.scoreBoard(matchId: match.id ?? "INVALID_ID") - .push(context); + if (match.toss_decision == null || match.toss_winner_id == null) { + AppRoute.addTossDetail(matchId: match.id ?? "INVALID_ID") + .push(context); + } else { + AppRoute.scoreBoard(matchId: match.id ?? "INVALID_ID") + .push(context); + } } }, icon: Icon( @@ -205,8 +210,6 @@ class MatchListScreen extends ConsumerWidget { required int totalOvers, required bool isRunning, }) { - final over = (team.over ?? 0) - 1; - return Text.rich(TextSpan( text: team.team.name, style: AppTextStyle.subtitle2.copyWith( @@ -226,7 +229,7 @@ class MatchListScreen extends ConsumerWidget { .copyWith(color: context.colorScheme.textPrimary), ), TextSpan( - text: " (${over.toStringAsFixed(1)}/$totalOvers)", + text: " (${team.over ?? 0}/$totalOvers)", style: AppTextStyle.body2 .copyWith(color: context.colorScheme.textSecondary), ), @@ -235,63 +238,15 @@ class MatchListScreen extends ConsumerWidget { } Widget _winnerMessageText(BuildContext context, MatchModel match) { - final firstTeam = match.toss_decision == TossDecision.bat - ? match.teams - .firstWhere((element) => element.team.id == match.toss_winner_id) - : match.teams - .firstWhere((element) => element.team.id != match.toss_winner_id); - final secondTeam = match.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 _messageText( - context, - teamName, - difference: runDifference, - trailingText: context.l10n.score_board_runs_dot_title, + final winSummary = match.getWinnerSummary(context); + if (match.match_status == MatchStatus.finish && winSummary != null) { + return WonByMessageText( + teamName: winSummary.teamName, + difference: winSummary.difference, + trailingText: winSummary.wonByText, ); } else { - // second batting team won - final teamName = secondTeam.team.name; - - final wicketDifference = - secondTeam.squad.length - (firstTeam.wicket ?? 0); - - return _messageText( - context, - teamName, - difference: wicketDifference, - trailingText: context.l10n.score_board_wickets_dot_title, - ); + return const SizedBox(); } } - - Widget _messageText( - BuildContext context, - String? teamName, { - required int difference, - required String trailingText, - }) { - return Text.rich(TextSpan( - text: "$teamName", - style: - AppTextStyle.subtitle2.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, - ), - ])); - } } diff --git a/khelo/lib/ui/flow/matches/match_list_view_model.freezed.dart b/khelo/lib/ui/flow/matches/match_list_view_model.freezed.dart index 47c4746e..8491c339 100644 --- a/khelo/lib/ui/flow/matches/match_list_view_model.freezed.dart +++ b/khelo/lib/ui/flow/matches/match_list_view_model.freezed.dart @@ -12,13 +12,13 @@ part of 'match_list_view_model.dart'; T _$identity(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 _$MatchListViewState { Object? get error => throw _privateConstructorUsedError; - bool get loading => throw _privateConstructorUsedError; List? get matches => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; @JsonKey(ignore: true) $MatchListViewStateCopyWith get copyWith => @@ -31,7 +31,7 @@ abstract class $MatchListViewStateCopyWith<$Res> { MatchListViewState value, $Res Function(MatchListViewState) then) = _$MatchListViewStateCopyWithImpl<$Res, MatchListViewState>; @useResult - $Res call({Object? error, bool loading, List? matches}); + $Res call({Object? error, List? matches, bool loading}); } /// @nodoc @@ -48,19 +48,19 @@ class _$MatchListViewStateCopyWithImpl<$Res, $Val extends MatchListViewState> @override $Res call({ Object? error = freezed, - Object? loading = null, Object? matches = freezed, + Object? loading = null, }) { return _then(_value.copyWith( error: freezed == error ? _value.error : error, - loading: null == loading - ? _value.loading - : loading // ignore: cast_nullable_to_non_nullable - as bool, matches: freezed == matches ? _value.matches : matches // ignore: cast_nullable_to_non_nullable as List?, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, ) as $Val); } } @@ -73,7 +73,7 @@ abstract class _$$MatchListViewStateImplCopyWith<$Res> __$$MatchListViewStateImplCopyWithImpl<$Res>; @override @useResult - $Res call({Object? error, bool loading, List? matches}); + $Res call({Object? error, List? matches, bool loading}); } /// @nodoc @@ -88,19 +88,19 @@ class __$$MatchListViewStateImplCopyWithImpl<$Res> @override $Res call({ Object? error = freezed, - Object? loading = null, Object? matches = freezed, + Object? loading = null, }) { return _then(_$MatchListViewStateImpl( error: freezed == error ? _value.error : error, - loading: null == loading - ? _value.loading - : loading // ignore: cast_nullable_to_non_nullable - as bool, matches: freezed == matches ? _value._matches : matches // ignore: cast_nullable_to_non_nullable as List?, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, )); } } @@ -109,14 +109,11 @@ class __$$MatchListViewStateImplCopyWithImpl<$Res> class _$MatchListViewStateImpl implements _MatchListViewState { const _$MatchListViewStateImpl( - {this.error, this.loading = false, final List? matches}) + {this.error, final List? matches, this.loading = false}) : _matches = matches; @override final Object? error; - @override - @JsonKey() - final bool loading; final List? _matches; @override List? get matches { @@ -127,9 +124,13 @@ class _$MatchListViewStateImpl implements _MatchListViewState { return EqualUnmodifiableListView(value); } + @override + @JsonKey() + final bool loading; + @override String toString() { - return 'MatchListViewState(error: $error, loading: $loading, matches: $matches)'; + return 'MatchListViewState(error: $error, matches: $matches, loading: $loading)'; } @override @@ -138,16 +139,16 @@ class _$MatchListViewStateImpl implements _MatchListViewState { (other.runtimeType == runtimeType && other is _$MatchListViewStateImpl && const DeepCollectionEquality().equals(other.error, error) && - (identical(other.loading, loading) || other.loading == loading) && - const DeepCollectionEquality().equals(other._matches, _matches)); + const DeepCollectionEquality().equals(other._matches, _matches) && + (identical(other.loading, loading) || other.loading == loading)); } @override int get hashCode => Object.hash( runtimeType, const DeepCollectionEquality().hash(error), - loading, - const DeepCollectionEquality().hash(_matches)); + const DeepCollectionEquality().hash(_matches), + loading); @JsonKey(ignore: true) @override @@ -160,16 +161,16 @@ class _$MatchListViewStateImpl implements _MatchListViewState { abstract class _MatchListViewState implements MatchListViewState { const factory _MatchListViewState( {final Object? error, - final bool loading, - final List? matches}) = _$MatchListViewStateImpl; + final List? matches, + final bool loading}) = _$MatchListViewStateImpl; @override Object? get error; @override - bool get loading; - @override List? get matches; @override + bool get loading; + @override @JsonKey(ignore: true) _$$MatchListViewStateImplCopyWith<_$MatchListViewStateImpl> get copyWith => throw _privateConstructorUsedError; diff --git a/khelo/lib/ui/flow/score_board/add_toss_detail/add_toss_detail_view_model.freezed.dart b/khelo/lib/ui/flow/score_board/add_toss_detail/add_toss_detail_view_model.freezed.dart index e26c1a1f..17442b59 100644 --- a/khelo/lib/ui/flow/score_board/add_toss_detail/add_toss_detail_view_model.freezed.dart +++ b/khelo/lib/ui/flow/score_board/add_toss_detail/add_toss_detail_view_model.freezed.dart @@ -12,7 +12,7 @@ part of 'add_toss_detail_view_model.dart'; T _$identity(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 _$AddTossDetailState { diff --git a/khelo/lib/ui/flow/score_board/components/confirm_action_dialog.dart b/khelo/lib/ui/flow/score_board/components/confirm_action_dialog.dart new file mode 100644 index 00000000..2cb8495c --- /dev/null +++ b/khelo/lib/ui/flow/score_board/components/confirm_action_dialog.dart @@ -0,0 +1,81 @@ +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.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 ConfirmActionDialog extends StatelessWidget { + static Future show( + BuildContext context, { + required String title, + required String description, + required String primaryButtonText, + final String? secondaryButtonText, + required Function() onConfirmation, + }) { + return showAdaptiveDialog( + context: context, + builder: (context) { + return ConfirmActionDialog( + title: title, + description: description, + primaryButtonText: primaryButtonText, + secondaryButtonText: secondaryButtonText, + onConfirmation: onConfirmation, + ); + }, + ); + } + + final String title; + final String description; + final String primaryButtonText; + final String? secondaryButtonText; + final Function() onConfirmation; + + const ConfirmActionDialog({ + super.key, + required this.title, + required this.description, + required this.primaryButtonText, + this.secondaryButtonText, + required this.onConfirmation, + }); + + @override + Widget build(BuildContext context) { + return AlertDialog.adaptive( + title: Text( + title, + style: AppTextStyle.header4 + .copyWith(color: context.colorScheme.textPrimary), + ), + content: Text( + description, + style: AppTextStyle.subtitle2 + .copyWith(color: context.colorScheme.textPrimary), + ), + actions: [ + TextButton( + onPressed: context.pop, + child: Text( + secondaryButtonText ?? context.l10n.common_cancel_title, + style: AppTextStyle.button + .copyWith(color: context.colorScheme.textSecondary), + ), + ), + TextButton( + onPressed: () { + context.pop(); + onConfirmation(); + }, + child: Text( + primaryButtonText, + style: + AppTextStyle.button.copyWith(color: context.colorScheme.alert), + ), + ), + ], + ); + } +} \ No newline at end of file diff --git a/khelo/lib/ui/flow/score_board/components/inning_complete_dialog.dart b/khelo/lib/ui/flow/score_board/components/inning_complete_dialog.dart index ef8c11cd..fe9e300d 100644 --- a/khelo/lib/ui/flow/score_board/components/inning_complete_dialog.dart +++ b/khelo/lib/ui/flow/score_board/components/inning_complete_dialog.dart @@ -8,21 +8,28 @@ import 'package:style/extensions/context_extensions.dart'; import 'package:style/text/app_text_style.dart'; class InningCompleteDialog extends ConsumerWidget { - static Future show(BuildContext context) { + static Future show( + BuildContext context, { + bool showUndoButton = true, + }) { return showDialog( barrierDismissible: false, context: context, builder: (context) { - return const InningCompleteDialog(); + return InningCompleteDialog( + showUndoButton: showUndoButton, + ); }, ); } - const InningCompleteDialog({super.key}); + final bool showUndoButton; + + const InningCompleteDialog({super.key, required this.showUndoButton}); @override Widget build(BuildContext context, WidgetRef ref) { - final state = ref.read(scoreBoardStateProvider); + final state = ref.watch(scoreBoardStateProvider); return AlertDialog( backgroundColor: context.colorScheme.containerLowOnSurface, @@ -34,11 +41,13 @@ class InningCompleteDialog extends ConsumerWidget { content: _inningContent(context, state), actionsOverflowButtonSpacing: 8, actions: [ - PrimaryButton( - expanded: false, - context.l10n.score_board_undo_last_ball_title, - onPressed: () => context.pop(false), - ), + if (showUndoButton) ...[ + PrimaryButton( + context.l10n.score_board_undo_last_ball_title, + expanded: false, + onPressed: () => context.pop(false), + ), + ], PrimaryButton( context.l10n.score_board_start_next_inning_title, expanded: false, @@ -99,7 +108,8 @@ class InningCompleteDialog extends ConsumerWidget { } String _getOverCount(ScoreBoardViewState state) { - return "${state.overCount - 1}.${state.ballCount}"; + return state.currentInning?.overs?.toString() ?? + "${state.overCount - 1}.${state.ballCount}"; } Widget _subTitleText( diff --git a/khelo/lib/ui/flow/score_board/components/match_complete_dialog.dart b/khelo/lib/ui/flow/score_board/components/match_complete_dialog.dart index 8cba6c85..2449d15d 100644 --- a/khelo/lib/ui/flow/score_board/components/match_complete_dialog.dart +++ b/khelo/lib/ui/flow/score_board/components/match_complete_dialog.dart @@ -2,30 +2,40 @@ import 'package:data/api/match/match_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; +import 'package:khelo/components/won_by_message_text.dart'; import 'package:khelo/domain/extensions/context_extensions.dart'; +import 'package:khelo/domain/extensions/data_model_extensions/match_model_extension.dart'; import 'package:khelo/ui/flow/score_board/score_board_view_model.dart'; import 'package:style/button/primary_button.dart'; import 'package:style/extensions/context_extensions.dart'; import 'package:style/text/app_text_style.dart'; class MatchCompleteDialog extends ConsumerWidget { - static Future show(BuildContext context) { + static Future show( + BuildContext context, { + bool showUndoButton = true, + }) { return showDialog( barrierDismissible: false, context: context, builder: (context) { - return const MatchCompleteDialog(); + return MatchCompleteDialog( + showUndoButton: showUndoButton, + ); }, ); } - const MatchCompleteDialog({super.key}); + final bool showUndoButton; + + const MatchCompleteDialog({super.key, required this.showUndoButton}); @override Widget build(BuildContext context, WidgetRef ref) { - final state = ref.read(scoreBoardStateProvider); + final state = ref.watch(scoreBoardStateProvider); + return AlertDialog( - backgroundColor: context.colorScheme.containerLowOnSurface, + backgroundColor: context.colorScheme.surface, title: Text( context.l10n.score_board_match_complete_title, style: AppTextStyle.subtitle1 @@ -34,11 +44,13 @@ class MatchCompleteDialog extends ConsumerWidget { content: _matchContent(context, state), actionsOverflowButtonSpacing: 8, actions: [ - PrimaryButton( - expanded: false, - context.l10n.score_board_undo_last_ball_title, - onPressed: () => context.pop(false), - ), + if (showUndoButton) ...[ + PrimaryButton( + context.l10n.score_board_undo_last_ball_title, + expanded: false, + onPressed: () => context.pop(false), + ), + ], PrimaryButton( context.l10n.score_board_end_match_title, expanded: false, @@ -53,7 +65,7 @@ class MatchCompleteDialog extends ConsumerWidget { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - _winnerMessageText(context, state), + _winnerMessageText(context, state.match), const SizedBox( height: 16, ), @@ -92,7 +104,10 @@ class MatchCompleteDialog extends ConsumerWidget { } TableRow _teamMatchScores( - BuildContext context, ScoreBoardViewState state, MatchTeamModel team) { + BuildContext context, + ScoreBoardViewState state, + MatchTeamModel team, + ) { final (run, wicket, overs) = _getTeamRunDetails(state, team.team.id ?? "INVALID ID"); return TableRow( @@ -126,65 +141,28 @@ class MatchCompleteDialog extends ConsumerWidget { ? state.currentInning : state.otherInning; - final inningOver = teamInning?.overs ?? 0; - - final ballCount = inningOver - inningOver.truncate(); - final over = inningOver - 1; - final overCount = over + ballCount; - return ( teamInning?.total_runs ?? 0, teamInning?.total_wickets ?? 0, - overCount + teamInning?.overs ?? 0 ); } - Widget _winnerMessageText(BuildContext context, ScoreBoardViewState state) { - final firstInning = state.otherInning; - final secondInning = state.currentInning; - - if (firstInning!.total_runs! > secondInning!.total_runs!) { - final teamName = state.match?.teams - .where((element) => element.team.id == firstInning.team_id) - .firstOrNull - ?.team - .name; - - final runDifference = firstInning.total_runs! - secondInning.total_runs!; - - return _messageText(context, teamName, runDifference, - context.l10n.score_board_runs_dot_title); + Widget _winnerMessageText(BuildContext context, MatchModel? match) { + if (match == null) { + return const SizedBox(); + } + final winSummary = match + .copyWith(match_status: MatchStatus.finish) + .getWinnerSummary(context); + if (winSummary != null) { + return WonByMessageText( + teamName: winSummary.teamName, + difference: winSummary.difference, + trailingText: winSummary.wonByText, + ); } else { - final team = state.match?.teams - .where((element) => element.team.id == secondInning.team_id) - .firstOrNull; - final teamName = team?.team.name; - - final wicketDifference = team!.squad.length - state.wicketCount; - - return _messageText(context, teamName, wicketDifference, - context.l10n.score_board_wickets_dot_title); + return const SizedBox(); } } - - Widget _messageText(BuildContext context, String? teamName, int difference, - String trailingText) { - return Text.rich(TextSpan( - text: "$teamName", - style: AppTextStyle.header4 - .copyWith(color: context.colorScheme.textPrimary), - children: [ - TextSpan( - text: context.l10n.score_board_won_by_title, - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textSecondary)), - TextSpan( - text: "$difference", - ), - TextSpan( - text: trailingText, - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textSecondary)), - ])); - } } diff --git a/khelo/lib/ui/flow/score_board/components/more_option_dialog.dart b/khelo/lib/ui/flow/score_board/components/more_option_dialog.dart new file mode 100644 index 00000000..b4f894e6 --- /dev/null +++ b/khelo/lib/ui/flow/score_board/components/more_option_dialog.dart @@ -0,0 +1,116 @@ +import 'package:flutter/material.dart'; +import 'package:go_router/go_router.dart'; +import 'package:khelo/domain/extensions/context_extensions.dart'; +import 'package:khelo/ui/flow/score_board/score_board_view_model.dart'; +import 'package:style/animations/on_tap_scale.dart'; +import 'package:style/extensions/context_extensions.dart'; +import 'package:style/text/app_text_style.dart'; + +class MoreOptionDialog extends StatefulWidget { + static Future show( + BuildContext context, { + required bool continueWithInjPlayer, + }) { + return showDialog( + barrierDismissible: false, + context: context, + builder: (context) { + return MoreOptionDialog( + continueWithInjPlayer: continueWithInjPlayer, + ); + }, + ); + } + + final bool continueWithInjPlayer; + + const MoreOptionDialog({ + super.key, + required this.continueWithInjPlayer, + }); + + @override + State createState() => _MoreOptionDialogState(); +} + +class _MoreOptionDialogState extends State { + bool isEnabled = false; + + @override + void initState() { + super.initState(); + isEnabled = widget.continueWithInjPlayer; + } + + @override + Widget build(BuildContext context) { + return AlertDialog( + backgroundColor: context.colorScheme.containerLowOnSurface, + title: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + context.l10n.score_board_more_options_title, + style: AppTextStyle.header2 + .copyWith(color: context.colorScheme.textPrimary), + ), + IconButton( + onPressed: () { + context.pop(( + option: MatchOption.continueWithInjuredPlayer, + contWithInjPlayer: isEnabled + )); + }, + icon: const Icon(Icons.close)), + ], + ), + content: _optionListContent(context), + actionsOverflowButtonSpacing: 8, + ); + } + + Widget _optionListContent(BuildContext context) { + return SingleChildScrollView( + child: Wrap( + runSpacing: 16, + children: [ + for (final option in MatchOption.values) ...[ + _optionCellView(context, option) + ], + ], + ), + ); + } + + Widget _optionCellView( + BuildContext context, + MatchOption option, + ) { + return OnTapScale( + onTap: () { + switch (option) { + case MatchOption.continueWithInjuredPlayer: + setState(() { + isEnabled = !isEnabled; + }); + default: + context.pop((option: option, contWithInjPlayer: isEnabled)); + } + }, + child: Row( + children: [ + Text( + option.getTitle(context), + style: AppTextStyle.subtitle1 + .copyWith(color: context.colorScheme.textPrimary, fontSize: 20), + ), + const Spacer(), + option == MatchOption.continueWithInjuredPlayer + ? Icon( + isEnabled ? Icons.check_box : Icons.check_box_outline_blank) + : const SizedBox(), + ], + ), + ); + } +} \ No newline at end of file diff --git a/khelo/lib/ui/flow/score_board/components/over_complete_dialog.dart b/khelo/lib/ui/flow/score_board/components/over_complete_dialog.dart index a99b905c..00741241 100644 --- a/khelo/lib/ui/flow/score_board/components/over_complete_dialog.dart +++ b/khelo/lib/ui/flow/score_board/components/over_complete_dialog.dart @@ -24,7 +24,7 @@ class OverCompleteDialog extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final state = ref.read(scoreBoardStateProvider); + final state = ref.watch(scoreBoardStateProvider); return AlertDialog( backgroundColor: context.colorScheme.containerLowOnSurface, diff --git a/khelo/lib/ui/flow/score_board/components/score_display_view.dart b/khelo/lib/ui/flow/score_board/components/score_display_view.dart new file mode 100644 index 00000000..70fd446f --- /dev/null +++ b/khelo/lib/ui/flow/score_board/components/score_display_view.dart @@ -0,0 +1,323 @@ +import 'package:data/api/ball_score/ball_score_model.dart'; +import 'package:data/api/innings/inning_model.dart'; +import 'package:data/api/match/match_model.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:khelo/domain/extensions/context_extensions.dart'; +import 'package:khelo/ui/flow/score_board/score_board_view_model.dart'; +import 'package:style/extensions/context_extensions.dart'; +import 'package:style/text/app_text_style.dart'; + +class ScoreDisplayView extends ConsumerWidget { + const ScoreDisplayView({super.key}); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final state = ref.watch(scoreBoardStateProvider); + + return Expanded( + child: ListView( + children: [ + _matchScoreView(context, state), + const SizedBox( + height: 24, + ), + _batsManDetailsView(context, state), + _bowlerAndBallDetailView(context, state), + ], + ), + ); + } + + Widget _matchScoreView( + BuildContext context, + ScoreBoardViewState state, + ) { + final currentOver = _getCurrentOver(state); + + return Stack( + children: [ + _powerPlayTag(context, state), + Center( + child: Wrap( + alignment: WrapAlignment.center, + direction: Axis.vertical, + children: [ + Text.rich( + textAlign: TextAlign.center, + TextSpan( + children: [ + TextSpan( + text: '${state.totalRuns}/${state.wicketCount}', + style: AppTextStyle.subtitle1.copyWith( + color: context.colorScheme.textPrimary, fontSize: 39), + ), + TextSpan( + text: '($currentOver/${state.match?.number_of_over})', + style: AppTextStyle.header4 + .copyWith(color: context.colorScheme.textSecondary), + ), + ], + ), + ), + _runNeededText(context, state), + ], + ), + ), + ], + ); + } + + Widget _powerPlayTag( + BuildContext context, + ScoreBoardViewState state, + ) { + final powerPlayText = _getPowerPlayText(context, state); + if (powerPlayText != null) { + return Container( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 2), + decoration: BoxDecoration( + color: context.colorScheme.primary, + borderRadius: + const BorderRadius.horizontal(right: Radius.circular(12))), + child: Text( + powerPlayText, + style: AppTextStyle.body1.copyWith( + color: context.colorScheme.textInversePrimary, + fontWeight: FontWeight.w500), + ), + ); + } else { + return const SizedBox(); + } + } + + String? _getPowerPlayText(BuildContext context, ScoreBoardViewState state) { + if (state.match?.power_play_overs1.contains(state.overCount) ?? false) { + return context.l10n.power_play_text(1); + } else if (state.match?.power_play_overs2.contains(state.overCount) ?? + false) { + return context.l10n.power_play_text(2); + } else if (state.match?.power_play_overs3.contains(state.overCount) ?? + false) { + return context.l10n.power_play_text(3); + } + return null; + } + + Widget _runNeededText( + BuildContext context, + ScoreBoardViewState state, + ) { + if (state.otherInning?.innings_status == InningStatus.finish) { + final requiredRun = ((state.otherInning?.total_runs ?? 0) + 1) - + (state.currentInning?.total_runs ?? 0); + final pendingOver = (state.match?.number_of_over ?? 0) - state.overCount; + final pendingBall = (pendingOver * 6) + (6 - state.ballCount); + return Text( + context.l10n.score_board_need_run_text( + requiredRun < 0 ? 0 : requiredRun, + pendingBall < 0 ? 0 : pendingBall), + textAlign: TextAlign.center, + style: + AppTextStyle.subtitle1.copyWith(color: context.colorScheme.warning), + ); + } else { + return const SizedBox(); + } + } + + String _getCurrentOver(ScoreBoardViewState state) { + return state.currentInning?.overs.toString() ?? + "${state.overCount - 1}.${state.ballCount}"; + } + + Widget _batsManDetailsView(BuildContext context, ScoreBoardViewState state) { + return Row( + children: [ + _batManCellView(context, state, state.batsMans?.firstOrNull), + _batManCellView(context, state, state.batsMans?.elementAtOrNull(1)), + ], + ); + } + + Widget _batManCellView( + BuildContext context, + ScoreBoardViewState state, + MatchPlayer? user, + ) { + bool isOnStrike = state.strikerId == user?.player.id; + final (run, ball) = + _getBatsManTotalRuns(state, user?.player.id ?? "INVALID ID"); + return Expanded( + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + alignment: Alignment.center, + decoration: BoxDecoration( + border: Border.all(color: context.colorScheme.outline)), + child: Row( + children: [ + Expanded( + child: Align( + alignment: Alignment.centerRight, + child: Icon( + Icons.sports_cricket, + color: isOnStrike + ? context.colorScheme.primary + : context.colorScheme.textDisabled, + ), + ), + ), + const SizedBox( + width: 16, + ), + Expanded( + flex: 2, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + user?.player.name ?? context.l10n.score_board_player_title, + style: AppTextStyle.header1 + .copyWith(color: context.colorScheme.textPrimary), + ), + Text( + "$run($ball)", + style: AppTextStyle.header4 + .copyWith(color: context.colorScheme.textSecondary), + ), + ], + ), + ) + ], + ), + ), + ); + } + + (int, int) _getBatsManTotalRuns(ScoreBoardViewState state, String batsManId) { + final scoresList = state.currentScoresList + .where((element) => element.batsman_id == batsManId); + + int totalRuns = scoresList + .where((element) => (element.extras_type == ExtrasType.noBall || + element.extras_type == null)) + .fold(0, (sum, element) => sum + (element.runs_scored ?? 0)); + + final batsManFacedBall = scoresList + .where((element) => (element.extras_type != ExtrasType.wide)) + .length; + + return (totalRuns, batsManFacedBall); + } + + Widget _bowlerAndBallDetailView( + BuildContext context, + ScoreBoardViewState state, + ) { + return Container( + width: double.infinity, + padding: const EdgeInsets.all(16), + color: context.colorScheme.secondaryVariant, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _bowlerNameView( + context, + state.bowler?.player.name ?? + context.l10n.score_board_player_title), + const SizedBox( + height: 16, + ), + _ballHistoryListView(context, state), + ], + ), + ); + } + + Widget _bowlerNameView(BuildContext context, String name) { + return Text.rich( + TextSpan( + children: [ + WidgetSpan( + child: Icon( + Icons.sports_baseball_outlined, + color: context.colorScheme.surface, + )), + TextSpan( + text: ' $name', + style: TextStyle( + fontWeight: FontWeight.bold, + color: context.colorScheme.textPrimary), + ), + ], + ), + ); + } + + Widget _ballHistoryListView(BuildContext context, ScoreBoardViewState state) { + return SingleChildScrollView( + reverse: true, + scrollDirection: Axis.horizontal, + child: Row( + children: [ + for (final ball in _getFilteredCurrentOverBall(state)) ...[ + _ballView(context, ball), + const SizedBox(width: 8) + ] + ], + ), + ); + } + + List _getFilteredCurrentOverBall(ScoreBoardViewState state) { + final list = state.currentScoresList + .where((element) => + element.over_number == state.overCount && + element.extras_type != ExtrasType.penaltyRun) + .toList(); + return list; + } + + Widget _ballView(BuildContext context, BallScoreModel ball) { + return Container( + height: 50, + width: 50, + alignment: Alignment.center, + padding: const EdgeInsets.all(8), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: context.colorScheme.containerLow, + border: Border.all(color: context.colorScheme.outline)), + child: Text(_getTextBasedOnBall(context, ball)), + ); + } + + String _getTextBasedOnBall(BuildContext context, BallScoreModel ball) { + if (ball.wicket_type != null) { + return context.l10n.score_board_wicket_short_text; + } else if (ball.extras_type != null) { + switch (ball.extras_type!) { + case ExtrasType.wide: + return context.l10n.score_board_wide_ball_short_text; + case ExtrasType.noBall: + return context.l10n.score_board_no_ball_short_text; + case ExtrasType.bye: + return context.l10n.score_board_run_sup_script_text( + "${ball.extras_awarded ?? 0}", + context.l10n.score_board_bye_short_text); + case ExtrasType.legBye: + return context.l10n.score_board_run_sup_script_text( + "${ball.extras_awarded ?? 0}", + context.l10n.score_board_leg_bye_short_text); + case ExtrasType.penaltyRun: + return "P"; + } + } else if (ball.wicket_type == null && ball.extras_type == null) { + return "${ball.runs_scored}"; + } else { + return ""; + } + } +} diff --git a/khelo/lib/ui/flow/score_board/components/select_player_sheet.dart b/khelo/lib/ui/flow/score_board/components/select_player_sheet.dart index 5da709fc..c63e58e5 100644 --- a/khelo/lib/ui/flow/score_board/components/select_player_sheet.dart +++ b/khelo/lib/ui/flow/score_board/components/select_player_sheet.dart @@ -1,4 +1,5 @@ import 'package:data/api/ball_score/ball_score_model.dart'; +import 'package:data/api/innings/inning_model.dart'; import 'package:data/api/match/match_model.dart'; import 'package:data/api/user/user_models.dart'; import 'package:flutter/material.dart'; @@ -16,7 +17,7 @@ class SelectPlayerSheet extends ConsumerStatefulWidget { static Future show( BuildContext context, { required PlayerSelectionType type, - List? excludedIds, + required bool continueWithInjPlayer, }) { return showModalBottomSheet( context: context, @@ -27,17 +28,21 @@ class SelectPlayerSheet extends ConsumerStatefulWidget { backgroundColor: context.colorScheme.surface, builder: (context) { return SelectPlayerSheet( - type: type, - excludedIds: excludedIds, + playerSelectionType: type, + continueWithInjPlayer: continueWithInjPlayer, ); }, ); } - final PlayerSelectionType type; - final List? excludedIds; + final PlayerSelectionType playerSelectionType; + final bool continueWithInjPlayer; - const SelectPlayerSheet({super.key, required this.type, this.excludedIds}); + const SelectPlayerSheet({ + super.key, + required this.playerSelectionType, + required this.continueWithInjPlayer, + }); @override ConsumerState createState() => _SelectPlayerSheetState(); @@ -47,6 +52,13 @@ class _SelectPlayerSheetState extends ConsumerState { MatchPlayer? batsMan1; MatchPlayer? batsMan2; MatchPlayer? bowler; + bool isEnabled = false; + + @override + void initState() { + super.initState(); + isEnabled = widget.continueWithInjPlayer; + } @override Widget build(BuildContext context) { @@ -54,9 +66,7 @@ class _SelectPlayerSheetState extends ConsumerState { return Padding( padding: context.mediaQueryPadding + - const EdgeInsets.symmetric( - horizontal: 16, - ), + const EdgeInsets.symmetric(horizontal: 16), child: SizedBox( height: context.mediaQuerySize.height * 0.8, child: _body(context, state), @@ -64,251 +74,95 @@ class _SelectPlayerSheetState extends ConsumerState { ); } - Widget _body(BuildContext context, ScoreBoardViewState state) { - if (widget.type == PlayerSelectionType.all || - widget.type == PlayerSelectionType.batsManAndBowler) { - return _allPlayerSelectionView(context, state); - } - return _specificPlayerSelectionView(context, state); - } + Widget _body( + BuildContext context, + ScoreBoardViewState state, + ) { + final List batsManList = + widget.playerSelectionType != PlayerSelectionType.bowler + ? _getFilteredList(state, type: PlayerSelectionType.batsMan) + : []; + final List bowlerList = + widget.playerSelectionType != PlayerSelectionType.batsMan + ? _getFilteredList(state, type: PlayerSelectionType.bowler) + : []; + + final showCheckBox = widget.playerSelectionType != + PlayerSelectionType.bowler + ? batsManList.any((element) => element.status == PlayerStatus.injured) + : false; + + final injuredPlayerRemained = + widget.playerSelectionType != PlayerSelectionType.bowler + ? batsManList.every((e) => e.status == PlayerStatus.injured) + : false; - Widget _allPlayerSelectionView( - BuildContext context, ScoreBoardViewState state) { return Stack( children: [ ListView( - padding: const EdgeInsets.only(bottom: 80), children: [ - _sectionTitle(context, context.l10n.score_board_batsman_title), - Row( - children: [ - _userCell( - context: context, - user: batsMan1?.player, - onTap: () async { - final player = await SelectPlayerSheet.show< - List<({String teamId, List players})>>( - context, - type: PlayerSelectionType.batsMan, - excludedIds: [ - batsMan1?.player.id ?? "INVALID ID", - batsMan2?.player.id ?? "INVALID ID" - ]); - if (player != null && context.mounted) { - setState(() { - batsMan1 = player.first.players.first; - }); - } - }, - ), - const SizedBox( - height: 16, - ), - if (widget.type == PlayerSelectionType.all) ...[ - _userCell( - context: context, - user: batsMan2?.player, - onTap: () async { - final player = await SelectPlayerSheet.show< - List< - ({ - List players, - String teamId - })>>(context, - type: PlayerSelectionType.batsMan, - excludedIds: [ - batsMan1?.player.id ?? "INVALID ID", - batsMan2?.player.id ?? "INVALID ID" - ]); - if (player != null && context.mounted) { - setState(() { - batsMan2 = player.first.players.first; - }); - } - }, - ), - ] else ...[ - const Expanded(child: SizedBox()), - ], - ], - ), - _sectionTitle(context, context.l10n.score_board_bowler_title), - Row( - children: [ - _userCell( - context: context, - user: bowler?.player, - onTap: () async { - final player = await SelectPlayerSheet.show< - List<({String teamId, List players})>>( - context, - type: PlayerSelectionType.bowler, - excludedIds: [bowler?.player.id ?? "INVALID ID"]); - if (player != null && context.mounted) { - setState(() { - bowler = player.first.players.first; - }); - } - }, - ), - const SizedBox( - height: 16, - ), - const Expanded(child: SizedBox()), - ], - ), - ], - ), - _stickyButton(context, state), - ], - ); - } - - Widget _sectionTitle(BuildContext context, String title) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 24, - ), - Text( - title, - style: AppTextStyle.header1 - .copyWith(color: context.colorScheme.textSecondary), - ), - const SizedBox( - height: 16, - ), - ], - ); - } - - Widget _userCell({ - required BuildContext context, - UserModel? user, - required Function() onTap, - }) { - return Expanded( - child: OnTapScale( - onTap: onTap, - child: Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: context.colorScheme.containerNormalOnSurface, - border: Border.all(color: context.colorScheme.outline), - borderRadius: BorderRadius.circular(20), - ), - child: Column( - children: [ - user != null - ? ImageAvatar( - imageUrl: user.profile_img_url, - initial: user.nameInitial, - size: 60, - ) - : _profilePlaceHolder(context, size: 60), - const SizedBox( - height: 16, + // batsman + if (widget.playerSelectionType != PlayerSelectionType.bowler && + batsManList.isNotEmpty) ...[ + _sectionTitle( + context, + (widget.playerSelectionType == PlayerSelectionType.all) + ? context.l10n.score_board_choose_opening_batsmen_title + : context.l10n.score_board_choose_batsman_title( + state.lastAssignedIndex + 1)), + _remainingPlayerGrid( + context, + state, + batsManList, + PlayerSelectionType.batsMan, ), - Text( - user?.name ?? context.l10n.score_board_select_player_title, - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), - ) ], - ), - ), - ), - ); - } - Widget _profilePlaceHolder(BuildContext context, {required double size}) { - return Container( - height: size, - width: size, - decoration: BoxDecoration( - color: context.colorScheme.containerLow, - shape: BoxShape.circle, - ), - child: const Icon(Icons.person), - ); - } - - Widget _specificPlayerSelectionView( - BuildContext context, - ScoreBoardViewState state, - ) { - final list = getFilteredList(state); - return Stack( - children: [ - ListView( - children: [ - _sectionTitle( + // bowler + if (widget.playerSelectionType != PlayerSelectionType.batsMan) ...[ + _sectionTitle( + context, + context.l10n.score_board_choose_bowler_for_over_title( + state.overCount)), + _remainingPlayerGrid( context, - (widget.type == PlayerSelectionType.batsMan) - ? context.l10n.score_board_choose_batsman_title - : context.l10n.score_board_choose_bowler_for_over_title( - state.overCount)), - GridView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 3, - crossAxisSpacing: 16, - mainAxisSpacing: 16, - childAspectRatio: 0.7), - itemCount: list.length, - itemBuilder: (context, index) { - return _userCellWithTag( - context: context, - state: state, - user: list[index].player, - tag: list[index].status == PlayerStatus.injured - ? context.l10n.score_board_injured_tag_title - : null, - isSelected: widget.type == PlayerSelectionType.batsMan - ? batsMan1?.player.id == list[index].player.id - : bowler?.player.id == list[index].player.id, - onTap: () { - setState(() { - if (widget.type == PlayerSelectionType.batsMan) { - batsMan1 = list[index]; - } else { - bowler = list[index]; - } - }); - }, - ); - }, - ) + state, + bowlerList, + PlayerSelectionType.bowler, + ), + ], ], ), - _stickyButton(context, state) + _stickyButton(context, state, showCheckBox, injuredPlayerRemained), ], ); } - List getFilteredList(ScoreBoardViewState state) { + List _getFilteredList( + ScoreBoardViewState state, { + required PlayerSelectionType type, + }) { if (state.match == null) { return []; } - final teamId = (widget.type == PlayerSelectionType.batsMan + final teamId = (type == PlayerSelectionType.batsMan ? state.currentInning?.team_id : state.otherInning?.team_id) ?? "INVALID ID"; final teamPlayers = state.match?.teams - .firstWhere((element) => element.team.id == teamId) - .squad; - - return teamPlayers - ?.where((element) => - !(widget.excludedIds ?? []).contains(element.player.id) && - ((widget.type == PlayerSelectionType.batsMan) - ? _isPlayerEligibleForBatsman(element.status) - : true)) - .toList() ?? - []; + .where((element) => element.team.id == teamId) + .firstOrNull + ?.squad; + + if (type == PlayerSelectionType.bowler) { + return teamPlayers ?? []; + } else { + return teamPlayers + ?.where((element) => _isPlayerEligibleForBatsman(element.status)) + .toList() ?? + []; + } } bool _isPlayerEligibleForBatsman(PlayerStatus? status) { @@ -317,23 +171,108 @@ class _SelectPlayerSheetState extends ConsumerState { status != PlayerStatus.suspended; } + Widget _sectionTitle(BuildContext context, String title) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 24), + Text( + title, + style: AppTextStyle.header1 + .copyWith(color: context.colorScheme.textSecondary), + ), + const SizedBox(height: 16), + ], + ); + } + + Widget _remainingPlayerGrid( + BuildContext context, + ScoreBoardViewState state, + List list, + PlayerSelectionType type, + ) { + return GridView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 3, + crossAxisSpacing: 16, + mainAxisSpacing: 16, + childAspectRatio: 0.7), + itemCount: list.length, + itemBuilder: (context, index) { + final player = list[index]; + + return _userCellWithTag( + context: context, + state: state, + showOverCount: type == PlayerSelectionType.bowler, + user: player.player, + tag: player.status == PlayerStatus.injured && + type == PlayerSelectionType.batsMan + ? context.l10n.score_board_injured_tag_title + : null, + isSelected: type == PlayerSelectionType.batsMan + ? [batsMan1?.player.id, batsMan2?.player.id] + .contains(player.player.id) + : bowler?.player.id == player.player.id, + disableCell: player.status == PlayerStatus.injured && + type == PlayerSelectionType.batsMan && + !isEnabled, + onTap: () { + setState(() { + if (type == PlayerSelectionType.batsMan) { + if (widget.playerSelectionType == PlayerSelectionType.all) { + if (batsMan1?.player.id == player.player.id) { + batsMan1 = null; + } else if (batsMan2?.player.id == player.player.id) { + batsMan2 = null; + } else if (batsMan1 == null) { + batsMan1 = player; + } else if (batsMan2 == null) { + batsMan2 = player; + } else { + return; + // extra else to suppress lint suggestion of using ??= for batsMan2 assignment + } + } else { + batsMan1 = player; + } + } else { + bowler = player; + } + }); + }, + ); + }, + ); + } + Widget _userCellWithTag({ required BuildContext context, required ScoreBoardViewState state, UserModel? user, String? tag, + bool showOverCount = false, required bool isSelected, + required bool disableCell, required Function() onTap, }) { - final overCount = _getOverCount(state, user?.id ?? "INVALID ID"); + final overCount = + showOverCount ? _getOverCount(state, user?.id ?? "INVALID ID") : 0; + return OnTapScale( - onTap: onTap, + enabled: !disableCell, + onTap: disableCell ? null : onTap, child: Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: isSelected ? context.colorScheme.primary - : context.colorScheme.containerNormalOnSurface, + : disableCell + ? Colors.transparent + : context.colorScheme.containerNormalOnSurface, border: Border.all(color: context.colorScheme.outline), borderRadius: BorderRadius.circular(20), ), @@ -351,10 +290,12 @@ class _SelectPlayerSheetState extends ConsumerState { ), Text( user?.name ?? context.l10n.score_board_select_player_title, - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), + style: AppTextStyle.subtitle1.copyWith( + color: disableCell + ? context.colorScheme.textDisabled + : context.colorScheme.textPrimary), ), - if (widget.type == PlayerSelectionType.bowler) ...[ + if (showOverCount) ...[ Text( "(${context.l10n.match_list_overs_title(overCount)})", style: AppTextStyle.body1 @@ -365,7 +306,7 @@ class _SelectPlayerSheetState extends ConsumerState { Text( tag, style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), + .copyWith(color: context.colorScheme.alert), ), ] ], @@ -380,60 +321,159 @@ class _SelectPlayerSheetState extends ConsumerState { element.bowler_id == id && element.extras_type != ExtrasType.noBall && element.extras_type != ExtrasType.penaltyRun && - element.extras_type != ExtrasType.wide) + element.extras_type != ExtrasType.wide && + element.wicket_type != WicketType.retired && + element.wicket_type != WicketType.retiredHurt && + element.wicket_type != WicketType.timedOut) .toList(); - return (scores.length / 6).floor(); } + Widget _profilePlaceHolder( + BuildContext context, { + required double size, + }) { + return Container( + height: size, + width: size, + decoration: BoxDecoration( + color: context.colorScheme.containerLow, + shape: BoxShape.circle, + ), + child: const Icon(Icons.person), + ); + } + Widget _stickyButton( BuildContext context, ScoreBoardViewState state, + bool showContWithInjPlayerOption, + bool injuredPlayerRemained, ) { return Align( alignment: Alignment.bottomCenter, - child: PrimaryButton( - context.l10n.score_board_select_title, - enabled: widget.type == PlayerSelectionType.all - ? (batsMan1 != null && batsMan2 != null && bowler != null) - : widget.type == PlayerSelectionType.batsManAndBowler - ? (batsMan1 != null && bowler != null) - : widget.type == PlayerSelectionType.batsMan - ? batsMan1 != null - : bowler != null, - onPressed: () { - final List<({List players, String teamId})> - selectedPlayer = []; - - if (widget.type != PlayerSelectionType.batsMan) { - selectedPlayer.add( - ( - teamId: state.otherInning?.team_id ?? "INVALID ID", - players: [bowler!] - ), - ); - } - - if (widget.type != PlayerSelectionType.bowler) { - List players = [batsMan1!]; + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + if (showContWithInjPlayerOption) ...[ + _contWithInjPlayerOption(context), + const SizedBox(height: 16) + ], + PrimaryButton( + _getButtonTitle( + state.otherInning?.innings_status == InningStatus.finish, + injuredPlayerRemained), + enabled: _isStickyButtonEnable(injuredPlayerRemained), + onPressed: () => + _onSelectButton(context, state, injuredPlayerRemained), + ), + ], + ), + ); + } - if (widget.type == PlayerSelectionType.all) { - players.add(batsMan2!); + Widget _contWithInjPlayerOption(BuildContext context) { + return OnTapScale( + onTap: () { + setState(() { + isEnabled = !isEnabled; + if (!isEnabled) { + if (batsMan1?.status == PlayerStatus.injured) { + batsMan1 = null; + } + if (batsMan2?.status == PlayerStatus.injured) { + batsMan2 = null; } - - selectedPlayer.add( - ( - teamId: state.currentInning?.team_id ?? "INVALID ID", - players: players - ), - ); } - - context.pop(selectedPlayer); - }, + }); + }, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16.0), + child: Row( + children: [ + Icon(isEnabled ? Icons.check_box : Icons.check_box_outline_blank), + const SizedBox(width: 8), + Text( + context.l10n.score_board_continue_with_injured_player_title, + style: AppTextStyle.subtitle1.copyWith( + color: context.colorScheme.textPrimary, fontSize: 20), + ), + ], + ), ), ); } + + String _getButtonTitle( + bool isSecondInningRunning, + bool injuredPlayerRemained, + ) { + if (injuredPlayerRemained && !isEnabled) { + if (isSecondInningRunning) { + return context.l10n.score_board_end_match_title; + } else { + return context.l10n.score_board_end_inning_title; + } + } else { + return context.l10n.score_board_select_title; + } + } + + bool _isStickyButtonEnable(bool injuredPlayerRemained) { + return widget.playerSelectionType == PlayerSelectionType.all + ? (batsMan1 != null && batsMan2 != null && bowler != null) + : widget.playerSelectionType == PlayerSelectionType.batsManAndBowler + ? (((injuredPlayerRemained && !isEnabled) || batsMan1 != null) && + bowler != null) + : widget.playerSelectionType == PlayerSelectionType.batsMan + ? (injuredPlayerRemained && !isEnabled) || batsMan1 != null + : bowler != null; + } + + void _onSelectButton( + BuildContext context, + ScoreBoardViewState state, + bool injuredPlayerRemained, + ) { + if (injuredPlayerRemained && !isEnabled) { + context.pop(( + selectedPlayer: null, + contWithInjPlayer: isEnabled, + )); + } else { + final List<({List players, String teamId})> selectedPlayer = + []; + + if (widget.playerSelectionType != PlayerSelectionType.batsMan) { + selectedPlayer.add( + ( + teamId: state.otherInning?.team_id ?? "INVALID ID", + players: [bowler!] + ), + ); + } + + if (widget.playerSelectionType != PlayerSelectionType.bowler) { + List players = [batsMan1!]; + + if (widget.playerSelectionType == PlayerSelectionType.all) { + players.add(batsMan2!); + } + + selectedPlayer.add( + ( + teamId: state.currentInning?.team_id ?? "INVALID ID", + players: players + ), + ); + } + + context.pop(( + selectedPlayer: selectedPlayer, + contWithInjPlayer: isEnabled, + )); + } + } } enum PlayerSelectionType { diff --git a/khelo/lib/ui/flow/score_board/score_board_screen.dart b/khelo/lib/ui/flow/score_board/score_board_screen.dart index a0eece55..2e94f9ed 100644 --- a/khelo/lib/ui/flow/score_board/score_board_screen.dart +++ b/khelo/lib/ui/flow/score_board/score_board_screen.dart @@ -1,5 +1,4 @@ import 'package:data/api/ball_score/ball_score_model.dart'; -import 'package:data/api/innings/inning_model.dart'; import 'package:data/api/match/match_model.dart'; import 'package:data/api/user/user_models.dart'; import 'package:flutter/material.dart'; @@ -11,10 +10,13 @@ import 'package:khelo/domain/extensions/context_extensions.dart'; import 'package:khelo/domain/extensions/widget_extension.dart'; import 'package:khelo/ui/flow/score_board/components/add_extra_dialog.dart'; import 'package:khelo/ui/flow/score_board/components/add_penalty_run_dialog.dart'; +import 'package:khelo/ui/flow/score_board/components/confirm_action_dialog.dart'; import 'package:khelo/ui/flow/score_board/components/is_boundary_dialog.dart'; import 'package:khelo/ui/flow/score_board/components/match_complete_dialog.dart'; +import 'package:khelo/ui/flow/score_board/components/more_option_dialog.dart'; import 'package:khelo/ui/flow/score_board/components/over_complete_dialog.dart'; import 'package:khelo/ui/flow/score_board/components/score_board_buttons.dart'; +import 'package:khelo/ui/flow/score_board/components/score_display_view.dart'; import 'package:khelo/ui/flow/score_board/components/select_player_sheet.dart'; import 'package:khelo/ui/flow/score_board/components/select_wicket_taker_sheet.dart'; import 'package:khelo/ui/flow/score_board/components/select_wicket_type_sheet.dart'; @@ -22,7 +24,6 @@ import 'package:khelo/ui/flow/score_board/components/striker_selection_dialog.da 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 'package:style/text/app_text_style.dart'; import 'components/inning_complete_dialog.dart'; @@ -38,44 +39,75 @@ class ScoreBoardScreen extends ConsumerStatefulWidget { class _ScoreBoardScreenState extends ConsumerState { late ScoreBoardViewNotifier notifier; - void _observeShowSelectBatsManSheet(BuildContext context, WidgetRef ref) { + void _observeShowSelectBatsManSheet( + BuildContext context, + WidgetRef ref, + bool continueWithInjuredPlayers, + ) { ref.listen( scoreBoardStateProvider.select((value) => value.showSelectBatsManSheet), (previous, next) { if (next != null) { - _showSelectPlayerSheet(context, PlayerSelectionType.batsMan); + _showSelectPlayerSheet( + context, + continueWithInjuredPlayers, + PlayerSelectionType.batsMan, + ); } }); } - void _observeShowSelectBowlerSheet(BuildContext context, WidgetRef ref) { + void _observeShowSelectBowlerSheet( + BuildContext context, + WidgetRef ref, + bool continueWithInjuredPlayers, + ) { ref.listen( scoreBoardStateProvider.select((value) => value.showSelectBowlerSheet), (previous, next) { if (next != null) { - _showSelectPlayerSheet(context, PlayerSelectionType.bowler); + _showSelectPlayerSheet( + context, + continueWithInjuredPlayers, + PlayerSelectionType.bowler, + ); } }); } void _observeShowSelectBowlerAndBatsManSheet( - BuildContext context, WidgetRef ref) { + BuildContext context, + WidgetRef ref, + bool continueWithInjuredPlayers, + ) { ref.listen( scoreBoardStateProvider .select((value) => value.showSelectBowlerAndBatsManSheet), (previous, next) { if (next != null) { - _showSelectPlayerSheet(context, PlayerSelectionType.batsManAndBowler); + _showSelectPlayerSheet( + context, + continueWithInjuredPlayers, + PlayerSelectionType.batsManAndBowler, + ); } }); } - void _observeShowSelectPlayerSheet(BuildContext context, WidgetRef ref) { + void _observeShowSelectPlayerSheet( + BuildContext context, + WidgetRef ref, + bool continueWithInjuredPlayers, + ) { ref.listen( scoreBoardStateProvider.select((value) => value.showSelectPlayerSheet), (previous, next) { if (next != null) { - _showSelectPlayerSheet(context, PlayerSelectionType.all); + _showSelectPlayerSheet( + context, + continueWithInjuredPlayers, + PlayerSelectionType.all, + ); } }); } @@ -106,9 +138,12 @@ class _ScoreBoardScreenState extends ConsumerState { scoreBoardStateProvider.select( (value) => value.showUndoBallConfirmationDialog), (previous, next) { if (next != null) { - _showUndoBallConfirmationDialog( + ConfirmActionDialog.show( context, - onUndo: notifier.undoLastBall, + title: context.l10n.score_board_undo_last_ball_title, + description: context.l10n.score_board_undo_last_ball_description_text, + primaryButtonText: context.l10n.score_board_undo_title, + onConfirmation: notifier.undoLastBall, ); } }); @@ -124,7 +159,10 @@ class _ScoreBoardScreenState extends ConsumerState { }); } - void _observeShowInningCompleteDialog(BuildContext context, WidgetRef ref) { + void _observeShowInningCompleteDialog( + BuildContext context, + WidgetRef ref, + ) { ref.listen( scoreBoardStateProvider.select( (value) => value.showInningCompleteDialog), (previous, next) { @@ -134,7 +172,10 @@ class _ScoreBoardScreenState extends ConsumerState { }); } - void _observeShowMatchCompleteDialog(BuildContext context, WidgetRef ref) { + void _observeShowMatchCompleteDialog( + BuildContext context, + WidgetRef ref, + ) { ref.listen( scoreBoardStateProvider.select( (value) => value.showMatchCompleteDialog), (previous, next) { @@ -221,9 +262,12 @@ class _ScoreBoardScreenState extends ConsumerState { scoreBoardStateProvider.select((value) => value.showPauseScoringDialog), (previous, next) { if (next != null) { - _showPauseScoringDialog( + ConfirmActionDialog.show( context, - onPause: () => notifier.onPauseScoring(), + title: context.l10n.score_board_pause_scoring_title, + description: context.l10n.score_board_pause_scoring_description_text, + primaryButtonText: context.l10n.score_board_pause_title, + onConfirmation: notifier.onPauseScoring, ); } }); @@ -247,8 +291,10 @@ class _ScoreBoardScreenState extends ConsumerState { (previous, next) { if (next != null) { showSnackBar( - context, context.l10n.score_board_can_undo_till_running_over_title, - length: SnackBarLength.long); + context, + context.l10n.score_board_can_undo_till_running_over_title, + length: SnackBarLength.long, + ); } }); } @@ -265,10 +311,14 @@ class _ScoreBoardScreenState extends ConsumerState { notifier = ref.watch(scoreBoardStateProvider.notifier); final state = ref.watch(scoreBoardStateProvider); - _observeShowSelectBatsManSheet(context, ref); - _observeShowSelectBowlerSheet(context, ref); - _observeShowSelectBowlerAndBatsManSheet(context, ref); - _observeShowSelectPlayerSheet(context, ref); + _observeShowSelectBatsManSheet( + context, ref, state.continueWithInjuredPlayers); + _observeShowSelectBowlerSheet( + context, ref, state.continueWithInjuredPlayers); + _observeShowSelectBowlerAndBatsManSheet( + context, ref, state.continueWithInjuredPlayers); + _observeShowSelectPlayerSheet( + context, ref, state.continueWithInjuredPlayers); _observeShowSelectWicketTypeSheet(context, ref); _observeShowStrikerSelectionDialog(context, ref); _observeShowUndoBallConfirmationDialog(context, ref); @@ -290,7 +340,7 @@ class _ScoreBoardScreenState extends ConsumerState { canPop: false, child: AppPage( title: context.l10n.score_board_screen_title, - actions: [_moreOptionButton(context, notifier)], + actions: [_moreOptionButton(context, notifier, state)], automaticallyImplyLeading: false, body: Padding( padding: context.mediaQueryPadding, @@ -303,23 +353,22 @@ class _ScoreBoardScreenState extends ConsumerState { Widget _moreOptionButton( BuildContext context, ScoreBoardViewNotifier notifier, + ScoreBoardViewState state, ) { - return PopupMenuButton( - color: context.colorScheme.containerNormalOnSurface, - onSelected: notifier.onMatchOptionSelect, - itemBuilder: (BuildContext context) { - return MatchOption.values - .map((option) => PopupMenuItem( - value: option, - child: Text( - option.getTitle(context), - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), - ), - )) - .toList(); - }, - ); + return IconButton( + onPressed: () async { + final selection = await MoreOptionDialog.show< + ({MatchOption option, bool contWithInjPlayer})>(context, + continueWithInjPlayer: state.continueWithInjuredPlayers); + + if (selection != null && context.mounted) { + notifier.onMatchOptionSelect( + selection.option, + selection.contWithInjPlayer, + ); + } + }, + icon: const Icon(Icons.more_horiz)); } Widget _body( @@ -333,327 +382,34 @@ class _ScoreBoardScreenState extends ConsumerState { return Column( children: [ - _scoreDisplayView(context, state), - ScoreBoardButtons( - onTap: notifier.onScoreButtonTap, - ), - ], - ); - } - - Widget _scoreDisplayView(BuildContext context, ScoreBoardViewState state) { - return Expanded( - child: ListView( - children: [ - _matchScoreView(context, state), - const SizedBox( - height: 24, - ), - _batsManDetailsView(context, state), - _bowlerAndBallDetailView(context, state), - ], - ), - ); - } - - Widget _matchScoreView( - BuildContext context, - ScoreBoardViewState state, - ) { - final currentOver = _getCurrentOver(state); - - return Stack( - children: [ - _powerPlayTag(context, state), - Center( - child: Wrap( - alignment: WrapAlignment.center, - direction: Axis.vertical, - children: [ - Text.rich( - textAlign: TextAlign.center, - TextSpan( - children: [ - TextSpan( - text: '${state.totalRuns}/${state.wicketCount}', - style: AppTextStyle.subtitle1.copyWith( - color: context.colorScheme.textPrimary, fontSize: 39), - ), - TextSpan( - text: '($currentOver/${state.match?.number_of_over})', - style: AppTextStyle.header4 - .copyWith(color: context.colorScheme.textSecondary), - ), - ], - ), - ), - _runNeededText(context, state), - ], - ), - ), - ], - ); - } - - Widget _powerPlayTag( - BuildContext context, - ScoreBoardViewState state, - ) { - final powerPlay = _getPowerPlayCount(state); - if (powerPlay != null) { - return Container( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 2), - decoration: BoxDecoration( - color: context.colorScheme.primary, - borderRadius: - const BorderRadius.horizontal(right: Radius.circular(12))), - child: Text( - context.l10n.score_board_power_play_title + powerPlay.toString(), - style: AppTextStyle.body1.copyWith( - color: context.colorScheme.textInversePrimary, - fontWeight: FontWeight.w500), - ), - ); - } else { - return const SizedBox(); - } - } - - int? _getPowerPlayCount(ScoreBoardViewState state) { - if (state.match?.power_play_overs1.contains(state.overCount) ?? false) { - return 1; - } else if (state.match?.power_play_overs2.contains(state.overCount) ?? - false) { - return 2; - } else if (state.match?.power_play_overs3.contains(state.overCount) ?? - false) { - return 3; - } - return null; - } - - Widget _runNeededText( - BuildContext context, - ScoreBoardViewState state, - ) { - if (state.otherInning?.innings_status == InningStatus.finish) { - final requiredRun = ((state.otherInning?.total_runs ?? 0) + 1) - - (state.currentInning?.total_runs ?? 0); - final pendingOver = (state.match?.number_of_over ?? 0) - state.overCount; - final pendingBall = (pendingOver * 6) + (6 - state.ballCount); - return Text( - context.l10n.score_board_need_run_text(requiredRun, pendingBall), - textAlign: TextAlign.center, - style: - AppTextStyle.subtitle1.copyWith(color: context.colorScheme.warning), - ); - } else { - return const SizedBox(); - } - } - - String _getCurrentOver(ScoreBoardViewState state) { - return "${state.overCount - 1}.${state.ballCount}"; - } - - Widget _batsManDetailsView(BuildContext context, ScoreBoardViewState state) { - return Row( - children: [ - _batManCellView(context, state, state.batsMans?.firstOrNull), - _batManCellView(context, state, state.batsMans?.elementAtOrNull(1)), + const ScoreDisplayView(), + ScoreBoardButtons(onTap: notifier.onScoreButtonTap), ], ); } - Widget _batManCellView( - BuildContext context, - ScoreBoardViewState state, - MatchPlayer? user, - ) { - bool isOnStrike = state.strikerId == user?.player.id; - final (run, ball) = - _getBatsManTotalRuns(state, user?.player.id ?? "INVALID ID"); - return Expanded( - child: Container( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - alignment: Alignment.center, - decoration: BoxDecoration( - border: Border.all(color: context.colorScheme.outline)), - child: Row( - children: [ - Expanded( - child: Align( - alignment: Alignment.centerRight, - child: Icon( - Icons.sports_cricket, - color: isOnStrike - ? context.colorScheme.primary - : context.colorScheme.textDisabled, - ), - ), - ), - const SizedBox( - width: 16, - ), - Expanded( - flex: 2, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - user?.player.name ?? context.l10n.score_board_player_title, - style: AppTextStyle.header1 - .copyWith(color: context.colorScheme.textPrimary), - ), - Text( - "$run($ball)", - style: AppTextStyle.header4 - .copyWith(color: context.colorScheme.textSecondary), - ), - ], - ), - ) - ], - ), - ), - ); - } - - (int, int) _getBatsManTotalRuns(ScoreBoardViewState state, String batsManId) { - final scoresList = state.currentScoresList - .where((element) => element.batsman_id == batsManId); - - int totalRuns = scoresList - .where((element) => (element.extras_type == ExtrasType.noBall || - element.extras_type == null)) - .fold(0, (sum, element) => sum + (element.runs_scored ?? 0)); - - final batsManFacedBall = scoresList - .where((element) => (element.extras_type != ExtrasType.wide)) - .length; - - return (totalRuns, batsManFacedBall); - } - - Widget _bowlerAndBallDetailView( - BuildContext context, - ScoreBoardViewState state, - ) { - return Container( - width: double.infinity, - padding: const EdgeInsets.all(16), - color: context.colorScheme.secondaryVariant, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _bowlerNameView( - context, - state.bowler?.player.name ?? - context.l10n.score_board_player_title), - const SizedBox( - height: 16, - ), - _ballHistoryListView(context, state), - ], - ), - ); - } - - Widget _bowlerNameView(BuildContext context, String name) { - return Text.rich( - TextSpan( - children: [ - WidgetSpan( - child: Icon( - Icons.sports_baseball_outlined, - color: context.colorScheme.surface, - )), - TextSpan( - text: ' $name', - style: TextStyle( - fontWeight: FontWeight.bold, - color: context.colorScheme.textPrimary), - ), - ], - ), - ); - } - - Widget _ballHistoryListView(BuildContext context, ScoreBoardViewState state) { - return SingleChildScrollView( - reverse: true, - scrollDirection: Axis.horizontal, - child: Row( - children: [ - for (final ball in _getFilteredCurrentOverBall(state)) ...[ - _ballView(context, ball), - const SizedBox(width: 8) - ] - ], - ), - ); - } - - List _getFilteredCurrentOverBall(ScoreBoardViewState state) { - final list = state.currentScoresList - .where((element) => - element.over_number == state.overCount && - element.extras_type != ExtrasType.penaltyRun) - .toList(); - return list; - } - - Widget _ballView(BuildContext context, BallScoreModel ball) { - return Container( - height: 50, - width: 50, - alignment: Alignment.center, - padding: const EdgeInsets.all(8), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: context.colorScheme.containerLow, - border: Border.all(color: context.colorScheme.outline)), - child: Text(_getTextBasedOnBall(context, ball)), - ); - } - - String _getTextBasedOnBall(BuildContext context, BallScoreModel ball) { - if (ball.wicket_type != null) { - return context.l10n.score_board_wicket_short_text; - } else if (ball.extras_type != null) { - switch (ball.extras_type!) { - case ExtrasType.wide: - return context.l10n.score_board_wide_ball_short_text; - case ExtrasType.noBall: - return context.l10n.score_board_no_ball_short_text; - case ExtrasType.bye: - return context.l10n.score_board_run_sup_script_text( - "${ball.extras_awarded ?? 0}", - context.l10n.score_board_bye_short_text); - case ExtrasType.legBye: - return context.l10n.score_board_run_sup_script_text( - "${ball.extras_awarded ?? 0}", - context.l10n.score_board_leg_bye_short_text); - case ExtrasType.penaltyRun: - return "P"; - } - } else if (ball.wicket_type == null && ball.extras_type == null) { - return "${ball.runs_scored}"; - } else { - return ""; - } - } - Future _showSelectPlayerSheet( BuildContext context, + bool continueWithInjuredPlayers, PlayerSelectionType type, ) async { - final players = await SelectPlayerSheet.show< - List<({String teamId, List players})>>(context, - type: type); - if (players != null && context.mounted) { - notifier.setPlayers(players); + final result = await SelectPlayerSheet.show< + ({ + List<({List players, String teamId})>? selectedPlayer, + bool contWithInjPlayer, + })>( + context, + type: type, + continueWithInjPlayer: continueWithInjuredPlayers, + ); + if (result != null && context.mounted) { + if (result.selectedPlayer != null) { + notifier.setPlayers( + currentPlayers: result.selectedPlayer!, + contWithInjPlayer: result.contWithInjPlayer); + } else { + notifier.onReviewMatchResult(result.contWithInjPlayer); + } } } @@ -666,8 +422,10 @@ class _ScoreBoardScreenState extends ConsumerState { Future _onWicketTypeSelect( BuildContext context, WicketType type) async { - final outBatsMan = await StrikerSelectionDialog.show(context, - isForStrikerSelection: false); // who got out + final outBatsMan = await StrikerSelectionDialog.show( + context, + isForStrikerSelection: false, + ); String? wicketTakerId; if ((type == WicketType.caught || @@ -703,48 +461,6 @@ class _ScoreBoardScreenState extends ConsumerState { } } - void _showUndoBallConfirmationDialog( - BuildContext context, { - required Function() onUndo, - }) { - showAdaptiveDialog( - context: context, - builder: (context) { - return AlertDialog.adaptive( - title: Text( - context.l10n.score_board_undo_last_ball_title, - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), - ), - content: Text( - context.l10n.score_board_undo_last_ball_description_text, - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), - ), - actions: [ - TextButton( - onPressed: () => context.pop(), - child: Text( - context.l10n.common_cancel_title, - style: TextStyle(color: context.colorScheme.textSecondary), - ), - ), - TextButton( - onPressed: () { - context.pop(); - onUndo(); - }, - child: Text( - context.l10n.score_board_undo_title, - style: TextStyle(color: context.colorScheme.alert), - ), - ), - ], - ); - }, - ); - } - Future _showOverCompleteDialog(BuildContext context) async { final startNext = await OverCompleteDialog.show(context); if (startNext != null && context.mounted) { @@ -822,48 +538,6 @@ class _ScoreBoardScreenState extends ConsumerState { } } - void _showPauseScoringDialog( - BuildContext context, { - required Function() onPause, - }) { - showAdaptiveDialog( - context: context, - builder: (context) { - return AlertDialog.adaptive( - title: Text( - context.l10n.score_board_pause_scoring_title, - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), - ), - content: Text( - context.l10n.score_board_pause_scoring_description_text, - style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), - ), - actions: [ - TextButton( - onPressed: () => context.pop(), - child: Text( - context.l10n.common_cancel_title, - style: TextStyle(color: context.colorScheme.textSecondary), - ), - ), - TextButton( - onPressed: () { - context.pop(); - onPause(); - }, - child: Text( - context.l10n.score_board_pause_title, - style: TextStyle(color: context.colorScheme.alert), - ), - ), - ], - ); - }, - ); - } - Future _showAddPenaltyRunDialog(BuildContext context) async { final penalty = await AddPenaltyRunDialog.show<({String teamId, int runs})>(context); diff --git a/khelo/lib/ui/flow/score_board/score_board_view_model.dart b/khelo/lib/ui/flow/score_board/score_board_view_model.dart index 7725cc5c..8516efd1 100644 --- a/khelo/lib/ui/flow/score_board/score_board_view_model.dart +++ b/khelo/lib/ui/flow/score_board/score_board_view_model.dart @@ -6,10 +6,11 @@ import 'package:data/service/match/match_service.dart'; import 'package:data/service/innings/inning_service.dart'; import 'package:data/service/ball_score/ball_score_service.dart'; import 'package:data/extensions/list_extensions.dart'; -import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:khelo/domain/extensions/context_extensions.dart'; +import 'package:khelo/domain/extensions/data_model_extensions/ball_score_model_extension.dart'; part 'score_board_view_model.freezed.dart'; @@ -36,10 +37,10 @@ class ScoreBoardViewNotifier extends StateNotifier { void setData(String matchId) { this.matchId = matchId; - getMatchById(); + _getMatchById(); } - Future getMatchById() async { + Future _getMatchById() async { if (matchId == null) { return; } @@ -49,14 +50,14 @@ class ScoreBoardViewNotifier extends StateNotifier { final match = await _matchService.getMatchById(matchId!); state = state.copyWith(match: match); - getInningsForTheMatch(); + _getInningsForTheMatch(); } catch (e) { state = state.copyWith(error: e, loading: false); debugPrint("ScoreBoardViewNotifier: error while get Match By id -> $e"); } } - Future getInningsForTheMatch() async { + Future _getInningsForTheMatch() async { if (state.match == null) { return; } @@ -65,7 +66,7 @@ class ScoreBoardViewNotifier extends StateNotifier { matchId: state.match!.id ?? "INVALID ID"); if (innings.isEmpty) { - await createInnings(); + await _createInnings(); return; } @@ -80,7 +81,7 @@ class ScoreBoardViewNotifier extends StateNotifier { state = state.copyWith(currentInning: inningFirst, otherInning: inningSecond); - getScoresList(); + _getScoresList(); } catch (e) { state = state.copyWith(error: e, loading: false); debugPrint( @@ -88,7 +89,7 @@ class ScoreBoardViewNotifier extends StateNotifier { } } - Future getScoresList() async { + Future _getScoresList() async { if (state.currentInning == null || state.otherInning == null) { return; } @@ -132,9 +133,20 @@ class ScoreBoardViewNotifier extends StateNotifier { (value ?? 0) > (element ?? 0) ? value ?? 0 : element ?? 0) ?? 0; - final lastBall = state.currentScoresList.lastOrNull; + BallScoreModel? lastBall; - final bowlerId = lastBall?.ball_number != 6 ? lastBall?.bowler_id : null; + try { + lastBall = _getDeliveredLastBall(); + } on StateError { + lastBall = null; + } + + // last_ball is not over's last ball or if last_ball_of_over then is_illegal_delivery ? bowler_id : null + final bowlerId = lastBall?.ball_number != 6 || + (lastBall?.ball_number == 6 && + !(lastBall?.isLegalDelivery() ?? true)) + ? lastBall?.bowler_id + : null; final bowler = bowlerId != null ? state.match!.teams .firstWhere( @@ -146,15 +158,13 @@ class ScoreBoardViewNotifier extends StateNotifier { bool showSelectAllPlayerSheet = bowler == null && (currentPlayingBatsMan.isEmpty); - int overCount = int.parse( - (state.currentInning!.overs == 0 ? 1 : state.currentInning!.overs ?? 1) - .toStringAsFixed(0)); + int inningOverCount = ((state.currentInning!.overs ?? 0) + 1).truncate(); state = state.copyWith( batsMans: currentPlayingBatsMan, bowler: bowler, lastAssignedIndex: lastPlayerIndex, - overCount: overCount, + overCount: inningOverCount, totalRuns: state.currentInning!.total_runs ?? 0, wicketCount: state.otherInning!.total_wickets ?? 0, showSelectPlayerSheet: showSelectAllPlayerSheet ? DateTime.now() : null, @@ -168,6 +178,7 @@ class ScoreBoardViewNotifier extends StateNotifier { currentPlayingBatsMan.length == 1 ? DateTime.now() : null, + strikerId: currentPlayingBatsMan.firstOrNull?.player.id, showSelectBatsManSheet: bowler != null && currentPlayingBatsMan.length == 1 && !showSelectAllPlayerSheet @@ -177,7 +188,7 @@ class ScoreBoardViewNotifier extends StateNotifier { ); } - Future createInnings() async { + Future _createInnings() async { if (state.match == null) { return; } @@ -225,6 +236,13 @@ class ScoreBoardViewNotifier extends StateNotifier { ? secondInning.copyWith(id: secondId) : firstInning.copyWith(id: firstId), match: state.match!.copyWith( + teams: state.match!.teams + .map((e) => e.copyWith( + wicket: 0, + over: 0, + run: 0, + )) + .toList(), current_playing_team_id: state.match!.toss_decision == TossDecision.bat ? firstInning.team_id @@ -237,6 +255,24 @@ class ScoreBoardViewNotifier extends StateNotifier { } } + void onMatchOptionSelect(MatchOption option, bool contWithInjPlayer) { + state = state.copyWith(continueWithInjuredPlayers: contWithInjPlayer); + switch (option) { + case MatchOption.changeStriker: + _showStrikerSelectionDialog(); + case MatchOption.pauseScoring: + state = state.copyWith(showPauseScoringDialog: DateTime.now()); + case MatchOption.penaltyRun: + state = state.copyWith(showAddPenaltyRunDialog: DateTime.now()); + default: + return; + } + } + + void _showStrikerSelectionDialog() { + state = state.copyWith(showStrikerSelectionDialog: DateTime.now()); + } + void onScoreButtonTap(ScoreButton btn) { switch (btn) { case ScoreButton.zero: @@ -254,10 +290,13 @@ class ScoreBoardViewNotifier extends StateNotifier { case ScoreButton.fiveOrSeven: state = state.copyWith(showAddExtraDialogForFiveSeven: DateTime.now()); case ScoreButton.undo: - final lastBall = state.currentScoresList.lastOrNull; - if (lastBall?.over_number != state.overCount) { + final lastBall = state.currentScoresList.lastWhere((ball) => + ball.extras_type != ExtrasType.penaltyRun && + ball.wicket_type != WicketType.timedOut && + ball.wicket_type != WicketType.retired && + ball.wicket_type != WicketType.retiredHurt); + if (lastBall.over_number != state.overCount) { state = state.copyWith(invalidUndoToast: DateTime.now()); - return; } else { state = state.copyWith(showUndoBallConfirmationDialog: DateTime.now()); @@ -301,12 +340,19 @@ class ScoreBoardViewNotifier extends StateNotifier { ballCount = state.ballCount + 1; } + final nonStrikerId = state.batsMans + ?.firstWhere((element) => element.player.id != state.strikerId) + .player + .id ?? + "INVALID ID"; + final ball = BallScoreModel( inning_id: inningId ?? state.currentInning?.id ?? "INVALID ID", over_number: state.overCount, ball_number: ballCount, bowler_id: state.bowler?.player.id ?? "INVALID ID", batsman_id: state.strikerId ?? "INVALID ID", + non_striker_id: nonStrikerId, is_four: isFour, is_six: isSix, extras_awarded: extra, @@ -329,7 +375,7 @@ class ScoreBoardViewNotifier extends StateNotifier { : extra ?? 0)); if (wicketType != null) { - await onWicket(wicketType, playerOutId); + await _handleWicketAndOutPlayer(wicketType, playerOutId); } if (ball.inning_id != state.currentInning?.id && @@ -348,16 +394,16 @@ class ScoreBoardViewNotifier extends StateNotifier { ball.copyWith(id: id) ]); } - _updateInningScoreDetails(); + await _updateInningAndTeamScore(); if (switchStrike) { setOrSwitchStriker(); } - checkIfInningComplete(wicket: wicketType); + _checkIfInningComplete(wicket: wicketType); } - Future onWicket( + Future _handleWicketAndOutPlayer( WicketType wicketType, String? playerOutId, ) async { @@ -377,7 +423,8 @@ class ScoreBoardViewNotifier extends StateNotifier { status: wicketType == WicketType.retiredHurt ? PlayerStatus.injured : PlayerStatus.played); - updateMatchPlayerStatus(( + + await _updateMatchPlayerStatus(( teamId: state.currentInning?.team_id ?? "INVALID ID", players: [updatedPlayer] )); @@ -387,84 +434,14 @@ class ScoreBoardViewNotifier extends StateNotifier { } } - void checkIfInningComplete({WicketType? wicket}) { - final battingSquad = state.match?.teams - .where((element) => element.team.id == state.currentInning?.team_id) - .firstOrNull - ?.squad - .where((element) => - element.status == PlayerStatus.yetToPlay || - element.status == PlayerStatus.playing || - element.status == PlayerStatus.injured) - .toList(); - - final playing = battingSquad - ?.where((element) => element.status == PlayerStatus.playing) - .toList(); - - final yetToPlay = battingSquad - ?.where((element) => element.status == PlayerStatus.yetToPlay) - .toList(); - - final injured = battingSquad - ?.where((element) => element.status == PlayerStatus.injured) - .toList(); - - final totalBalls = (state.match?.number_of_over ?? 0) * 6; - final playedBalls = ((state.overCount - 1) * 6) + state.ballCount; - - final remainingBall = totalBalls - playedBalls; - - if (state.otherInning?.innings_status == InningStatus.finish && - (state.totalRuns > (state.otherInning?.total_runs ?? 0))) { - state = state.copyWith(showMatchCompleteDialog: DateTime.now()); - } else if (((playing?.length == 1) && - (yetToPlay?.isEmpty ?? true) && - (state.continueWithInjuredPlayers - ? injured?.isEmpty ?? true - : true)) || - remainingBall <= 0) { - // TODO: playWithInjuredPlayer - // all-out(inc. injured) OR all-overs-complete - if (state.otherInning?.innings_status == InningStatus.finish) { - state = state.copyWith(showMatchCompleteDialog: DateTime.now()); - } else { - state = state.copyWith(showInningCompleteDialog: DateTime.now()); - } - } else if ((playing?.length == 1) && - (yetToPlay?.isEmpty ?? true) && - (injured?.isNotEmpty ?? true) && - state.continueWithInjuredPlayers) { - // only injured player remaining - // TODO: injured player remaining flow - // ask user to continue with injured player - // if yes then select one of them - // if no complete the inning - } else { - List fairDeliveries = state.currentScoresList - .where((element) => (element.over_number == state.overCount && - element.extras_type != ExtrasType.noBall && - element.extras_type != ExtrasType.wide && - element.extras_type != ExtrasType.penaltyRun && - element.wicket_type != WicketType.retired && - element.wicket_type != WicketType.retiredHurt && - element.wicket_type != WicketType.timedOut)) - .toList(); - if (fairDeliveries.length == 6) { - state = state.copyWith(showOverCompleteDialog: DateTime.now()); - } else { - if (wicket != null) { - state = state.copyWith(showSelectBatsManSheet: DateTime.now()); - } - } - } - } - - Future _updateInningScoreDetails() async { + Future _updateInningAndTeamScore() async { try { + final overCount = + double.parse("${state.overCount - 1}.${state.ballCount}"); + await _inningService.updateInningScoreDetail( battingTeamInningId: state.currentInning?.id ?? "INVALID ID", - over: double.parse("${state.overCount}.${state.ballCount}"), + over: overCount, totalRun: state.totalRuns, bowlingTeamInningId: state.otherInning?.id ?? "INVALID ID", wicketCount: state.wicketCount, @@ -474,7 +451,7 @@ class ScoreBoardViewNotifier extends StateNotifier { matchId: state.match?.id ?? "INVALID ID", battingTeamId: state.currentInning?.team_id ?? "INVALID ID", totalRun: state.totalRuns, - over: double.parse("${state.overCount}.${state.ballCount}"), + over: overCount, bowlingTeamId: state.otherInning?.team_id ?? "INVALID ID", wicket: state.wicketCount, runs: state.otherInning?.total_runs); @@ -482,9 +459,7 @@ class ScoreBoardViewNotifier extends StateNotifier { final teams = state.match?.teams.toList(); teams?.map((e) { if (e.team.id == state.currentInning?.team_id) { - return e.copyWith( - over: double.parse("${state.overCount}.${state.ballCount}"), - run: state.totalRuns); + return e.copyWith(over: overCount, run: state.totalRuns); } else { return e.copyWith( wicket: state.wicketCount, run: state.otherInning?.total_runs); @@ -494,9 +469,8 @@ class ScoreBoardViewNotifier extends StateNotifier { state = state.copyWith( match: state.match?.copyWith(teams: teams ?? state.match?.teams ?? []), - currentInning: state.currentInning?.copyWith( - overs: double.parse("${state.overCount}.${state.ballCount}"), - total_runs: state.totalRuns), + currentInning: state.currentInning + ?.copyWith(overs: overCount, total_runs: state.totalRuns), otherInning: state.otherInning?.copyWith(total_wickets: state.wicketCount)); } catch (e) { @@ -508,28 +482,135 @@ class ScoreBoardViewNotifier extends StateNotifier { void setOrSwitchStriker({UserModel? batsMan}) { final player = batsMan ?? state.batsMans - ?.firstWhere((element) => element.player.id != state.strikerId) - .player; - state = state.copyWith(strikerId: player?.id); + ?.where((element) => element.player.id != state.strikerId) + .firstOrNull + ?.player; + state = state.copyWith( + strikerId: player?.id, + ); + } + + void _checkIfInningComplete({WicketType? wicket}) { + final allOut = _isAllOut(); + final allDeliveryDelivered = _isAllDeliveryDelivered(); + final targetAchieved = _isTargetAchieved(); + + if (allOut || allDeliveryDelivered || targetAchieved) { + // match or inning complete + if (_isMatchTied()) { + state = state.copyWith(showMatchCompleteDialog: DateTime.now()); + } else { + if (state.otherInning?.innings_status == InningStatus.finish) { + state = state.copyWith(showMatchCompleteDialog: DateTime.now()); + } else { + state = state.copyWith(showInningCompleteDialog: DateTime.now()); + } + } + } else { + List fairDeliveries = state.currentScoresList + .where((element) => (element.over_number == state.overCount && + element.extras_type != ExtrasType.noBall && + element.extras_type != ExtrasType.wide && + element.extras_type != ExtrasType.penaltyRun && + element.wicket_type != WicketType.retired && + element.wicket_type != WicketType.retiredHurt && + element.wicket_type != WicketType.timedOut)) + .toList(); + if (fairDeliveries.length == 6) { + // over complete + state = state.copyWith(showOverCompleteDialog: DateTime.now()); + } else { + if (wicket != null) { + // wicket on current_ball if current_ball is not last_ball_of_over + state = state.copyWith(showSelectBatsManSheet: DateTime.now()); + } + } + } + } + + bool _isAllOut() { + // yet_to_play == 0 && playing == 1 && (cont_with_inj ? injured == 0 : true) && wicket_count == (cont_with_inj ? total_wicket : total_wicket - injure_count) - 1 + final battingSquad = state.match?.teams + .where((element) => element.team.id == state.currentInning?.team_id) + .firstOrNull + ?.squad; + + int yetToPlayCount = 0; + int playingCount = 0; + int injuredCount = 0; + + battingSquad?.forEach((element) { + if (element.status == PlayerStatus.yetToPlay) { + yetToPlayCount += 1; + } else if (element.status == PlayerStatus.playing) { + playingCount += 1; + } else if (element.status == PlayerStatus.injured) { + injuredCount += 1; + } + }); + + final totalWicket = state.continueWithInjuredPlayers + ? (battingSquad?.length ?? 0) + : (battingSquad?.length ?? 0) - injuredCount; + return yetToPlayCount == 0 && + playingCount == 1 && + state.wicketCount == totalWicket - 1 && + (state.continueWithInjuredPlayers ? injuredCount == 0 : true); + } + + bool _isAllDeliveryDelivered() { + // fair_deliveries / 6 == number_of_over_decided + // number_of_total_ball == total_played_ball + final totalBalls = (state.match?.number_of_over ?? 0) * 6; + final playedBalls = ((state.overCount - 1) * 6) + state.ballCount; + + return playedBalls == totalBalls; + } + + bool _isTargetAchieved() { + // run >= target_run (other_teams_run + 1) + if (state.otherInning?.innings_status == InningStatus.yetToStart || + state.otherInning == null) { + return false; + } + + final targetRun = (state.otherInning!.total_runs ?? 0) + 1; + return state.totalRuns >= targetRun; + } + + bool _isMatchTied() { + // inning_complete and run == other_teams_run + final isInningComplete = _isAllOut() || _isAllDeliveryDelivered(); + if (state.otherInning?.innings_status == InningStatus.yetToStart || + state.otherInning == null) { + return false; + } + + return isInningComplete && + state.totalRuns == (state.otherInning!.total_runs ?? 0); } Future undoLastBall() async { try { - final lastBall = state.currentScoresList.lastOrNull; - if (lastBall?.over_number != state.overCount) { + final lastBall = _getDeliveredLastBall(); + if (lastBall.over_number != state.overCount) { return; } - await _ballScoreService.deleteBall(lastBall?.id ?? "INVALID ID"); - if (lastBall?.wicket_type != null) { + await _ballScoreService.deleteBall(lastBall.id ?? "INVALID ID"); + if (lastBall.wicket_type != null) { final battingTeam = state.match?.teams .where((element) => element.team.id == state.currentInning?.team_id) .firstOrNull ?.squad; final outPlayer = battingTeam?.firstWhere( - (element) => element.player.id == lastBall?.player_out_id); + (element) => element.player.id == lastBall.player_out_id); - final newBatsMan = state.batsMans?.elementAtOrNull(1); + final newBatsMan = state.batsMans + ?.where((element) => + element.player.id != lastBall.batsman_id && + element.player.id != lastBall.non_striker_id) + .firstOrNull; if (newBatsMan != null && outPlayer != null) { final updateList = [ outPlayer.copyWith(status: PlayerStatus.playing), @@ -542,53 +623,67 @@ class ScoreBoardViewNotifier extends StateNotifier { : newBatsMan.index) ]; - updateMatchPlayerStatus(( + await _updateMatchPlayerStatus(( teamId: state.currentInning?.team_id ?? "INVALID_ID", players: updateList )); final updatedBatsManList = state.batsMans?.toList(); - updatedBatsManList?.updateWhere( + final batsMen = updatedBatsManList?.updateWhere( where: (element) => element.player.id == newBatsMan.player.id, updated: (oldElement) => outPlayer, ); - state = state.copyWith(batsMans: updatedBatsManList); + state = state.copyWith(batsMans: batsMen); } } final updateList = state.currentScoresList.toList(); - updateList.removeWhere((element) => element.id == lastBall?.id); - - final (ballCount, overCount) = - (lastBall?.extras_type == ExtrasType.noBall || - lastBall?.extras_type == ExtrasType.wide) - ? (state.ballCount, state.overCount) - : state.ballCount == 0 - ? (5, state.overCount - 1) - : (state.ballCount - 1, state.overCount); + updateList.removeWhere((element) => element.id == lastBall.id); + state = state.copyWith( - currentScoresList: updateList, - ballCount: ballCount, - overCount: overCount, - wicketCount: lastBall?.wicket_type != null && - lastBall?.wicket_type != WicketType.retiredHurt - ? state.wicketCount - 1 - : state.wicketCount, - lastAssignedIndex: lastBall?.wicket_type != null - ? state.lastAssignedIndex - 1 - : state.lastAssignedIndex, - totalRuns: state.totalRuns - - ((lastBall?.extras_awarded ?? 0) + (lastBall?.runs_scored ?? 0)), - ); + currentScoresList: updateList, + ballCount: (lastBall.extras_type == ExtrasType.noBall || + lastBall.extras_type == ExtrasType.wide) + ? state.ballCount + : state.ballCount - 1, + wicketCount: lastBall.wicket_type != null && + lastBall.wicket_type != WicketType.retiredHurt + ? state.wicketCount - 1 + : state.wicketCount, + lastAssignedIndex: lastBall.wicket_type != null + ? state.lastAssignedIndex - 1 + : state.lastAssignedIndex, + totalRuns: state.totalRuns - + ((lastBall.extras_awarded ?? 0) + (lastBall.runs_scored ?? 0)), + strikerId: lastBall.wicket_type == null + ? lastBall.batsman_id + : state.strikerId); + + await _updateInningAndTeamScore(); + + if (!(state.batsMans?.map((e) => e.player.id).contains(state.strikerId) ?? + false)) { + _showStrikerSelectionDialog(); + } } catch (e) { debugPrint("ScoreBoardViewNotifier: error while undo last ball -> $e"); } } - Future updateMatchPlayerStatus( - ({String teamId, List players}) team) async { + BallScoreModel _getDeliveredLastBall() { + // last_ball that is delivered no matter legal or illegal, i.e exclude penalty-run, timed out, retired or retired hurt. + return state.currentScoresList.lastWhere((ball) => + ball.extras_type != ExtrasType.penaltyRun && + ball.wicket_type != WicketType.timedOut && + ball.wicket_type != WicketType.retired && + ball.wicket_type != WicketType.retiredHurt); + } + + Future _updateMatchPlayerStatus( + ({String teamId, List players}) team, + ) async { final teamRequest = AddMatchTeamRequest( team_id: team.teamId, squad: team.players @@ -602,15 +697,14 @@ class ScoreBoardViewNotifier extends StateNotifier { state.match?.id ?? "INVALID ID", teamRequest, ); - final matchTeams = state.match!.teams.toList(); - matchTeams.updateWhere( + final updatedMatchTeams = matchTeams.updateWhere( where: (element) => team.teamId == element.team.id, updated: (oldElement) { final teamSquadList = oldElement.squad.toList(); final newSquadList = team.players; - teamSquadList.updateWhere( + final updatedTeamSquad = teamSquadList.updateWhere( where: (element) => newSquadList.map((e) => e.player.id).contains(element.player.id), updated: (oldElement) { @@ -619,15 +713,12 @@ class ScoreBoardViewNotifier extends StateNotifier { }, ); - return oldElement.copyWith(squad: teamSquadList); + return oldElement.copyWith(squad: updatedTeamSquad); }, ); - state = state.copyWith(match: state.match?.copyWith(teams: matchTeams)); - } - - void _showStrikerSelectionDialog() { - state = state.copyWith(showStrikerSelectionDialog: DateTime.now()); + state = + state.copyWith(match: state.match?.copyWith(teams: updatedMatchTeams)); } Future startNextOver() async { @@ -648,7 +739,7 @@ class ScoreBoardViewNotifier extends StateNotifier { final batsMan = state.batsMans! .map((e) => e.copyWith(status: PlayerStatus.played)) .toList(); - updateMatchPlayerStatus(( + await _updateMatchPlayerStatus(( teamId: state.currentInning?.team_id ?? "INVALID ID", players: batsMan )); @@ -679,6 +770,7 @@ class ScoreBoardViewNotifier extends StateNotifier { currentScoresList: List.empty(), otherInning: swappedOtherInning, currentInning: swappedCurrentInning, + continueWithInjuredPlayers: true, match: state.match ?.copyWith(current_playing_team_id: swappedCurrentInning?.team_id), showSelectPlayerSheet: DateTime.now()); @@ -689,7 +781,7 @@ class ScoreBoardViewNotifier extends StateNotifier { var batsMan = state.batsMans! .map((e) => e.copyWith(status: PlayerStatus.played)) .toList(); - await updateMatchPlayerStatus(( + await _updateMatchPlayerStatus(( teamId: state.currentInning?.team_id ?? "INVALID ID", players: batsMan )); @@ -709,19 +801,8 @@ class ScoreBoardViewNotifier extends StateNotifier { pop: true); } - void onMatchOptionSelect(MatchOption option) { - switch (option) { - case MatchOption.changeStriker: - _showStrikerSelectionDialog(); - case MatchOption.pauseScoring: - state = state.copyWith(showPauseScoringDialog: DateTime.now()); - case MatchOption.penaltyRun: - state = state.copyWith(showAddPenaltyRunDialog: DateTime.now()); - } - } - Future onPauseScoring() async { - await _updateInningScoreDetails(); + await _updateInningAndTeamScore(); state = state.copyWith(pop: true); } @@ -736,17 +817,34 @@ class ScoreBoardViewNotifier extends StateNotifier { ); } - void setPlayers( - List<({String teamId, List players})> currentPlayers) { + void onReviewMatchResult(bool contWithInjPlayer) { + // func will be called only if injured player is remained and user disable that continue with injured player option + state = state.copyWith(continueWithInjuredPlayers: contWithInjPlayer); + + if (_isAllOut()) { + if (state.otherInning?.innings_status == InningStatus.finish) { + state = state.copyWith(showMatchCompleteDialog: DateTime.now()); + } else { + state = state.copyWith(showInningCompleteDialog: DateTime.now()); + } + } + + _checkIfInningComplete(); + } + + Future setPlayers({ + required List<({List players, String teamId})> currentPlayers, + required bool contWithInjPlayer, + }) async { + state = state.copyWith(continueWithInjuredPlayers: contWithInjPlayer); + MatchPlayer? bowler; - List? batsMans; + List? batsMen; var battingPlayer = currentPlayers - .toList() .where((element) => element.teamId == state.currentInning?.team_id) .firstOrNull; bowler = currentPlayers - .toList() .where((element) => element.teamId == state.otherInning?.team_id) .firstOrNull ?.players @@ -754,38 +852,35 @@ class ScoreBoardViewNotifier extends StateNotifier { if (battingPlayer != null) { final statusUpdatedSquad = battingPlayer.players; - for (int j = 0; j < statusUpdatedSquad.length; j++) { - var batsManIndex = state.lastAssignedIndex + 1; - if (statusUpdatedSquad.elementAt(j).index == null || - statusUpdatedSquad.elementAt(j).index == 0) { - statusUpdatedSquad[j] = statusUpdatedSquad - .elementAt(j) + for (int index = 0; index < statusUpdatedSquad.length; index++) { + int batsManIndex = state.lastAssignedIndex + 1; + + if (statusUpdatedSquad.elementAt(index).index == null || + statusUpdatedSquad.elementAt(index).index == 0) { + statusUpdatedSquad[index] = statusUpdatedSquad + .elementAt(index) .copyWith(index: batsManIndex, status: PlayerStatus.playing); - state = state.copyWith( - lastAssignedIndex: batsManIndex, - ); + state = state.copyWith(lastAssignedIndex: batsManIndex); } } - batsMans = statusUpdatedSquad; + batsMen = statusUpdatedSquad; battingPlayer = (teamId: battingPlayer.teamId, players: statusUpdatedSquad); + await _updateMatchPlayerStatus(battingPlayer); } + state = state.copyWith( bowler: bowler ?? state.bowler, - batsMans: batsMans != null - ? batsMans.length == 1 - ? [...?state.batsMans, batsMans.first] - : batsMans + batsMans: batsMen != null + ? batsMen.length == 1 + ? [...?state.batsMans, batsMen.first] + : batsMen : state.batsMans); if (!(state.batsMans?.map((e) => e.player.id).contains(state.strikerId) ?? false)) { _showStrikerSelectionDialog(); } - - if (battingPlayer != null) { - updateMatchPlayerStatus(battingPlayer); - } } } @@ -822,7 +917,7 @@ class ScoreBoardViewState with _$ScoreBoardViewState { @Default([]) List previousScoresList, @Default(false) bool loading, @Default(false) bool pop, - @Default(false) bool continueWithInjuredPlayers, + @Default(true) bool continueWithInjuredPlayers, @Default(0) int ballCount, @Default(1) int overCount, @Default(0) int totalRuns, @@ -881,7 +976,8 @@ enum ScoreButton { enum MatchOption { changeStriker, penaltyRun, - pauseScoring; + pauseScoring, + continueWithInjuredPlayer; String getTitle(BuildContext context) { switch (this) { @@ -891,6 +987,8 @@ enum MatchOption { return context.l10n.score_board_penalty_run_title; case MatchOption.pauseScoring: return context.l10n.score_board_pause_scoring_title; + case MatchOption.continueWithInjuredPlayer: + return context.l10n.score_board_continue_with_injured_player_title; } } } diff --git a/khelo/lib/ui/flow/score_board/score_board_view_model.freezed.dart b/khelo/lib/ui/flow/score_board/score_board_view_model.freezed.dart index de382c20..875a81ea 100644 --- a/khelo/lib/ui/flow/score_board/score_board_view_model.freezed.dart +++ b/khelo/lib/ui/flow/score_board/score_board_view_model.freezed.dart @@ -12,7 +12,7 @@ part of 'score_board_view_model.dart'; T _$identity(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 _$ScoreBoardViewState { diff --git a/khelo/lib/ui/flow/settings/edit_profile/edit_profile_view_model.freezed.dart b/khelo/lib/ui/flow/settings/edit_profile/edit_profile_view_model.freezed.dart index 0bdb25a1..18df485f 100644 --- a/khelo/lib/ui/flow/settings/edit_profile/edit_profile_view_model.freezed.dart +++ b/khelo/lib/ui/flow/settings/edit_profile/edit_profile_view_model.freezed.dart @@ -23,6 +23,7 @@ mixin _$EditProfileState { throw _privateConstructorUsedError; TextEditingController get locationController => throw _privateConstructorUsedError; + UserModel? get currentUser => throw _privateConstructorUsedError; String? get imageUrl => throw _privateConstructorUsedError; UserGender? get gender => throw _privateConstructorUsedError; BattingStyle? get battingStyle => throw _privateConstructorUsedError; @@ -32,7 +33,6 @@ mixin _$EditProfileState { bool get isImageUploading => throw _privateConstructorUsedError; bool get isSaved => throw _privateConstructorUsedError; bool get isSaveInProgress => throw _privateConstructorUsedError; - UserModel? get currentUser => throw _privateConstructorUsedError; @JsonKey(ignore: true) $EditProfileStateCopyWith get copyWith => @@ -50,6 +50,7 @@ abstract class $EditProfileStateCopyWith<$Res> { TextEditingController nameController, TextEditingController emailController, TextEditingController locationController, + UserModel? currentUser, String? imageUrl, UserGender? gender, BattingStyle? battingStyle, @@ -58,8 +59,7 @@ abstract class $EditProfileStateCopyWith<$Res> { bool isButtonEnable, bool isImageUploading, bool isSaved, - bool isSaveInProgress, - UserModel? currentUser}); + bool isSaveInProgress}); $UserModelCopyWith<$Res>? get currentUser; } @@ -81,6 +81,7 @@ class _$EditProfileStateCopyWithImpl<$Res, $Val extends EditProfileState> Object? nameController = null, Object? emailController = null, Object? locationController = null, + Object? currentUser = freezed, Object? imageUrl = freezed, Object? gender = freezed, Object? battingStyle = freezed, @@ -90,7 +91,6 @@ class _$EditProfileStateCopyWithImpl<$Res, $Val extends EditProfileState> Object? isImageUploading = null, Object? isSaved = null, Object? isSaveInProgress = null, - Object? currentUser = freezed, }) { return _then(_value.copyWith( dob: null == dob @@ -109,6 +109,10 @@ class _$EditProfileStateCopyWithImpl<$Res, $Val extends EditProfileState> ? _value.locationController : locationController // ignore: cast_nullable_to_non_nullable as TextEditingController, + currentUser: freezed == currentUser + ? _value.currentUser + : currentUser // ignore: cast_nullable_to_non_nullable + as UserModel?, imageUrl: freezed == imageUrl ? _value.imageUrl : imageUrl // ignore: cast_nullable_to_non_nullable @@ -145,10 +149,6 @@ class _$EditProfileStateCopyWithImpl<$Res, $Val extends EditProfileState> ? _value.isSaveInProgress : isSaveInProgress // ignore: cast_nullable_to_non_nullable as bool, - currentUser: freezed == currentUser - ? _value.currentUser - : currentUser // ignore: cast_nullable_to_non_nullable - as UserModel?, ) as $Val); } @@ -178,6 +178,7 @@ abstract class _$$EditProfileStateImplCopyWith<$Res> TextEditingController nameController, TextEditingController emailController, TextEditingController locationController, + UserModel? currentUser, String? imageUrl, UserGender? gender, BattingStyle? battingStyle, @@ -186,8 +187,7 @@ abstract class _$$EditProfileStateImplCopyWith<$Res> bool isButtonEnable, bool isImageUploading, bool isSaved, - bool isSaveInProgress, - UserModel? currentUser}); + bool isSaveInProgress}); @override $UserModelCopyWith<$Res>? get currentUser; @@ -208,6 +208,7 @@ class __$$EditProfileStateImplCopyWithImpl<$Res> Object? nameController = null, Object? emailController = null, Object? locationController = null, + Object? currentUser = freezed, Object? imageUrl = freezed, Object? gender = freezed, Object? battingStyle = freezed, @@ -217,7 +218,6 @@ class __$$EditProfileStateImplCopyWithImpl<$Res> Object? isImageUploading = null, Object? isSaved = null, Object? isSaveInProgress = null, - Object? currentUser = freezed, }) { return _then(_$EditProfileStateImpl( dob: null == dob @@ -236,6 +236,10 @@ class __$$EditProfileStateImplCopyWithImpl<$Res> ? _value.locationController : locationController // ignore: cast_nullable_to_non_nullable as TextEditingController, + currentUser: freezed == currentUser + ? _value.currentUser + : currentUser // ignore: cast_nullable_to_non_nullable + as UserModel?, imageUrl: freezed == imageUrl ? _value.imageUrl : imageUrl // ignore: cast_nullable_to_non_nullable @@ -272,10 +276,6 @@ class __$$EditProfileStateImplCopyWithImpl<$Res> ? _value.isSaveInProgress : isSaveInProgress // ignore: cast_nullable_to_non_nullable as bool, - currentUser: freezed == currentUser - ? _value.currentUser - : currentUser // ignore: cast_nullable_to_non_nullable - as UserModel?, )); } } @@ -288,6 +288,7 @@ class _$EditProfileStateImpl implements _EditProfileState { required this.nameController, required this.emailController, required this.locationController, + this.currentUser, this.imageUrl = null, this.gender = null, this.battingStyle = null, @@ -296,8 +297,7 @@ class _$EditProfileStateImpl implements _EditProfileState { this.isButtonEnable = false, this.isImageUploading = false, this.isSaved = false, - this.isSaveInProgress = false, - this.currentUser}); + this.isSaveInProgress = false}); @override final DateTime dob; @@ -308,6 +308,8 @@ class _$EditProfileStateImpl implements _EditProfileState { @override final TextEditingController locationController; @override + final UserModel? currentUser; + @override @JsonKey() final String? imageUrl; @override @@ -334,12 +336,10 @@ class _$EditProfileStateImpl implements _EditProfileState { @override @JsonKey() final bool isSaveInProgress; - @override - final UserModel? currentUser; @override String toString() { - return 'EditProfileState(dob: $dob, nameController: $nameController, emailController: $emailController, locationController: $locationController, imageUrl: $imageUrl, gender: $gender, battingStyle: $battingStyle, bowlingStyle: $bowlingStyle, playerRole: $playerRole, isButtonEnable: $isButtonEnable, isImageUploading: $isImageUploading, isSaved: $isSaved, isSaveInProgress: $isSaveInProgress, currentUser: $currentUser)'; + return 'EditProfileState(dob: $dob, nameController: $nameController, emailController: $emailController, locationController: $locationController, currentUser: $currentUser, imageUrl: $imageUrl, gender: $gender, battingStyle: $battingStyle, bowlingStyle: $bowlingStyle, playerRole: $playerRole, isButtonEnable: $isButtonEnable, isImageUploading: $isImageUploading, isSaved: $isSaved, isSaveInProgress: $isSaveInProgress)'; } @override @@ -354,6 +354,8 @@ class _$EditProfileStateImpl implements _EditProfileState { other.emailController == emailController) && (identical(other.locationController, locationController) || other.locationController == locationController) && + (identical(other.currentUser, currentUser) || + other.currentUser == currentUser) && (identical(other.imageUrl, imageUrl) || other.imageUrl == imageUrl) && (identical(other.gender, gender) || other.gender == gender) && @@ -369,9 +371,7 @@ class _$EditProfileStateImpl implements _EditProfileState { other.isImageUploading == isImageUploading) && (identical(other.isSaved, isSaved) || other.isSaved == isSaved) && (identical(other.isSaveInProgress, isSaveInProgress) || - other.isSaveInProgress == isSaveInProgress) && - (identical(other.currentUser, currentUser) || - other.currentUser == currentUser)); + other.isSaveInProgress == isSaveInProgress)); } @override @@ -381,6 +381,7 @@ class _$EditProfileStateImpl implements _EditProfileState { nameController, emailController, locationController, + currentUser, imageUrl, gender, battingStyle, @@ -389,8 +390,7 @@ class _$EditProfileStateImpl implements _EditProfileState { isButtonEnable, isImageUploading, isSaved, - isSaveInProgress, - currentUser); + isSaveInProgress); @JsonKey(ignore: true) @override @@ -406,6 +406,7 @@ abstract class _EditProfileState implements EditProfileState { required final TextEditingController nameController, required final TextEditingController emailController, required final TextEditingController locationController, + final UserModel? currentUser, final String? imageUrl, final UserGender? gender, final BattingStyle? battingStyle, @@ -414,8 +415,7 @@ abstract class _EditProfileState implements EditProfileState { final bool isButtonEnable, final bool isImageUploading, final bool isSaved, - final bool isSaveInProgress, - final UserModel? currentUser}) = _$EditProfileStateImpl; + final bool isSaveInProgress}) = _$EditProfileStateImpl; @override DateTime get dob; @@ -426,6 +426,8 @@ abstract class _EditProfileState implements EditProfileState { @override TextEditingController get locationController; @override + UserModel? get currentUser; + @override String? get imageUrl; @override UserGender? get gender; @@ -444,8 +446,6 @@ abstract class _EditProfileState implements EditProfileState { @override bool get isSaveInProgress; @override - UserModel? get currentUser; - @override @JsonKey(ignore: true) _$$EditProfileStateImplCopyWith<_$EditProfileStateImpl> get copyWith => throw _privateConstructorUsedError; diff --git a/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_view_model.freezed.dart b/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_view_model.freezed.dart index e2076fa9..fdc545f8 100644 --- a/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_view_model.freezed.dart +++ b/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_view_model.freezed.dart @@ -16,14 +16,14 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$PhoneVerificationState { + Object? get error => throw _privateConstructorUsedError; + String? get verificationId => throw _privateConstructorUsedError; bool get verifying => throw _privateConstructorUsedError; bool get enableVerify => throw _privateConstructorUsedError; bool get isVerificationComplete => throw _privateConstructorUsedError; bool get showErrorVerificationCodeText => throw _privateConstructorUsedError; - String? get verificationId => throw _privateConstructorUsedError; String get otp => throw _privateConstructorUsedError; Duration get activeResendDuration => throw _privateConstructorUsedError; - Object? get error => throw _privateConstructorUsedError; @JsonKey(ignore: true) $PhoneVerificationStateCopyWith get copyWith => @@ -37,14 +37,14 @@ abstract class $PhoneVerificationStateCopyWith<$Res> { _$PhoneVerificationStateCopyWithImpl<$Res, PhoneVerificationState>; @useResult $Res call( - {bool verifying, + {Object? error, + String? verificationId, + bool verifying, bool enableVerify, bool isVerificationComplete, bool showErrorVerificationCodeText, - String? verificationId, String otp, - Duration activeResendDuration, - Object? error}); + Duration activeResendDuration}); } /// @nodoc @@ -61,16 +61,21 @@ class _$PhoneVerificationStateCopyWithImpl<$Res, @pragma('vm:prefer-inline') @override $Res call({ + Object? error = freezed, + Object? verificationId = freezed, Object? verifying = null, Object? enableVerify = null, Object? isVerificationComplete = null, Object? showErrorVerificationCodeText = null, - Object? verificationId = freezed, Object? otp = null, Object? activeResendDuration = null, - Object? error = freezed, }) { return _then(_value.copyWith( + error: freezed == error ? _value.error : error, + verificationId: freezed == verificationId + ? _value.verificationId + : verificationId // ignore: cast_nullable_to_non_nullable + as String?, verifying: null == verifying ? _value.verifying : verifying // ignore: cast_nullable_to_non_nullable @@ -87,10 +92,6 @@ class _$PhoneVerificationStateCopyWithImpl<$Res, ? _value.showErrorVerificationCodeText : showErrorVerificationCodeText // ignore: cast_nullable_to_non_nullable as bool, - verificationId: freezed == verificationId - ? _value.verificationId - : verificationId // ignore: cast_nullable_to_non_nullable - as String?, otp: null == otp ? _value.otp : otp // ignore: cast_nullable_to_non_nullable @@ -99,7 +100,6 @@ class _$PhoneVerificationStateCopyWithImpl<$Res, ? _value.activeResendDuration : activeResendDuration // ignore: cast_nullable_to_non_nullable as Duration, - error: freezed == error ? _value.error : error, ) as $Val); } } @@ -114,14 +114,14 @@ abstract class _$$PhoneVerificationStateImplCopyWith<$Res> @override @useResult $Res call( - {bool verifying, + {Object? error, + String? verificationId, + bool verifying, bool enableVerify, bool isVerificationComplete, bool showErrorVerificationCodeText, - String? verificationId, String otp, - Duration activeResendDuration, - Object? error}); + Duration activeResendDuration}); } /// @nodoc @@ -137,16 +137,21 @@ class __$$PhoneVerificationStateImplCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ + Object? error = freezed, + Object? verificationId = freezed, Object? verifying = null, Object? enableVerify = null, Object? isVerificationComplete = null, Object? showErrorVerificationCodeText = null, - Object? verificationId = freezed, Object? otp = null, Object? activeResendDuration = null, - Object? error = freezed, }) { return _then(_$PhoneVerificationStateImpl( + error: freezed == error ? _value.error : error, + verificationId: freezed == verificationId + ? _value.verificationId + : verificationId // ignore: cast_nullable_to_non_nullable + as String?, verifying: null == verifying ? _value.verifying : verifying // ignore: cast_nullable_to_non_nullable @@ -163,10 +168,6 @@ class __$$PhoneVerificationStateImplCopyWithImpl<$Res> ? _value.showErrorVerificationCodeText : showErrorVerificationCodeText // ignore: cast_nullable_to_non_nullable as bool, - verificationId: freezed == verificationId - ? _value.verificationId - : verificationId // ignore: cast_nullable_to_non_nullable - as String?, otp: null == otp ? _value.otp : otp // ignore: cast_nullable_to_non_nullable @@ -175,7 +176,6 @@ class __$$PhoneVerificationStateImplCopyWithImpl<$Res> ? _value.activeResendDuration : activeResendDuration // ignore: cast_nullable_to_non_nullable as Duration, - error: freezed == error ? _value.error : error, )); } } @@ -184,15 +184,19 @@ class __$$PhoneVerificationStateImplCopyWithImpl<$Res> class _$PhoneVerificationStateImpl implements _PhoneVerificationState { const _$PhoneVerificationStateImpl( - {this.verifying = false, + {this.error, + this.verificationId, + this.verifying = false, this.enableVerify = false, this.isVerificationComplete = false, this.showErrorVerificationCodeText = false, - this.verificationId, this.otp = '', - this.activeResendDuration = const Duration(seconds: 30), - this.error}); + this.activeResendDuration = const Duration(seconds: 30)}); + @override + final Object? error; + @override + final String? verificationId; @override @JsonKey() final bool verifying; @@ -206,19 +210,15 @@ class _$PhoneVerificationStateImpl implements _PhoneVerificationState { @JsonKey() final bool showErrorVerificationCodeText; @override - final String? verificationId; - @override @JsonKey() final String otp; @override @JsonKey() final Duration activeResendDuration; - @override - final Object? error; @override String toString() { - return 'PhoneVerificationState(verifying: $verifying, enableVerify: $enableVerify, isVerificationComplete: $isVerificationComplete, showErrorVerificationCodeText: $showErrorVerificationCodeText, verificationId: $verificationId, otp: $otp, activeResendDuration: $activeResendDuration, error: $error)'; + return 'PhoneVerificationState(error: $error, verificationId: $verificationId, verifying: $verifying, enableVerify: $enableVerify, isVerificationComplete: $isVerificationComplete, showErrorVerificationCodeText: $showErrorVerificationCodeText, otp: $otp, activeResendDuration: $activeResendDuration)'; } @override @@ -226,6 +226,9 @@ class _$PhoneVerificationStateImpl implements _PhoneVerificationState { return identical(this, other) || (other.runtimeType == runtimeType && other is _$PhoneVerificationStateImpl && + const DeepCollectionEquality().equals(other.error, error) && + (identical(other.verificationId, verificationId) || + other.verificationId == verificationId) && (identical(other.verifying, verifying) || other.verifying == verifying) && (identical(other.enableVerify, enableVerify) || @@ -236,25 +239,22 @@ class _$PhoneVerificationStateImpl implements _PhoneVerificationState { showErrorVerificationCodeText) || other.showErrorVerificationCodeText == showErrorVerificationCodeText) && - (identical(other.verificationId, verificationId) || - other.verificationId == verificationId) && (identical(other.otp, otp) || other.otp == otp) && (identical(other.activeResendDuration, activeResendDuration) || - other.activeResendDuration == activeResendDuration) && - const DeepCollectionEquality().equals(other.error, error)); + other.activeResendDuration == activeResendDuration)); } @override int get hashCode => Object.hash( runtimeType, + const DeepCollectionEquality().hash(error), + verificationId, verifying, enableVerify, isVerificationComplete, showErrorVerificationCodeText, - verificationId, otp, - activeResendDuration, - const DeepCollectionEquality().hash(error)); + activeResendDuration); @JsonKey(ignore: true) @override @@ -266,15 +266,19 @@ class _$PhoneVerificationStateImpl implements _PhoneVerificationState { abstract class _PhoneVerificationState implements PhoneVerificationState { const factory _PhoneVerificationState( - {final bool verifying, + {final Object? error, + final String? verificationId, + final bool verifying, final bool enableVerify, final bool isVerificationComplete, final bool showErrorVerificationCodeText, - final String? verificationId, final String otp, - final Duration activeResendDuration, - final Object? error}) = _$PhoneVerificationStateImpl; + final Duration activeResendDuration}) = _$PhoneVerificationStateImpl; + @override + Object? get error; + @override + String? get verificationId; @override bool get verifying; @override @@ -284,14 +288,10 @@ abstract class _PhoneVerificationState implements PhoneVerificationState { @override bool get showErrorVerificationCodeText; @override - String? get verificationId; - @override String get otp; @override Duration get activeResendDuration; @override - Object? get error; - @override @JsonKey(ignore: true) _$$PhoneVerificationStateImplCopyWith<_$PhoneVerificationStateImpl> get copyWith => throw _privateConstructorUsedError; diff --git a/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_view_model.freezed.dart b/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_view_model.freezed.dart index 6ec86619..67fe0873 100644 --- a/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_view_model.freezed.dart +++ b/khelo/lib/ui/flow/sign_in/sign_in_with_phone/sign_in_with_phone_view_model.freezed.dart @@ -17,11 +17,11 @@ final _privateConstructorUsedError = UnsupportedError( /// @nodoc mixin _$SignInWithPhoneState { CountryCode get code => throw _privateConstructorUsedError; + Object? get error => throw _privateConstructorUsedError; + String? get verificationId => throw _privateConstructorUsedError; bool get verifying => throw _privateConstructorUsedError; bool get signInSuccess => throw _privateConstructorUsedError; - String? get verificationId => throw _privateConstructorUsedError; bool get enableBtn => throw _privateConstructorUsedError; - Object? get error => throw _privateConstructorUsedError; String get phone => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -37,11 +37,11 @@ abstract class $SignInWithPhoneStateCopyWith<$Res> { @useResult $Res call( {CountryCode code, + Object? error, + String? verificationId, bool verifying, bool signInSuccess, - String? verificationId, bool enableBtn, - Object? error, String phone}); } @@ -60,11 +60,11 @@ class _$SignInWithPhoneStateCopyWithImpl<$Res, @override $Res call({ Object? code = null, + Object? error = freezed, + Object? verificationId = freezed, Object? verifying = null, Object? signInSuccess = null, - Object? verificationId = freezed, Object? enableBtn = null, - Object? error = freezed, Object? phone = null, }) { return _then(_value.copyWith( @@ -72,6 +72,11 @@ class _$SignInWithPhoneStateCopyWithImpl<$Res, ? _value.code : code // ignore: cast_nullable_to_non_nullable as CountryCode, + error: freezed == error ? _value.error : error, + verificationId: freezed == verificationId + ? _value.verificationId + : verificationId // ignore: cast_nullable_to_non_nullable + as String?, verifying: null == verifying ? _value.verifying : verifying // ignore: cast_nullable_to_non_nullable @@ -80,15 +85,10 @@ class _$SignInWithPhoneStateCopyWithImpl<$Res, ? _value.signInSuccess : signInSuccess // ignore: cast_nullable_to_non_nullable as bool, - verificationId: freezed == verificationId - ? _value.verificationId - : verificationId // ignore: cast_nullable_to_non_nullable - as String?, enableBtn: null == enableBtn ? _value.enableBtn : enableBtn // ignore: cast_nullable_to_non_nullable as bool, - error: freezed == error ? _value.error : error, phone: null == phone ? _value.phone : phone // ignore: cast_nullable_to_non_nullable @@ -107,11 +107,11 @@ abstract class _$$SignInWithPhoneStateImplCopyWith<$Res> @useResult $Res call( {CountryCode code, + Object? error, + String? verificationId, bool verifying, bool signInSuccess, - String? verificationId, bool enableBtn, - Object? error, String phone}); } @@ -127,11 +127,11 @@ class __$$SignInWithPhoneStateImplCopyWithImpl<$Res> @override $Res call({ Object? code = null, + Object? error = freezed, + Object? verificationId = freezed, Object? verifying = null, Object? signInSuccess = null, - Object? verificationId = freezed, Object? enableBtn = null, - Object? error = freezed, Object? phone = null, }) { return _then(_$SignInWithPhoneStateImpl( @@ -139,6 +139,11 @@ class __$$SignInWithPhoneStateImplCopyWithImpl<$Res> ? _value.code : code // ignore: cast_nullable_to_non_nullable as CountryCode, + error: freezed == error ? _value.error : error, + verificationId: freezed == verificationId + ? _value.verificationId + : verificationId // ignore: cast_nullable_to_non_nullable + as String?, verifying: null == verifying ? _value.verifying : verifying // ignore: cast_nullable_to_non_nullable @@ -147,15 +152,10 @@ class __$$SignInWithPhoneStateImplCopyWithImpl<$Res> ? _value.signInSuccess : signInSuccess // ignore: cast_nullable_to_non_nullable as bool, - verificationId: freezed == verificationId - ? _value.verificationId - : verificationId // ignore: cast_nullable_to_non_nullable - as String?, enableBtn: null == enableBtn ? _value.enableBtn : enableBtn // ignore: cast_nullable_to_non_nullable as bool, - error: freezed == error ? _value.error : error, phone: null == phone ? _value.phone : phone // ignore: cast_nullable_to_non_nullable @@ -169,35 +169,35 @@ class __$$SignInWithPhoneStateImplCopyWithImpl<$Res> class _$SignInWithPhoneStateImpl implements _SignInWithPhoneState { const _$SignInWithPhoneStateImpl( {required this.code, + this.error, + this.verificationId, this.verifying = false, this.signInSuccess = false, - this.verificationId, this.enableBtn = false, - this.error, this.phone = ''}); @override final CountryCode code; @override + final Object? error; + @override + final String? verificationId; + @override @JsonKey() final bool verifying; @override @JsonKey() final bool signInSuccess; @override - final String? verificationId; - @override @JsonKey() final bool enableBtn; @override - final Object? error; - @override @JsonKey() final String phone; @override String toString() { - return 'SignInWithPhoneState(code: $code, verifying: $verifying, signInSuccess: $signInSuccess, verificationId: $verificationId, enableBtn: $enableBtn, error: $error, phone: $phone)'; + return 'SignInWithPhoneState(code: $code, error: $error, verificationId: $verificationId, verifying: $verifying, signInSuccess: $signInSuccess, enableBtn: $enableBtn, phone: $phone)'; } @override @@ -206,15 +206,15 @@ class _$SignInWithPhoneStateImpl implements _SignInWithPhoneState { (other.runtimeType == runtimeType && other is _$SignInWithPhoneStateImpl && (identical(other.code, code) || other.code == code) && + const DeepCollectionEquality().equals(other.error, error) && + (identical(other.verificationId, verificationId) || + other.verificationId == verificationId) && (identical(other.verifying, verifying) || other.verifying == verifying) && (identical(other.signInSuccess, signInSuccess) || other.signInSuccess == signInSuccess) && - (identical(other.verificationId, verificationId) || - other.verificationId == verificationId) && (identical(other.enableBtn, enableBtn) || other.enableBtn == enableBtn) && - const DeepCollectionEquality().equals(other.error, error) && (identical(other.phone, phone) || other.phone == phone)); } @@ -222,11 +222,11 @@ class _$SignInWithPhoneStateImpl implements _SignInWithPhoneState { int get hashCode => Object.hash( runtimeType, code, + const DeepCollectionEquality().hash(error), + verificationId, verifying, signInSuccess, - verificationId, enableBtn, - const DeepCollectionEquality().hash(error), phone); @JsonKey(ignore: true) @@ -241,26 +241,26 @@ class _$SignInWithPhoneStateImpl implements _SignInWithPhoneState { abstract class _SignInWithPhoneState implements SignInWithPhoneState { const factory _SignInWithPhoneState( {required final CountryCode code, + final Object? error, + final String? verificationId, final bool verifying, final bool signInSuccess, - final String? verificationId, final bool enableBtn, - final Object? error, final String phone}) = _$SignInWithPhoneStateImpl; @override CountryCode get code; @override + Object? get error; + @override + String? get verificationId; + @override bool get verifying; @override bool get signInSuccess; @override - String? get verificationId; - @override bool get enableBtn; @override - Object? get error; - @override String get phone; @override @JsonKey(ignore: true) diff --git a/khelo/lib/ui/flow/stats/user_match/match_detail_stat/match_detail_stat_screen.dart b/khelo/lib/ui/flow/stats/user_match/match_detail_stat/match_detail_stat_screen.dart index 7c477ee6..4e7ecc18 100644 --- a/khelo/lib/ui/flow/stats/user_match/match_detail_stat/match_detail_stat_screen.dart +++ b/khelo/lib/ui/flow/stats/user_match/match_detail_stat/match_detail_stat_screen.dart @@ -165,15 +165,13 @@ class _MatchDetailStatScreenState extends ConsumerState { } Widget _runScoredText(BuildContext context, int run, double over) { - final overCount = over != 0 ? over - 1 : over; return Text.rich(TextSpan( text: run.toString(), style: AppTextStyle.subtitle1 .copyWith(color: context.colorScheme.textPrimary, fontSize: 22), children: [ TextSpan( - text: context.l10n - .match_stat_in_over_text(overCount.toStringAsFixed(1)), + text: context.l10n.match_stat_in_over_text(over.toString()), style: AppTextStyle.body1 .copyWith(color: context.colorScheme.textPrimary), ), diff --git a/khelo/lib/ui/flow/stats/user_match/match_detail_stat/match_detail_stat_view_model.freezed.dart b/khelo/lib/ui/flow/stats/user_match/match_detail_stat/match_detail_stat_view_model.freezed.dart index 1135edfc..0b26d111 100644 --- a/khelo/lib/ui/flow/stats/user_match/match_detail_stat/match_detail_stat_view_model.freezed.dart +++ b/khelo/lib/ui/flow/stats/user_match/match_detail_stat/match_detail_stat_view_model.freezed.dart @@ -12,18 +12,18 @@ part of 'match_detail_stat_view_model.dart'; T _$identity(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 _$MatchDetailStatViewState { Object? get error => throw _privateConstructorUsedError; - bool get loading => throw _privateConstructorUsedError; String? get matchId => throw _privateConstructorUsedError; MatchModel? get match => throw _privateConstructorUsedError; InningModel? get firstInning => throw _privateConstructorUsedError; InningModel? get secondInning => throw _privateConstructorUsedError; List? get firstScore => throw _privateConstructorUsedError; List? get secondScore => throw _privateConstructorUsedError; + bool get loading => throw _privateConstructorUsedError; @JsonKey(ignore: true) $MatchDetailStatViewStateCopyWith get copyWith => @@ -38,13 +38,13 @@ abstract class $MatchDetailStatViewStateCopyWith<$Res> { @useResult $Res call( {Object? error, - bool loading, String? matchId, MatchModel? match, InningModel? firstInning, InningModel? secondInning, List? firstScore, - List? secondScore}); + List? secondScore, + bool loading}); $MatchModelCopyWith<$Res>? get match; $InningModelCopyWith<$Res>? get firstInning; @@ -66,20 +66,16 @@ class _$MatchDetailStatViewStateCopyWithImpl<$Res, @override $Res call({ Object? error = freezed, - Object? loading = null, Object? matchId = freezed, Object? match = freezed, Object? firstInning = freezed, Object? secondInning = freezed, Object? firstScore = freezed, Object? secondScore = freezed, + Object? loading = null, }) { return _then(_value.copyWith( error: freezed == error ? _value.error : error, - loading: null == loading - ? _value.loading - : loading // ignore: cast_nullable_to_non_nullable - as bool, matchId: freezed == matchId ? _value.matchId : matchId // ignore: cast_nullable_to_non_nullable @@ -104,6 +100,10 @@ class _$MatchDetailStatViewStateCopyWithImpl<$Res, ? _value.secondScore : secondScore // ignore: cast_nullable_to_non_nullable as List?, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, ) as $Val); } @@ -155,13 +155,13 @@ abstract class _$$MatchDetailStatViewStateImplCopyWith<$Res> @useResult $Res call( {Object? error, - bool loading, String? matchId, MatchModel? match, InningModel? firstInning, InningModel? secondInning, List? firstScore, - List? secondScore}); + List? secondScore, + bool loading}); @override $MatchModelCopyWith<$Res>? get match; @@ -185,20 +185,16 @@ class __$$MatchDetailStatViewStateImplCopyWithImpl<$Res> @override $Res call({ Object? error = freezed, - Object? loading = null, Object? matchId = freezed, Object? match = freezed, Object? firstInning = freezed, Object? secondInning = freezed, Object? firstScore = freezed, Object? secondScore = freezed, + Object? loading = null, }) { return _then(_$MatchDetailStatViewStateImpl( error: freezed == error ? _value.error : error, - loading: null == loading - ? _value.loading - : loading // ignore: cast_nullable_to_non_nullable - as bool, matchId: freezed == matchId ? _value.matchId : matchId // ignore: cast_nullable_to_non_nullable @@ -223,6 +219,10 @@ class __$$MatchDetailStatViewStateImplCopyWithImpl<$Res> ? _value._secondScore : secondScore // ignore: cast_nullable_to_non_nullable as List?, + loading: null == loading + ? _value.loading + : loading // ignore: cast_nullable_to_non_nullable + as bool, )); } } @@ -232,22 +232,19 @@ class __$$MatchDetailStatViewStateImplCopyWithImpl<$Res> class _$MatchDetailStatViewStateImpl implements _MatchDetailStatViewState { const _$MatchDetailStatViewStateImpl( {this.error, - this.loading = false, this.matchId, this.match, this.firstInning, this.secondInning, final List? firstScore, - final List? secondScore}) + final List? secondScore, + this.loading = false}) : _firstScore = firstScore, _secondScore = secondScore; @override final Object? error; @override - @JsonKey() - final bool loading; - @override final String? matchId; @override final MatchModel? match; @@ -275,9 +272,13 @@ class _$MatchDetailStatViewStateImpl implements _MatchDetailStatViewState { return EqualUnmodifiableListView(value); } + @override + @JsonKey() + final bool loading; + @override String toString() { - return 'MatchDetailStatViewState(error: $error, loading: $loading, matchId: $matchId, match: $match, firstInning: $firstInning, secondInning: $secondInning, firstScore: $firstScore, secondScore: $secondScore)'; + return 'MatchDetailStatViewState(error: $error, matchId: $matchId, match: $match, firstInning: $firstInning, secondInning: $secondInning, firstScore: $firstScore, secondScore: $secondScore, loading: $loading)'; } @override @@ -286,7 +287,6 @@ class _$MatchDetailStatViewStateImpl implements _MatchDetailStatViewState { (other.runtimeType == runtimeType && other is _$MatchDetailStatViewStateImpl && const DeepCollectionEquality().equals(other.error, error) && - (identical(other.loading, loading) || other.loading == loading) && (identical(other.matchId, matchId) || other.matchId == matchId) && (identical(other.match, match) || other.match == match) && (identical(other.firstInning, firstInning) || @@ -296,20 +296,21 @@ class _$MatchDetailStatViewStateImpl implements _MatchDetailStatViewState { const DeepCollectionEquality() .equals(other._firstScore, _firstScore) && const DeepCollectionEquality() - .equals(other._secondScore, _secondScore)); + .equals(other._secondScore, _secondScore) && + (identical(other.loading, loading) || other.loading == loading)); } @override int get hashCode => Object.hash( runtimeType, const DeepCollectionEquality().hash(error), - loading, matchId, match, firstInning, secondInning, const DeepCollectionEquality().hash(_firstScore), - const DeepCollectionEquality().hash(_secondScore)); + const DeepCollectionEquality().hash(_secondScore), + loading); @JsonKey(ignore: true) @override @@ -321,21 +322,18 @@ class _$MatchDetailStatViewStateImpl implements _MatchDetailStatViewState { abstract class _MatchDetailStatViewState implements MatchDetailStatViewState { const factory _MatchDetailStatViewState( - {final Object? error, - final bool loading, - final String? matchId, - final MatchModel? match, - final InningModel? firstInning, - final InningModel? secondInning, - final List? firstScore, - final List? secondScore}) = - _$MatchDetailStatViewStateImpl; + {final Object? error, + final String? matchId, + final MatchModel? match, + final InningModel? firstInning, + final InningModel? secondInning, + final List? firstScore, + final List? secondScore, + final bool loading}) = _$MatchDetailStatViewStateImpl; @override Object? get error; @override - bool get loading; - @override String? get matchId; @override MatchModel? get match; @@ -348,6 +346,8 @@ abstract class _MatchDetailStatViewState implements MatchDetailStatViewState { @override List? get secondScore; @override + bool get loading; + @override @JsonKey(ignore: true) _$$MatchDetailStatViewStateImplCopyWith<_$MatchDetailStatViewStateImpl> get copyWith => throw _privateConstructorUsedError; diff --git a/khelo/lib/ui/flow/stats/user_match/user_match_list_screen.dart b/khelo/lib/ui/flow/stats/user_match/user_match_list_screen.dart index 2b858027..85aa82e4 100644 --- a/khelo/lib/ui/flow/stats/user_match/user_match_list_screen.dart +++ b/khelo/lib/ui/flow/stats/user_match/user_match_list_screen.dart @@ -3,7 +3,9 @@ import 'package:data/api/team/team_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:khelo/components/image_avatar.dart'; +import 'package:khelo/components/won_by_message_text.dart'; import 'package:khelo/domain/extensions/context_extensions.dart'; +import 'package:khelo/domain/extensions/data_model_extensions/match_model_extension.dart'; import 'package:khelo/domain/extensions/enum_extensions.dart'; import 'package:khelo/domain/formatter/date_formatter.dart'; import 'package:khelo/ui/app_route.dart'; @@ -27,17 +29,27 @@ class UserMatchListScreen extends ConsumerWidget { } Widget _body(BuildContext context, UserMatchListState state) { - return ListView.separated( - padding: const EdgeInsets.only(bottom: 50, top: 24), - itemBuilder: (context, index) { - return _matchListCell(context, state.matches.elementAt(index)); - }, - separatorBuilder: (context, index) { - return const SizedBox( - height: 16, - ); - }, - itemCount: state.matches.length); + if (state.matches.isNotEmpty) { + return ListView.separated( + padding: const EdgeInsets.only(bottom: 50, top: 24), + itemBuilder: (context, index) { + return _matchListCell(context, state.matches.elementAt(index)); + }, + separatorBuilder: (context, index) { + return const SizedBox( + height: 16, + ); + }, + itemCount: state.matches.length); + } else { + return Center( + child: Text( + context.l10n.match_list_no_match_yet_title, + style: AppTextStyle.subtitle1 + .copyWith(color: context.colorScheme.textPrimary), + ), + ); + } } Widget _matchListCell(BuildContext context, MatchModel match) { @@ -111,55 +123,15 @@ class UserMatchListScreen extends ConsumerWidget { } Widget _winnerMessageText(BuildContext context, MatchModel match) { - final firstTeam = match.toss_decision == TossDecision.bat - ? match.teams - .firstWhere((element) => element.team.id == match.toss_winner_id) - : match.teams - .firstWhere((element) => element.team.id != match.toss_winner_id); - final secondTeam = match.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 _messageText(context, teamName, runDifference, - context.l10n.score_board_runs_dot_title); + final winSummary = match.getWinnerSummary(context); + if (match.match_status == MatchStatus.finish && winSummary != null) { + return WonByMessageText( + teamName: winSummary.teamName, + difference: winSummary.difference, + trailingText: winSummary.wonByText, + ); } else { - // second batting team won - final teamName = secondTeam.team.name; - - final wicketDifference = - secondTeam.squad.length - (firstTeam.wicket ?? 0); - - return _messageText(context, teamName, wicketDifference, - context.l10n.score_board_wickets_dot_title); + return const SizedBox(); } } - - Widget _messageText( - BuildContext context, - String? teamName, - int difference, - String trailingText, - ) { - return Text.rich(TextSpan( - text: "$teamName", - style: - AppTextStyle.subtitle2.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, - ), - ])); - } } diff --git a/khelo/lib/ui/flow/stats/user_match/user_match_list_view_model.freezed.dart b/khelo/lib/ui/flow/stats/user_match/user_match_list_view_model.freezed.dart index d3957176..822fc4aa 100644 --- a/khelo/lib/ui/flow/stats/user_match/user_match_list_view_model.freezed.dart +++ b/khelo/lib/ui/flow/stats/user_match/user_match_list_view_model.freezed.dart @@ -12,7 +12,7 @@ part of 'user_match_list_view_model.dart'; T _$identity(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 _$UserMatchListState { diff --git a/khelo/lib/ui/flow/team/add_team/add_team_view_model.dart b/khelo/lib/ui/flow/team/add_team/add_team_view_model.dart index 72da6878..0cd9312c 100644 --- a/khelo/lib/ui/flow/team/add_team/add_team_view_model.dart +++ b/khelo/lib/ui/flow/team/add_team/add_team_view_model.dart @@ -121,7 +121,7 @@ class AddTeamViewNotifier extends StateNotifier { players: players.map((e) => e.id).toList(), created_at: state.editTeam?.created_at ?? DateTime.now()); - await _teamService.updateTeam(team); + final newTeamId = await _teamService.updateTeam(team); if (previousImageUrl != null) { await deleteUnusedImage(previousImageUrl); @@ -139,7 +139,7 @@ class AddTeamViewNotifier extends StateNotifier { state = state.copyWith(isAddInProgress: false, isPop: true); } else { final teamModel = TeamModel( - id: state.editTeam?.id, + id: newTeamId, name: name, name_lowercase: name.caseAndSpaceInsensitive, profile_img_url: state.imageUrl, diff --git a/khelo/lib/ui/flow/team/add_team/add_team_view_model.freezed.dart b/khelo/lib/ui/flow/team/add_team/add_team_view_model.freezed.dart index 29f8bc83..6a2e728a 100644 --- a/khelo/lib/ui/flow/team/add_team/add_team_view_model.freezed.dart +++ b/khelo/lib/ui/flow/team/add_team/add_team_view_model.freezed.dart @@ -20,6 +20,11 @@ mixin _$AddTeamState { throw _privateConstructorUsedError; TextEditingController get locationController => throw _privateConstructorUsedError; + String? get imageUrl => throw _privateConstructorUsedError; + bool? get isNameAvailable => throw _privateConstructorUsedError; + TeamModel? get team => throw _privateConstructorUsedError; + TeamModel? get editTeam => throw _privateConstructorUsedError; + UserModel? get currentUser => throw _privateConstructorUsedError; bool get isImageUploading => throw _privateConstructorUsedError; bool get isAddMeCheckBoxEnable => throw _privateConstructorUsedError; bool get checkingForAvailability => throw _privateConstructorUsedError; @@ -27,11 +32,6 @@ mixin _$AddTeamState { bool get isAddInProgress => throw _privateConstructorUsedError; bool get isPop => throw _privateConstructorUsedError; List get teamMembers => throw _privateConstructorUsedError; - String? get imageUrl => throw _privateConstructorUsedError; - bool? get isNameAvailable => throw _privateConstructorUsedError; - TeamModel? get team => throw _privateConstructorUsedError; - TeamModel? get editTeam => throw _privateConstructorUsedError; - UserModel? get currentUser => throw _privateConstructorUsedError; @JsonKey(ignore: true) $AddTeamStateCopyWith get copyWith => @@ -47,18 +47,18 @@ abstract class $AddTeamStateCopyWith<$Res> { $Res call( {TextEditingController nameController, TextEditingController locationController, + String? imageUrl, + bool? isNameAvailable, + TeamModel? team, + TeamModel? editTeam, + UserModel? currentUser, bool isImageUploading, bool isAddMeCheckBoxEnable, bool checkingForAvailability, bool isAddBtnEnable, bool isAddInProgress, bool isPop, - List teamMembers, - String? imageUrl, - bool? isNameAvailable, - TeamModel? team, - TeamModel? editTeam, - UserModel? currentUser}); + List teamMembers}); $TeamModelCopyWith<$Res>? get team; $TeamModelCopyWith<$Res>? get editTeam; @@ -80,6 +80,11 @@ class _$AddTeamStateCopyWithImpl<$Res, $Val extends AddTeamState> $Res call({ Object? nameController = null, Object? locationController = null, + Object? imageUrl = freezed, + Object? isNameAvailable = freezed, + Object? team = freezed, + Object? editTeam = freezed, + Object? currentUser = freezed, Object? isImageUploading = null, Object? isAddMeCheckBoxEnable = null, Object? checkingForAvailability = null, @@ -87,11 +92,6 @@ class _$AddTeamStateCopyWithImpl<$Res, $Val extends AddTeamState> Object? isAddInProgress = null, Object? isPop = null, Object? teamMembers = null, - Object? imageUrl = freezed, - Object? isNameAvailable = freezed, - Object? team = freezed, - Object? editTeam = freezed, - Object? currentUser = freezed, }) { return _then(_value.copyWith( nameController: null == nameController @@ -102,6 +102,26 @@ class _$AddTeamStateCopyWithImpl<$Res, $Val extends AddTeamState> ? _value.locationController : locationController // ignore: cast_nullable_to_non_nullable as TextEditingController, + imageUrl: freezed == imageUrl + ? _value.imageUrl + : imageUrl // ignore: cast_nullable_to_non_nullable + as String?, + isNameAvailable: freezed == isNameAvailable + ? _value.isNameAvailable + : isNameAvailable // ignore: cast_nullable_to_non_nullable + as bool?, + team: freezed == team + ? _value.team + : team // ignore: cast_nullable_to_non_nullable + as TeamModel?, + editTeam: freezed == editTeam + ? _value.editTeam + : editTeam // ignore: cast_nullable_to_non_nullable + as TeamModel?, + currentUser: freezed == currentUser + ? _value.currentUser + : currentUser // ignore: cast_nullable_to_non_nullable + as UserModel?, isImageUploading: null == isImageUploading ? _value.isImageUploading : isImageUploading // ignore: cast_nullable_to_non_nullable @@ -130,26 +150,6 @@ class _$AddTeamStateCopyWithImpl<$Res, $Val extends AddTeamState> ? _value.teamMembers : teamMembers // ignore: cast_nullable_to_non_nullable as List, - imageUrl: freezed == imageUrl - ? _value.imageUrl - : imageUrl // ignore: cast_nullable_to_non_nullable - as String?, - isNameAvailable: freezed == isNameAvailable - ? _value.isNameAvailable - : isNameAvailable // ignore: cast_nullable_to_non_nullable - as bool?, - team: freezed == team - ? _value.team - : team // ignore: cast_nullable_to_non_nullable - as TeamModel?, - editTeam: freezed == editTeam - ? _value.editTeam - : editTeam // ignore: cast_nullable_to_non_nullable - as TeamModel?, - currentUser: freezed == currentUser - ? _value.currentUser - : currentUser // ignore: cast_nullable_to_non_nullable - as UserModel?, ) as $Val); } @@ -201,18 +201,18 @@ abstract class _$$AddTeamStateImplCopyWith<$Res> $Res call( {TextEditingController nameController, TextEditingController locationController, + String? imageUrl, + bool? isNameAvailable, + TeamModel? team, + TeamModel? editTeam, + UserModel? currentUser, bool isImageUploading, bool isAddMeCheckBoxEnable, bool checkingForAvailability, bool isAddBtnEnable, bool isAddInProgress, bool isPop, - List teamMembers, - String? imageUrl, - bool? isNameAvailable, - TeamModel? team, - TeamModel? editTeam, - UserModel? currentUser}); + List teamMembers}); @override $TeamModelCopyWith<$Res>? get team; @@ -235,6 +235,11 @@ class __$$AddTeamStateImplCopyWithImpl<$Res> $Res call({ Object? nameController = null, Object? locationController = null, + Object? imageUrl = freezed, + Object? isNameAvailable = freezed, + Object? team = freezed, + Object? editTeam = freezed, + Object? currentUser = freezed, Object? isImageUploading = null, Object? isAddMeCheckBoxEnable = null, Object? checkingForAvailability = null, @@ -242,11 +247,6 @@ class __$$AddTeamStateImplCopyWithImpl<$Res> Object? isAddInProgress = null, Object? isPop = null, Object? teamMembers = null, - Object? imageUrl = freezed, - Object? isNameAvailable = freezed, - Object? team = freezed, - Object? editTeam = freezed, - Object? currentUser = freezed, }) { return _then(_$AddTeamStateImpl( nameController: null == nameController @@ -257,6 +257,26 @@ class __$$AddTeamStateImplCopyWithImpl<$Res> ? _value.locationController : locationController // ignore: cast_nullable_to_non_nullable as TextEditingController, + imageUrl: freezed == imageUrl + ? _value.imageUrl + : imageUrl // ignore: cast_nullable_to_non_nullable + as String?, + isNameAvailable: freezed == isNameAvailable + ? _value.isNameAvailable + : isNameAvailable // ignore: cast_nullable_to_non_nullable + as bool?, + team: freezed == team + ? _value.team + : team // ignore: cast_nullable_to_non_nullable + as TeamModel?, + editTeam: freezed == editTeam + ? _value.editTeam + : editTeam // ignore: cast_nullable_to_non_nullable + as TeamModel?, + currentUser: freezed == currentUser + ? _value.currentUser + : currentUser // ignore: cast_nullable_to_non_nullable + as UserModel?, isImageUploading: null == isImageUploading ? _value.isImageUploading : isImageUploading // ignore: cast_nullable_to_non_nullable @@ -285,26 +305,6 @@ class __$$AddTeamStateImplCopyWithImpl<$Res> ? _value._teamMembers : teamMembers // ignore: cast_nullable_to_non_nullable as List, - imageUrl: freezed == imageUrl - ? _value.imageUrl - : imageUrl // ignore: cast_nullable_to_non_nullable - as String?, - isNameAvailable: freezed == isNameAvailable - ? _value.isNameAvailable - : isNameAvailable // ignore: cast_nullable_to_non_nullable - as bool?, - team: freezed == team - ? _value.team - : team // ignore: cast_nullable_to_non_nullable - as TeamModel?, - editTeam: freezed == editTeam - ? _value.editTeam - : editTeam // ignore: cast_nullable_to_non_nullable - as TeamModel?, - currentUser: freezed == currentUser - ? _value.currentUser - : currentUser // ignore: cast_nullable_to_non_nullable - as UserModel?, )); } } @@ -315,18 +315,18 @@ class _$AddTeamStateImpl implements _AddTeamState { const _$AddTeamStateImpl( {required this.nameController, required this.locationController, + this.imageUrl, + this.isNameAvailable, + this.team, + this.editTeam, + this.currentUser, this.isImageUploading = false, this.isAddMeCheckBoxEnable = true, this.checkingForAvailability = false, this.isAddBtnEnable = false, this.isAddInProgress = false, this.isPop = false, - final List teamMembers = const [], - this.imageUrl, - this.isNameAvailable, - this.team, - this.editTeam, - this.currentUser}) + final List teamMembers = const []}) : _teamMembers = teamMembers; @override @@ -334,6 +334,16 @@ class _$AddTeamStateImpl implements _AddTeamState { @override final TextEditingController locationController; @override + final String? imageUrl; + @override + final bool? isNameAvailable; + @override + final TeamModel? team; + @override + final TeamModel? editTeam; + @override + final UserModel? currentUser; + @override @JsonKey() final bool isImageUploading; @override @@ -360,20 +370,9 @@ class _$AddTeamStateImpl implements _AddTeamState { return EqualUnmodifiableListView(_teamMembers); } - @override - final String? imageUrl; - @override - final bool? isNameAvailable; - @override - final TeamModel? team; - @override - final TeamModel? editTeam; - @override - final UserModel? currentUser; - @override String toString() { - return 'AddTeamState(nameController: $nameController, locationController: $locationController, isImageUploading: $isImageUploading, isAddMeCheckBoxEnable: $isAddMeCheckBoxEnable, checkingForAvailability: $checkingForAvailability, isAddBtnEnable: $isAddBtnEnable, isAddInProgress: $isAddInProgress, isPop: $isPop, teamMembers: $teamMembers, imageUrl: $imageUrl, isNameAvailable: $isNameAvailable, team: $team, editTeam: $editTeam, currentUser: $currentUser)'; + return 'AddTeamState(nameController: $nameController, locationController: $locationController, imageUrl: $imageUrl, isNameAvailable: $isNameAvailable, team: $team, editTeam: $editTeam, currentUser: $currentUser, isImageUploading: $isImageUploading, isAddMeCheckBoxEnable: $isAddMeCheckBoxEnable, checkingForAvailability: $checkingForAvailability, isAddBtnEnable: $isAddBtnEnable, isAddInProgress: $isAddInProgress, isPop: $isPop, teamMembers: $teamMembers)'; } @override @@ -385,6 +384,15 @@ class _$AddTeamStateImpl implements _AddTeamState { other.nameController == nameController) && (identical(other.locationController, locationController) || other.locationController == locationController) && + (identical(other.imageUrl, imageUrl) || + other.imageUrl == imageUrl) && + (identical(other.isNameAvailable, isNameAvailable) || + other.isNameAvailable == isNameAvailable) && + (identical(other.team, team) || other.team == team) && + (identical(other.editTeam, editTeam) || + other.editTeam == editTeam) && + (identical(other.currentUser, currentUser) || + other.currentUser == currentUser) && (identical(other.isImageUploading, isImageUploading) || other.isImageUploading == isImageUploading) && (identical(other.isAddMeCheckBoxEnable, isAddMeCheckBoxEnable) || @@ -398,16 +406,7 @@ class _$AddTeamStateImpl implements _AddTeamState { other.isAddInProgress == isAddInProgress) && (identical(other.isPop, isPop) || other.isPop == isPop) && const DeepCollectionEquality() - .equals(other._teamMembers, _teamMembers) && - (identical(other.imageUrl, imageUrl) || - other.imageUrl == imageUrl) && - (identical(other.isNameAvailable, isNameAvailable) || - other.isNameAvailable == isNameAvailable) && - (identical(other.team, team) || other.team == team) && - (identical(other.editTeam, editTeam) || - other.editTeam == editTeam) && - (identical(other.currentUser, currentUser) || - other.currentUser == currentUser)); + .equals(other._teamMembers, _teamMembers)); } @override @@ -415,18 +414,18 @@ class _$AddTeamStateImpl implements _AddTeamState { runtimeType, nameController, locationController, + imageUrl, + isNameAvailable, + team, + editTeam, + currentUser, isImageUploading, isAddMeCheckBoxEnable, checkingForAvailability, isAddBtnEnable, isAddInProgress, isPop, - const DeepCollectionEquality().hash(_teamMembers), - imageUrl, - isNameAvailable, - team, - editTeam, - currentUser); + const DeepCollectionEquality().hash(_teamMembers)); @JsonKey(ignore: true) @override @@ -439,24 +438,34 @@ abstract class _AddTeamState implements AddTeamState { const factory _AddTeamState( {required final TextEditingController nameController, required final TextEditingController locationController, + final String? imageUrl, + final bool? isNameAvailable, + final TeamModel? team, + final TeamModel? editTeam, + final UserModel? currentUser, final bool isImageUploading, final bool isAddMeCheckBoxEnable, final bool checkingForAvailability, final bool isAddBtnEnable, final bool isAddInProgress, final bool isPop, - final List teamMembers, - final String? imageUrl, - final bool? isNameAvailable, - final TeamModel? team, - final TeamModel? editTeam, - final UserModel? currentUser}) = _$AddTeamStateImpl; + final List teamMembers}) = _$AddTeamStateImpl; @override TextEditingController get nameController; @override TextEditingController get locationController; @override + String? get imageUrl; + @override + bool? get isNameAvailable; + @override + TeamModel? get team; + @override + TeamModel? get editTeam; + @override + UserModel? get currentUser; + @override bool get isImageUploading; @override bool get isAddMeCheckBoxEnable; @@ -471,16 +480,6 @@ abstract class _AddTeamState implements AddTeamState { @override List get teamMembers; @override - String? get imageUrl; - @override - bool? get isNameAvailable; - @override - TeamModel? get team; - @override - TeamModel? get editTeam; - @override - UserModel? get currentUser; - @override @JsonKey(ignore: true) _$$AddTeamStateImplCopyWith<_$AddTeamStateImpl> get copyWith => throw _privateConstructorUsedError; diff --git a/khelo/lib/ui/flow/team/add_team_member/add_team_member_screen.dart b/khelo/lib/ui/flow/team/add_team_member/add_team_member_screen.dart index 2869cfad..c69652be 100644 --- a/khelo/lib/ui/flow/team/add_team_member/add_team_member_screen.dart +++ b/khelo/lib/ui/flow/team/add_team_member/add_team_member_screen.dart @@ -48,7 +48,7 @@ class AddTeamMemberScreen extends ConsumerWidget { ) : IconButton( onPressed: () { - notifier.addPlayersToTeam(team.id ?? "INVALID ID"); + notifier.addPlayersToTeam(team.id); }, icon: Icon( Icons.check, diff --git a/khelo/lib/ui/flow/team/add_team_member/add_team_member_view_model.dart b/khelo/lib/ui/flow/team/add_team_member/add_team_member_view_model.dart index 6e24243f..d5d72520 100644 --- a/khelo/lib/ui/flow/team/add_team_member/add_team_member_view_model.dart +++ b/khelo/lib/ui/flow/team/add_team_member/add_team_member_view_model.dart @@ -52,7 +52,11 @@ class AddTeamMemberViewNotifier extends StateNotifier { state = state.copyWith(selectedUsers: updatedList); } - Future addPlayersToTeam(String id) async { + Future addPlayersToTeam(String? id) async { + if (id == null) { + return; + } + state = state.copyWith(isAddInProgress: true); try { await _teamService.addPlayersToTeam( diff --git a/khelo/lib/ui/flow/team/add_team_member/add_team_member_view_model.freezed.dart b/khelo/lib/ui/flow/team/add_team_member/add_team_member_view_model.freezed.dart index 1b0523b0..c0b83fd7 100644 --- a/khelo/lib/ui/flow/team/add_team_member/add_team_member_view_model.freezed.dart +++ b/khelo/lib/ui/flow/team/add_team_member/add_team_member_view_model.freezed.dart @@ -18,9 +18,9 @@ final _privateConstructorUsedError = UnsupportedError( mixin _$AddTeamMemberState { TextEditingController get searchController => throw _privateConstructorUsedError; + Object? get error => throw _privateConstructorUsedError; List get searchedUsers => throw _privateConstructorUsedError; List get selectedUsers => throw _privateConstructorUsedError; - Object? get error => throw _privateConstructorUsedError; bool get isAdded => throw _privateConstructorUsedError; bool get isAddInProgress => throw _privateConstructorUsedError; @@ -37,9 +37,9 @@ abstract class $AddTeamMemberStateCopyWith<$Res> { @useResult $Res call( {TextEditingController searchController, + Object? error, List searchedUsers, List selectedUsers, - Object? error, bool isAdded, bool isAddInProgress}); } @@ -58,9 +58,9 @@ class _$AddTeamMemberStateCopyWithImpl<$Res, $Val extends AddTeamMemberState> @override $Res call({ Object? searchController = null, + Object? error = freezed, Object? searchedUsers = null, Object? selectedUsers = null, - Object? error = freezed, Object? isAdded = null, Object? isAddInProgress = null, }) { @@ -69,6 +69,7 @@ class _$AddTeamMemberStateCopyWithImpl<$Res, $Val extends AddTeamMemberState> ? _value.searchController : searchController // ignore: cast_nullable_to_non_nullable as TextEditingController, + error: freezed == error ? _value.error : error, searchedUsers: null == searchedUsers ? _value.searchedUsers : searchedUsers // ignore: cast_nullable_to_non_nullable @@ -77,7 +78,6 @@ class _$AddTeamMemberStateCopyWithImpl<$Res, $Val extends AddTeamMemberState> ? _value.selectedUsers : selectedUsers // ignore: cast_nullable_to_non_nullable as List, - error: freezed == error ? _value.error : error, isAdded: null == isAdded ? _value.isAdded : isAdded // ignore: cast_nullable_to_non_nullable @@ -100,9 +100,9 @@ abstract class _$$AddTeamMemberStateImplCopyWith<$Res> @useResult $Res call( {TextEditingController searchController, + Object? error, List searchedUsers, List selectedUsers, - Object? error, bool isAdded, bool isAddInProgress}); } @@ -119,9 +119,9 @@ class __$$AddTeamMemberStateImplCopyWithImpl<$Res> @override $Res call({ Object? searchController = null, + Object? error = freezed, Object? searchedUsers = null, Object? selectedUsers = null, - Object? error = freezed, Object? isAdded = null, Object? isAddInProgress = null, }) { @@ -130,6 +130,7 @@ class __$$AddTeamMemberStateImplCopyWithImpl<$Res> ? _value.searchController : searchController // ignore: cast_nullable_to_non_nullable as TextEditingController, + error: freezed == error ? _value.error : error, searchedUsers: null == searchedUsers ? _value._searchedUsers : searchedUsers // ignore: cast_nullable_to_non_nullable @@ -138,7 +139,6 @@ class __$$AddTeamMemberStateImplCopyWithImpl<$Res> ? _value._selectedUsers : selectedUsers // ignore: cast_nullable_to_non_nullable as List, - error: freezed == error ? _value.error : error, isAdded: null == isAdded ? _value.isAdded : isAdded // ignore: cast_nullable_to_non_nullable @@ -156,9 +156,9 @@ class __$$AddTeamMemberStateImplCopyWithImpl<$Res> class _$AddTeamMemberStateImpl implements _AddTeamMemberState { const _$AddTeamMemberStateImpl( {required this.searchController, + this.error, final List searchedUsers = const [], final List selectedUsers = const [], - this.error, this.isAdded = false, this.isAddInProgress = false}) : _searchedUsers = searchedUsers, @@ -166,6 +166,8 @@ class _$AddTeamMemberStateImpl implements _AddTeamMemberState { @override final TextEditingController searchController; + @override + final Object? error; final List _searchedUsers; @override @JsonKey() @@ -184,8 +186,6 @@ class _$AddTeamMemberStateImpl implements _AddTeamMemberState { return EqualUnmodifiableListView(_selectedUsers); } - @override - final Object? error; @override @JsonKey() final bool isAdded; @@ -195,7 +195,7 @@ class _$AddTeamMemberStateImpl implements _AddTeamMemberState { @override String toString() { - return 'AddTeamMemberState(searchController: $searchController, searchedUsers: $searchedUsers, selectedUsers: $selectedUsers, error: $error, isAdded: $isAdded, isAddInProgress: $isAddInProgress)'; + return 'AddTeamMemberState(searchController: $searchController, error: $error, searchedUsers: $searchedUsers, selectedUsers: $selectedUsers, isAdded: $isAdded, isAddInProgress: $isAddInProgress)'; } @override @@ -205,11 +205,11 @@ class _$AddTeamMemberStateImpl implements _AddTeamMemberState { other is _$AddTeamMemberStateImpl && (identical(other.searchController, searchController) || other.searchController == searchController) && + const DeepCollectionEquality().equals(other.error, error) && const DeepCollectionEquality() .equals(other._searchedUsers, _searchedUsers) && const DeepCollectionEquality() .equals(other._selectedUsers, _selectedUsers) && - const DeepCollectionEquality().equals(other.error, error) && (identical(other.isAdded, isAdded) || other.isAdded == isAdded) && (identical(other.isAddInProgress, isAddInProgress) || other.isAddInProgress == isAddInProgress)); @@ -219,9 +219,9 @@ class _$AddTeamMemberStateImpl implements _AddTeamMemberState { int get hashCode => Object.hash( runtimeType, searchController, + const DeepCollectionEquality().hash(error), const DeepCollectionEquality().hash(_searchedUsers), const DeepCollectionEquality().hash(_selectedUsers), - const DeepCollectionEquality().hash(error), isAdded, isAddInProgress); @@ -236,21 +236,21 @@ class _$AddTeamMemberStateImpl implements _AddTeamMemberState { abstract class _AddTeamMemberState implements AddTeamMemberState { const factory _AddTeamMemberState( {required final TextEditingController searchController, + final Object? error, final List searchedUsers, final List selectedUsers, - final Object? error, final bool isAdded, final bool isAddInProgress}) = _$AddTeamMemberStateImpl; @override TextEditingController get searchController; @override + Object? get error; + @override List get searchedUsers; @override List get selectedUsers; @override - Object? get error; - @override bool get isAdded; @override bool get isAddInProgress; diff --git a/khelo/lib/ui/flow/team/detail/components/team_detail_match_content.dart b/khelo/lib/ui/flow/team/detail/components/team_detail_match_content.dart index bc440421..b82840d6 100644 --- a/khelo/lib/ui/flow/team/detail/components/team_detail_match_content.dart +++ b/khelo/lib/ui/flow/team/detail/components/team_detail_match_content.dart @@ -24,13 +24,14 @@ class TeamDetailMatchContent extends ConsumerWidget { context.l10n.team_detail_empty_match_title, textAlign: TextAlign.center, style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), + .copyWith(color: context.colorScheme.textPrimary, fontSize: 20), ), ), ); } - return Column( + return ListView( + padding: const EdgeInsets.symmetric(horizontal: 16), children: [ const SizedBox( height: 24, diff --git a/khelo/lib/ui/flow/team/detail/components/team_detail_member_content.dart b/khelo/lib/ui/flow/team/detail/components/team_detail_member_content.dart index 74b4f3b8..0fff2c24 100644 --- a/khelo/lib/ui/flow/team/detail/components/team_detail_member_content.dart +++ b/khelo/lib/ui/flow/team/detail/components/team_detail_member_content.dart @@ -29,7 +29,8 @@ class TeamDetailMemberContent extends ConsumerWidget { ); } - return Column( + return ListView( + padding: const EdgeInsets.symmetric(horizontal: 16), children: [ const SizedBox( height: 24, diff --git a/khelo/lib/ui/flow/team/detail/components/team_detail_stat_content.dart b/khelo/lib/ui/flow/team/detail/components/team_detail_stat_content.dart index 7b7bc926..8f665996 100644 --- a/khelo/lib/ui/flow/team/detail/components/team_detail_stat_content.dart +++ b/khelo/lib/ui/flow/team/detail/components/team_detail_stat_content.dart @@ -24,7 +24,7 @@ class TeamDetailStatContent extends ConsumerWidget { context.l10n.team_detail_empty_stat_title, textAlign: TextAlign.center, style: AppTextStyle.subtitle1 - .copyWith(color: context.colorScheme.textPrimary), + .copyWith(color: context.colorScheme.textPrimary, fontSize: 20), ), ), ); @@ -34,7 +34,8 @@ class TeamDetailStatContent extends ConsumerWidget { } Widget _content(BuildContext context, TeamDetailState state) { - return Column( + return ListView( + padding: const EdgeInsets.symmetric(horizontal: 16), children: [ const SizedBox(height: 24), _matchPlayedCount(context, state), @@ -46,13 +47,13 @@ class TeamDetailStatContent extends ConsumerWidget { _averageCountView( context, context.l10n.team_detail_batting_average_title, - "${_calculateTeamBattingAverage(state)}", + _calculateTeamBattingAverage(state).toStringAsFixed(2), ), const SizedBox(height: 16), _averageCountView( context, context.l10n.team_detail_bowling_average_title, - "${_calculateTeamBowlingAverage(state)}", + _calculateTeamBowlingAverage(state).toStringAsFixed(2), ), const SizedBox(height: 16), _highestAndLowestRunCount(context, state), 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 45a47c40..b87c4716 100644 --- a/khelo/lib/ui/flow/team/detail/team_detail_screen.dart +++ b/khelo/lib/ui/flow/team/detail/team_detail_screen.dart @@ -11,7 +11,6 @@ import 'package:style/animations/on_tap_scale.dart'; import 'package:style/extensions/context_extensions.dart'; import 'package:style/indicator/progress_indicator.dart'; import 'package:style/text/app_text_style.dart'; -import 'package:style/page_views/expandable_page_view.dart'; import 'components/team_detail_match_content.dart'; import 'components/team_detail_stat_content.dart'; @@ -67,75 +66,74 @@ class _TeamDetailScreenState extends ConsumerState { child: AppProgressIndicator(), ); } - return ListView( - padding: context.mediaQueryPadding + - const EdgeInsets.symmetric(horizontal: 16), - children: [ - _teamProfileView(context, state), - _content(context), - ], + return Padding( + padding: context.mediaQueryPadding, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + _teamProfileView(context, state), + _tabView(context), + _content(context), + ], + ), ); } Widget _teamProfileView(BuildContext context, TeamDetailState state) { - return Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - // profile view - ImageAvatar( - initial: state.team?.name[0].toUpperCase() ?? "?", - imageUrl: state.team?.profile_img_url, - size: 90, - ), - const SizedBox( - width: 16, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text(state.team?.name ?? "", - style: AppTextStyle.header4 - .copyWith(color: context.colorScheme.textPrimary)), - Text(state.team?.city ?? "", - style: AppTextStyle.subtitle2 - .copyWith(color: context.colorScheme.textPrimary)), - Text( - DateFormat.yMMMd() - .format(state.team?.created_at ?? DateTime.now()), - style: AppTextStyle.subtitle2 - .copyWith(color: context.colorScheme.textPrimary)), - ], - ), - ], - ), - const SizedBox( - height: 16, - ), - const Divider(), - ], + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + // profile view + ImageAvatar( + initial: state.team?.name[0].toUpperCase() ?? "?", + imageUrl: state.team?.profile_img_url, + size: 90, + ), + const SizedBox( + width: 16, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text(state.team?.name ?? "", + style: AppTextStyle.header4 + .copyWith(color: context.colorScheme.textPrimary)), + Text(state.team?.city ?? "", + style: AppTextStyle.subtitle2 + .copyWith(color: context.colorScheme.textPrimary)), + Text( + DateFormat.yMMMd() + .format(state.team?.created_at ?? DateTime.now()), + style: AppTextStyle.subtitle2 + .copyWith(color: context.colorScheme.textPrimary)), + ], + ), + ], + ), + const SizedBox( + height: 16, + ), + const Divider(), + ], + ), ); } Widget _content(BuildContext context) { - return Column( - children: [ - _tabView(context), - ExpandablePageView( - itemCount: _tabs.length, - controller: _controller, - itemBuilder: (context, index) { - return _tabs[index]; - }, - onPageChanged: (index) { - setState(() { - notifier.onTabChange(index); - }); - }, - ), - ], + return Expanded( + child: PageView( + controller: _controller, + children: _tabs, + onPageChanged: (index) { + notifier.onTabChange(index); + setState(() {}); + }, + ), ); } diff --git a/khelo/lib/ui/flow/team/detail/team_detail_view_model.freezed.dart b/khelo/lib/ui/flow/team/detail/team_detail_view_model.freezed.dart index adff1d00..f1057319 100644 --- a/khelo/lib/ui/flow/team/detail/team_detail_view_model.freezed.dart +++ b/khelo/lib/ui/flow/team/detail/team_detail_view_model.freezed.dart @@ -12,7 +12,7 @@ part of 'team_detail_view_model.dart'; T _$identity(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 _$TeamDetailState { diff --git a/khelo/lib/ui/flow/team/search_team/search_team_view_model.freezed.dart b/khelo/lib/ui/flow/team/search_team/search_team_view_model.freezed.dart index 8ef7bd13..c13ac9d2 100644 --- a/khelo/lib/ui/flow/team/search_team/search_team_view_model.freezed.dart +++ b/khelo/lib/ui/flow/team/search_team/search_team_view_model.freezed.dart @@ -18,11 +18,11 @@ final _privateConstructorUsedError = UnsupportedError( mixin _$SearchTeamState { TextEditingController get searchController => throw _privateConstructorUsedError; + Object? get error => throw _privateConstructorUsedError; + TeamModel? get selectedTeam => throw _privateConstructorUsedError; List get searchResults => throw _privateConstructorUsedError; List get userTeams => throw _privateConstructorUsedError; - TeamModel? get selectedTeam => throw _privateConstructorUsedError; bool get loading => throw _privateConstructorUsedError; - Object? get error => throw _privateConstructorUsedError; @JsonKey(ignore: true) $SearchTeamStateCopyWith get copyWith => @@ -37,11 +37,11 @@ abstract class $SearchTeamStateCopyWith<$Res> { @useResult $Res call( {TextEditingController searchController, + Object? error, + TeamModel? selectedTeam, List searchResults, List userTeams, - TeamModel? selectedTeam, - bool loading, - Object? error}); + bool loading}); $TeamModelCopyWith<$Res>? get selectedTeam; } @@ -60,17 +60,22 @@ class _$SearchTeamStateCopyWithImpl<$Res, $Val extends SearchTeamState> @override $Res call({ Object? searchController = null, + Object? error = freezed, + Object? selectedTeam = freezed, Object? searchResults = null, Object? userTeams = null, - Object? selectedTeam = freezed, Object? loading = null, - Object? error = freezed, }) { return _then(_value.copyWith( searchController: null == searchController ? _value.searchController : searchController // ignore: cast_nullable_to_non_nullable as TextEditingController, + error: freezed == error ? _value.error : error, + selectedTeam: freezed == selectedTeam + ? _value.selectedTeam + : selectedTeam // ignore: cast_nullable_to_non_nullable + as TeamModel?, searchResults: null == searchResults ? _value.searchResults : searchResults // ignore: cast_nullable_to_non_nullable @@ -79,15 +84,10 @@ class _$SearchTeamStateCopyWithImpl<$Res, $Val extends SearchTeamState> ? _value.userTeams : userTeams // ignore: cast_nullable_to_non_nullable as List, - selectedTeam: freezed == selectedTeam - ? _value.selectedTeam - : selectedTeam // ignore: cast_nullable_to_non_nullable - as TeamModel?, loading: null == loading ? _value.loading : loading // ignore: cast_nullable_to_non_nullable as bool, - error: freezed == error ? _value.error : error, ) as $Val); } @@ -114,11 +114,11 @@ abstract class _$$SearchTeamStateImplCopyWith<$Res> @useResult $Res call( {TextEditingController searchController, + Object? error, + TeamModel? selectedTeam, List searchResults, List userTeams, - TeamModel? selectedTeam, - bool loading, - Object? error}); + bool loading}); @override $TeamModelCopyWith<$Res>? get selectedTeam; @@ -136,17 +136,22 @@ class __$$SearchTeamStateImplCopyWithImpl<$Res> @override $Res call({ Object? searchController = null, + Object? error = freezed, + Object? selectedTeam = freezed, Object? searchResults = null, Object? userTeams = null, - Object? selectedTeam = freezed, Object? loading = null, - Object? error = freezed, }) { return _then(_$SearchTeamStateImpl( searchController: null == searchController ? _value.searchController : searchController // ignore: cast_nullable_to_non_nullable as TextEditingController, + error: freezed == error ? _value.error : error, + selectedTeam: freezed == selectedTeam + ? _value.selectedTeam + : selectedTeam // ignore: cast_nullable_to_non_nullable + as TeamModel?, searchResults: null == searchResults ? _value._searchResults : searchResults // ignore: cast_nullable_to_non_nullable @@ -155,15 +160,10 @@ class __$$SearchTeamStateImplCopyWithImpl<$Res> ? _value._userTeams : userTeams // ignore: cast_nullable_to_non_nullable as List, - selectedTeam: freezed == selectedTeam - ? _value.selectedTeam - : selectedTeam // ignore: cast_nullable_to_non_nullable - as TeamModel?, loading: null == loading ? _value.loading : loading // ignore: cast_nullable_to_non_nullable as bool, - error: freezed == error ? _value.error : error, )); } } @@ -173,16 +173,20 @@ class __$$SearchTeamStateImplCopyWithImpl<$Res> class _$SearchTeamStateImpl implements _SearchTeamState { const _$SearchTeamStateImpl( {required this.searchController, + this.error, + this.selectedTeam, final List searchResults = const [], final List userTeams = const [], - this.selectedTeam, - this.loading = false, - this.error}) + this.loading = false}) : _searchResults = searchResults, _userTeams = userTeams; @override final TextEditingController searchController; + @override + final Object? error; + @override + final TeamModel? selectedTeam; final List _searchResults; @override @JsonKey() @@ -201,17 +205,13 @@ class _$SearchTeamStateImpl implements _SearchTeamState { return EqualUnmodifiableListView(_userTeams); } - @override - final TeamModel? selectedTeam; @override @JsonKey() final bool loading; - @override - final Object? error; @override String toString() { - return 'SearchTeamState(searchController: $searchController, searchResults: $searchResults, userTeams: $userTeams, selectedTeam: $selectedTeam, loading: $loading, error: $error)'; + return 'SearchTeamState(searchController: $searchController, error: $error, selectedTeam: $selectedTeam, searchResults: $searchResults, userTeams: $userTeams, loading: $loading)'; } @override @@ -221,25 +221,25 @@ class _$SearchTeamStateImpl implements _SearchTeamState { other is _$SearchTeamStateImpl && (identical(other.searchController, searchController) || other.searchController == searchController) && + const DeepCollectionEquality().equals(other.error, error) && + (identical(other.selectedTeam, selectedTeam) || + other.selectedTeam == selectedTeam) && const DeepCollectionEquality() .equals(other._searchResults, _searchResults) && const DeepCollectionEquality() .equals(other._userTeams, _userTeams) && - (identical(other.selectedTeam, selectedTeam) || - other.selectedTeam == selectedTeam) && - (identical(other.loading, loading) || other.loading == loading) && - const DeepCollectionEquality().equals(other.error, error)); + (identical(other.loading, loading) || other.loading == loading)); } @override int get hashCode => Object.hash( runtimeType, searchController, + const DeepCollectionEquality().hash(error), + selectedTeam, const DeepCollectionEquality().hash(_searchResults), const DeepCollectionEquality().hash(_userTeams), - selectedTeam, - loading, - const DeepCollectionEquality().hash(error)); + loading); @JsonKey(ignore: true) @override @@ -252,25 +252,25 @@ class _$SearchTeamStateImpl implements _SearchTeamState { abstract class _SearchTeamState implements SearchTeamState { const factory _SearchTeamState( {required final TextEditingController searchController, + final Object? error, + final TeamModel? selectedTeam, final List searchResults, final List userTeams, - final TeamModel? selectedTeam, - final bool loading, - final Object? error}) = _$SearchTeamStateImpl; + final bool loading}) = _$SearchTeamStateImpl; @override TextEditingController get searchController; @override + Object? get error; + @override + TeamModel? get selectedTeam; + @override List get searchResults; @override List get userTeams; @override - TeamModel? get selectedTeam; - @override bool get loading; @override - Object? get error; - @override @JsonKey(ignore: true) _$$SearchTeamStateImplCopyWith<_$SearchTeamStateImpl> get copyWith => throw _privateConstructorUsedError;