Skip to content

Commit

Permalink
Merge pull request #73 from canopas/Mayank/fix-match-detail
Browse files Browse the repository at this point in the history
Fix match detail
  • Loading branch information
cp-mayank authored Jul 10, 2024
2 parents 2bf1835 + ea68c60 commit 295e21a
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CommentaryBallSummary extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
_ballNumberView(context),
Expand All @@ -42,7 +42,10 @@ class CommentaryBallSummary extends StatelessWidget {
.copyWith(color: context.colorScheme.textDisabled)
: AppTextStyle.body1
.copyWith(color: context.colorScheme.textDisabled)),
if (showBallScore) ...[BallScoreView(ball: ball, size: 24)]
if (showBallScore) ...[
const SizedBox(height: 4),
BallScoreView(ball: ball, size: 24)
]
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CommentaryOverOverview extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
margin: const EdgeInsets.symmetric(vertical: 16),
color: context.colorScheme.containerLow,
child: Column(
children: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:data/api/ball_score/ball_score_model.dart';
import 'package:data/api/team/team_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:khelo/components/empty_screen.dart';
import 'package:khelo/components/error_screen.dart';
Expand Down Expand Up @@ -69,32 +67,41 @@ class MatchDetailCommentaryView extends ConsumerWidget {
final nextOverSummary = state.overList.elementAtOrNull(index + 1);
if (nextOverSummary != null &&
nextOverSummary.overNumber != overSummary.overNumber) {
children.add(BowlerSummaryView(
bowlerSummary: nextOverSummary.bowlerStatAtStart,
isForBowlerIntro: true,
children.add(Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: BowlerSummaryView(
bowlerSummary: nextOverSummary.bowlerStatAtStart,
isForBowlerIntro: true,
),
));
children.add(const SizedBox(height: 24));
}

if ((overSummary.balls.lastOrNull?.isLegalDelivery() ?? false) &&
overSummary.balls.lastOrNull?.ball_number == 6 &&
nextOverSummary?.inning_id == overSummary.inning_id) {
children
.add(CommentaryOverOverview(overSummary: overSummary, team: team));
children.add(const SizedBox(height: 24));
} else if (nextOverSummary != null &&
nextOverSummary.inning_id != overSummary.inning_id) {
children.add(_inningOverview(context,
teamName: team?.name ?? "", targetRun: overSummary.totalRuns + 1));
children.addAll([
_inningOverview(context,
teamName: team?.name ?? "", targetRun: overSummary.totalRuns + 1),
CommentaryOverOverview(overSummary: overSummary, team: team),
]);
}

for (final ball in overSummary.balls.reversed) {
children.add(CommentaryBallSummary(
ball: ball,
overSummary: overSummary,
showBallScore: false,
));
children.add(const SizedBox(height: 8));
children.addAll([
CommentaryBallSummary(
ball: ball,
overSummary: overSummary,
showBallScore:
ball.is_four || ball.is_six || ball.wicket_taker_id != null,
),
if (ball != overSummary.balls.first) ...[
Divider(color: context.colorScheme.outline),
],
]);
}
}
return children;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ class MatchDetailScorecardView extends ConsumerWidget {
MatchDetailTabViewNotifier notifier,
MatchDetailTabState state,
) {
List<List<int>> powerPlays = [
if (state.match?.power_play_overs1.isNotEmpty ?? false)
state.match!.power_play_overs1,
if (state.match?.power_play_overs2.isNotEmpty ?? false)
state.match!.power_play_overs2,
if (state.match?.power_play_overs3.isNotEmpty ?? false)
state.match!.power_play_overs3,
];
final groupOversByInnings = groupOversByInning(state.overList);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand All @@ -65,9 +74,9 @@ class MatchDetailScorecardView extends ConsumerWidget {
padding: context.mediaQueryPadding +
EdgeInsets.only(
top: state.match?.matchResult == null ? 16 : 0, bottom: 16),
itemCount: groupOversByInning(state.overList).length,
itemCount: groupOversByInnings.length,
itemBuilder: (context, index) {
final inningOvers = groupOversByInning(state.overList)[index];
final inningOvers = groupOversByInnings[index];
final overs = inningOvers.lastOrNull;
final batsmen = _getBatsmen(inningOvers);
final bowler = _getBowlers(inningOvers);
Expand All @@ -78,20 +87,11 @@ class MatchDetailScorecardView extends ConsumerWidget {
?.squad
.toList();

List<List<int>> powerPlays = [
if (state.match?.power_play_overs1.isNotEmpty ?? false)
state.match!.power_play_overs1,
if (state.match?.power_play_overs2.isNotEmpty ?? false)
state.match!.power_play_overs2,
if (state.match?.power_play_overs3.isNotEmpty ?? false)
state.match!.power_play_overs3,
];

return _teamTitleView(context,
teamName: _getTeamNameByTeamId(state, overs?.team_id ?? ""),
over: overs ?? const OverSummary(),
initiallyExpanded: state.expandedTeamScorecard
.contains(overs?.team_id ?? ""),
.contains(inningOvers.first.team_id),
children: [
_dataTable(context, batsmen: batsmen),
..._buildMatchTotalView(context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,19 @@ class MatchDetailSquadView extends ConsumerWidget {
color: context.colorScheme.outline,
),
));
children.add(Row(
children: [
Expanded(
child: _playerProfileView(context,
user: firstTeamPlayer, captainId: firstTeamCaptainId)),
Expanded(
child: _playerProfileView(context,
user: secondTeamPlayer,
isFirstCell: false,
captainId: secondTeamCaptainId))
],
children.add(IntrinsicHeight(
child: Row(
children: [
_playerProfileView(context,
user: firstTeamPlayer, captainId: firstTeamCaptainId),
VerticalDivider(color: context.colorScheme.outline),
_playerProfileView(context,
user: secondTeamPlayer,
isFirstCell: false,
isSecondTeam: true,
captainId: secondTeamCaptainId)
],
),
));
}
return children;
Expand Down Expand Up @@ -178,56 +180,68 @@ class MatchDetailSquadView extends ConsumerWidget {
BuildContext context, {
UserModel? user,
bool isFirstCell = true,
bool isSecondTeam = false,
String? captainId,
}) {
if (user == null) {
return const SizedBox(
height: 0,
return const Expanded(
child: SizedBox(
height: 0,
),
);
}
bool isCaptain = user.id == captainId;
return IntrinsicHeight(
child: Container(
padding: const EdgeInsets.only(left: 16, top: 16, bottom: 16),
decoration: BoxDecoration(
border: BorderDirectional(
end: BorderSide(
color: isFirstCell
? context.colorScheme.outline
: Colors.transparent))),
child: OnTapScale(
onTap: () => UserDetailSheet.show(context, user),
return Expanded(
child: OnTapScale(
onTap: () => UserDetailSheet.show(context, user),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
ImageAvatar(
initial: user.nameInitial,
imageUrl: user.profile_img_url,
size: 40,
),
const SizedBox(width: 8),
if (!isSecondTeam) ...[
ImageAvatar(
initial: user.nameInitial,
imageUrl: user.profile_img_url,
size: 40,
),
const SizedBox(width: 8),
],
Expanded(
child: Padding(
padding: const EdgeInsets.only(right: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
user.name == null
? context.l10n.common_anonymous_title
: "${user.name}${isCaptain ? context.l10n.match_info_captain_short_title : ""}",
style: AppTextStyle.subtitle2
.copyWith(color: context.colorScheme.textPrimary),
),
Text(
user.player_role != null
? user.player_role!.getString(context)
: context.l10n.common_not_specified_title,
style: AppTextStyle.caption.copyWith(
color: context.colorScheme.textDisabled)),
],
),
child: Column(
crossAxisAlignment: isSecondTeam
? CrossAxisAlignment.end
: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
user.name == null
? context.l10n.common_anonymous_title
: "${user.name}${isCaptain ? context.l10n.match_info_captain_short_title : ""}",
style: AppTextStyle.subtitle2
.copyWith(color: context.colorScheme.textPrimary),
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: isSecondTeam ? TextAlign.end : null,
),
Text(
user.player_role != null
? user.player_role!.getString(context)
: context.l10n.common_not_specified_title,
style: AppTextStyle.caption
.copyWith(color: context.colorScheme.textDisabled),
textAlign: isSecondTeam ? TextAlign.end : null,
),
],
),
),
if (isSecondTeam) ...[
const SizedBox(width: 8),
ImageAvatar(
initial: user.nameInitial,
imageUrl: user.profile_img_url,
size: 40,
),
],
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MatchDetailTabViewNotifier extends StateNotifier<MatchDetailTabState> {
.firstOrNull;

onScorecardExpansionChange(
match.matchResult?.teamId ?? match.teams.firstOrNull?.team.id ?? "",
match.matchResult?.teamId ?? match.current_playing_team_id?? "",
true,
);
state = state.copyWith(
Expand Down Expand Up @@ -417,7 +417,7 @@ class MatchDetailTabState with _$MatchDetailTabState {
String? highlightTeamId,
DateTime? showTeamSelectionSheet,
DateTime? showHighlightOptionSelectionSheet,
@Default(0) int selectedTab,
@Default(1) int selectedTab,
@Default([]) List<OverSummary> overList,
@Default([]) List<OverSummary> filteredHighlight,
@Default([]) List<String> expandedTeamScorecard,
Expand All @@ -429,23 +429,23 @@ class MatchDetailTabState with _$MatchDetailTabState {
}

enum MatchDetailTab {
matchInfo,
commentary,
scorecard,
overs,
squad,
matchInfo,
highlight;

String getString(BuildContext context) {
switch (this) {
case MatchDetailTab.matchInfo:
return context.l10n.match_detail_match_info_tab_title;
case MatchDetailTab.commentary:
return context.l10n.match_detail_commentary_tab_title;
case MatchDetailTab.scorecard:
return context.l10n.match_detail_scorecard_tab_title;
case MatchDetailTab.squad:
return context.l10n.match_detail_squad_tab_title;
case MatchDetailTab.matchInfo:
return context.l10n.match_detail_match_info_tab_title;
case MatchDetailTab.highlight:
return context.l10n.match_detail_highlight_tab_title;
case MatchDetailTab.overs:
Expand All @@ -455,14 +455,14 @@ enum MatchDetailTab {

Widget getTabScreen() {
switch (this) {
case MatchDetailTab.matchInfo:
return const MatchDetailInfoView();
case MatchDetailTab.commentary:
return const MatchDetailCommentaryView();
case MatchDetailTab.scorecard:
return const MatchDetailScorecardView();
case MatchDetailTab.squad:
return const MatchDetailSquadView();
case MatchDetailTab.matchInfo:
return const MatchDetailInfoView();
case MatchDetailTab.highlight:
return const MatchDetailHighlightView();
case MatchDetailTab.overs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class _$MatchDetailTabStateImpl implements _MatchDetailTabState {
this.highlightTeamId,
this.showTeamSelectionSheet,
this.showHighlightOptionSelectionSheet,
this.selectedTab = 0,
this.selectedTab = 1,
final List<OverSummary> overList = const [],
final List<OverSummary> filteredHighlight = const [],
final List<String> expandedTeamScorecard = const [],
Expand Down

0 comments on commit 295e21a

Please sign in to comment.