-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
297 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import 'package:data/api/match/match_model.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_svg/flutter_svg.dart'; | ||
import 'package:khelo/components/image_avatar.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/gen/assets.gen.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 MatchDetailCell extends StatelessWidget { | ||
final MatchModel match; | ||
final Function() onTap; | ||
final bool showStatusTag; | ||
final bool showActionButtons; | ||
final Function()? onActionTap; | ||
|
||
const MatchDetailCell({ | ||
super.key, | ||
required this.match, | ||
required this.onTap, | ||
this.showStatusTag = true, | ||
this.showActionButtons = false, | ||
this.onActionTap, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return OnTapScale( | ||
onTap: onTap, | ||
child: Container( | ||
padding: const EdgeInsets.all(16), | ||
decoration: BoxDecoration( | ||
border: Border.all(color: context.colorScheme.secondary), | ||
borderRadius: BorderRadius.circular(16), | ||
), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
_matchTimeAndGroundView(context), | ||
const SizedBox(height: 16), | ||
...match.teams.map( | ||
(team) => _teamView(context, team), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 16.0), | ||
child: Divider( | ||
color: context.colorScheme.outline, | ||
height: 1, | ||
), | ||
), | ||
Row( | ||
children: [ | ||
Expanded(child: _winnerMessageText(context)), | ||
if (showStatusTag) ...[ | ||
MatchStatusTag( | ||
status: match.match_status, | ||
onTap: showActionButtons && | ||
match.match_status != MatchStatus.finish | ||
? onActionTap | ||
: null, | ||
) | ||
], | ||
], | ||
) | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget _matchTimeAndGroundView(BuildContext context) { | ||
return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ | ||
Flexible( | ||
flex: 2, | ||
child: Text( | ||
match.start_time.format(context, DateFormatType.dateAndTime), | ||
style: AppTextStyle.caption | ||
.copyWith(color: context.colorScheme.textDisabled)), | ||
), | ||
Flexible( | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: [ | ||
SvgPicture.asset( | ||
Assets.images.icLocation, | ||
height: 20, | ||
width: 20, | ||
colorFilter: ColorFilter.mode( | ||
context.colorScheme.textSecondary, | ||
BlendMode.srcATop, | ||
), | ||
), | ||
const SizedBox(width: 4), | ||
Flexible( | ||
child: Text( | ||
match.ground, | ||
style: AppTextStyle.caption | ||
.copyWith(color: context.colorScheme.textDisabled), | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
]); | ||
} | ||
|
||
Widget _teamView(BuildContext context, MatchTeamModel matchTeam) { | ||
return Padding( | ||
padding: const EdgeInsets.only(bottom: 8), | ||
child: Row( | ||
children: [ | ||
ImageAvatar( | ||
initial: matchTeam.team.name[0].toUpperCase(), | ||
imageUrl: matchTeam.team.profile_img_url, | ||
size: 32, | ||
), | ||
const SizedBox(width: 8), | ||
Expanded( | ||
child: Text(matchTeam.team.name, | ||
overflow: TextOverflow.ellipsis, | ||
maxLines: 2, | ||
style: AppTextStyle.subtitle3 | ||
.copyWith(color: context.colorScheme.textPrimary)), | ||
), | ||
if (!(matchTeam.run == 0 && | ||
matchTeam.wicket == 0 && | ||
matchTeam.over == 0)) ...[ | ||
Text.rich(TextSpan( | ||
text: "${matchTeam.run}-${matchTeam.wicket}", | ||
style: AppTextStyle.subtitle2 | ||
.copyWith(color: context.colorScheme.textPrimary), | ||
children: [ | ||
TextSpan( | ||
text: " ${matchTeam.over}", | ||
style: AppTextStyle.body2 | ||
.copyWith(color: context.colorScheme.textSecondary), | ||
) | ||
])) | ||
], | ||
], | ||
), | ||
); | ||
} | ||
|
||
Widget _winnerMessageText(BuildContext context) { | ||
final winSummary = match.getWinnerSummary(context); | ||
if (match.match_status == MatchStatus.finish && winSummary != null) { | ||
if (winSummary.teamName.isEmpty) { | ||
return Text( | ||
context.l10n.score_board_match_tied_text, | ||
style: AppTextStyle.subtitle1 | ||
.copyWith(color: context.colorScheme.textPrimary), | ||
); | ||
} | ||
return WonByMessageText( | ||
teamName: winSummary.teamName, | ||
difference: winSummary.difference, | ||
trailingText: winSummary.wonByText, | ||
); | ||
} else { | ||
return Text( | ||
"${match.match_type.getString(context)} ${context.l10n.match_list_overs_title(match.number_of_over)}", | ||
style: AppTextStyle.body2 | ||
.copyWith(color: context.colorScheme.textDisabled), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.