Skip to content

Commit

Permalink
Redesign match detail screen (#24)
Browse files Browse the repository at this point in the history
* redesign match detail

* change highlight btn

* code refactor

* transform data in models

* fix data repeating

* change image avatar

* add status tag

* use tab button
  • Loading branch information
cp-sidhdhi-p authored Jun 6, 2024
1 parent afc7df9 commit a32a415
Show file tree
Hide file tree
Showing 54 changed files with 3,613 additions and 1,810 deletions.
438 changes: 437 additions & 1 deletion data/lib/api/ball_score/ball_score_model.dart

Large diffs are not rendered by default.

1,340 changes: 1,340 additions & 0 deletions data/lib/api/ball_score/ball_score_model.freezed.dart

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/lib/api/innings/inning_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ enum InningStatus {
final int value;

const InningStatus(this.value);
}
}
4 changes: 2 additions & 2 deletions data/lib/api/innings/inning_model.g.dart

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

65 changes: 65 additions & 0 deletions data/lib/api/match/match_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,71 @@ class MatchTeamModel with _$MatchTeamModel {
_$MatchTeamModelFromJson(json);
}

extension DataMatchModel on MatchModel {
MatchResult? get matchResult {
if (match_status != MatchStatus.finish) {
return null;
}

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

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

final runDifference = firstTeam.run - secondTeam.run;
return MatchResult(
teamId: firstTeam.team.id ?? "",
teamName: teamName,
difference: runDifference,
winType: WinnerByType.run);
} else if (firstTeam.run == secondTeam.run) {
return MatchResult(
teamId: "",
teamName: "",
difference: 0,
winType: WinnerByType.tie,
);
} else {
// second batting team won
final teamName = secondTeam.team.name;

final wicketDifference = secondTeam.squad.length - firstTeam.wicket;

return MatchResult(
teamId: secondTeam.team.id ?? "",
teamName: teamName,
difference: wicketDifference,
winType: WinnerByType.wicket,
);
}
}
}

enum WinnerByType {
run,
wicket,
tie;
}

class MatchResult {
String teamId;
int difference;
String teamName;
WinnerByType winType;

MatchResult({
required this.teamId,
required this.teamName,
required this.difference,
required this.winType,
});
}

@freezed
class MatchPlayer with _$MatchPlayer {
const factory MatchPlayer({
Expand Down
2 changes: 1 addition & 1 deletion data/lib/api/network/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ final rawDioProvider = Provider((ref) {
..options.connectTimeout = const Duration(seconds: 30)
..options.sendTimeout = const Duration(seconds: 30)
..options.receiveTimeout = const Duration(seconds: 30);
});
});
34 changes: 34 additions & 0 deletions data/lib/extensions/double_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:data/extensions/int_extensions.dart';

extension OverExtensionOnDouble on double {
double add(int ballsToAdd) {
int totalBalls = toBalls() + ballsToAdd;
return totalBalls.toOvers();
}

double remove(int ballsToRemove) {
int totalBalls = toBalls() - ballsToRemove;
if (totalBalls < 0) totalBalls = 0;
return totalBalls.toOvers();
}

int getBallNumberFromOver() {
String valueString = toString();

List<String> parts = valueString.split('.');

if (parts.length > 1) {
return int.parse(parts[1]);
} else {
return 0;
}
}

int getOverNumberFromOver() {
return toInt();
}

int toBalls() {
return (getOverNumberFromOver() * 6) + getBallNumberFromOver();
}
}
7 changes: 7 additions & 0 deletions data/lib/extensions/int_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extension OverExtensionOnInt on int {
double toOvers() {
int overs = this ~/ 6;
int additionalBalls = this % 6;
return double.parse("$overs.$additionalBalls");
}
}
2 changes: 1 addition & 1 deletion data/lib/extensions/list_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ extension ChunkedList<T> on List<T> {
return sublist(start, start + size < length ? start + size : length);
});
}
}
}
2 changes: 1 addition & 1 deletion data/lib/service/ball_score/ball_score_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ class BallScoreChange {
final BallScoreModel ballScore;

BallScoreChange(this.type, this.ballScore);
}
}
3 changes: 2 additions & 1 deletion data/lib/service/user/user_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class UserService {
.collection(FireStoreConst.usersCollection)
.where(FireStoreConst.nameLowercase,
isGreaterThanOrEqualTo: searchKey.toLowerCase())
.where(FireStoreConst.nameLowercase, isLessThan: '${searchKey.toLowerCase()}z')
.where(FireStoreConst.nameLowercase,
isLessThan: '${searchKey.toLowerCase()}z')
.get();

return snapshot.docs.map((doc) {
Expand Down
5 changes: 2 additions & 3 deletions data/lib/storage/app_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ final currentUserPod = Provider<UserModel?>((ref) {
return json == null ? null : UserModel.fromJsonString(json);
});

final hasUserSession = Provider<bool>((ref) => ref.watch(currentUserPod) != null);


final hasUserSession =
Provider<bool>((ref) => ref.watch(currentUserPod) != null);
3 changes: 2 additions & 1 deletion data/lib/storage/provider/preferences_provider.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';

final sharedPreferencesProvider = Provider<SharedPreferences>((ref) => throw UnimplementedError());
final sharedPreferencesProvider =
Provider<SharedPreferences>((ref) => throw UnimplementedError());

StateProvider<T> createPrefProvider<T>({
required String prefKey,
Expand Down
2 changes: 1 addition & 1 deletion data/lib/utils/constant/firebase_error_constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const String errorInvalidPhoneNumber = "invalid-phone-number";
const String errorNetworkRequestFailed = "network-request-failed";
const String errorUserNotFound = "user-not-found";
const String errorUnauthenticated = "unauthenticated";
const String errorTooManyRequest = "too-many-requests";
const String errorTooManyRequest = "too-many-requests";
2 changes: 1 addition & 1 deletion data/lib/utils/constant/firestore_constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class FireStoreConst {
static const String players = "players";
static const String createdBy = "created_by";
static const String nameLowercase = "name_lowercase";
}
}
54 changes: 38 additions & 16 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@
"common_no_title": "No",
"common_retry_title": "Retry",
"common_not_specified_title": "Not Specified",
"common_runs_dot_title": " Runs.",
"common_wickets_dot_title": " Wickets.",
"common_runs_title": "{count, plural, =0{{count} runs} =1{{count} run} other{{count} runs}}",
"@common_runs_title": {
"placeholders": {
"count": {}
}
},
"common_wickets_title": "{count, plural, =0{{count} wickets} =1{{count} wicket} other{{count} wickets}}",
"@common_wickets_title": {
"placeholders": {
"count": {}
}
},
"common_tie_title": "Tie",
"common_wicket_taken_title": " Wicket taken",
"common_matches_title": "Matches",
"common_edit_team_title": "Edit Team",
Expand Down Expand Up @@ -276,28 +287,29 @@
"match_detail_commentary_tab_title": "Commentary",
"match_detail_scorecard_tab_title": "Scorecard",
"match_detail_squad_tab_title": "Squad",
"match_detail_match_info_tab_title": "Match Info",
"match_detail_match_info_tab_title": "Info",
"match_detail_highlight_tab_title": "Highlight",
"match_detail_overs_tab_title": "Overs",

"match_info_match_title": "Match:",
"match_info_date_title": "Date:",
"match_info_toss_title": "Toss:",
"match_info_time_title": "Time:",
"match_info_umpire_title": "Umpire:",
"match_info_referee_title": "Referee:",
"match_info_squad_title": "{name} Squad:",
"match_info_match_title": "Match",
"match_info_date_title": "Date",
"match_info_toss_title": "Toss",
"match_info_time_title": "Time",
"match_info_umpire_title": "Umpire",
"match_info_referee_title": "Referee",
"match_info_date_and_time_title": "Date & Time",
"match_info_squad_title": "{name} Squad",
"@match_info_squad_title": {
"description": "{name} Squad:",
"description": "{name} Squad",
"placeholders": {
"name": {
"type": "String"
}
}
},
"match_info_playing_title": "Playing:",
"match_info_bench_title": "Bench:",
"match_info_venue_title": "Venue",
"match_info_ground_title": "Ground:",
"match_info_ground_title": "Ground",
"match_info_city_title": "City",
"match_info_captain_short_title": "(c)",
"match_info_toss_detail_text": "{name} won the toss and opt to {decision}",
"@match_info_toss_detail_text": {
Expand Down Expand Up @@ -394,6 +406,15 @@
"match_commentary_end_inning_text_part_1": " wraps up their innings, leaving ",
"match_commentary_end_inning_text_part_2": " for victory.",
"match_commentary_empty_commentary_text": "Commentary will be shown here as soon as the match starts.",
"match_commentary_inning_count_text": "Inning {count}",
"@match_commentary_inning_count_text": {
"description": "Inning {count}",
"placeholders": {
"count": {
"type": "int"
}
}
},

"match_scorecard_fall_of_wicket_text": "Fall of Wicket",
"match_scorecard_over_text": "Over",
Expand All @@ -413,8 +434,8 @@
"match_scorecard_batter_text": "Batter",
"match_scorecard_bowler_text": "Bowler",
"match_scorecard_not_out_text": "Not out",
"match_scorecard_bowler_catcher_short_text": "b {bowler} c {fielder}",
"match_scorecard_did_not_bat_text": "Did not bat",
"match_scorecard_bowler_catcher_short_text": "b {bowler} c {fielder}",
"@match_scorecard_bowler_catcher_short_text": {
"description": "b {bowler} c {fielder}",
"placeholders": {
Expand Down Expand Up @@ -471,7 +492,8 @@
}
},

"match_squad_bench_text": "Bench",
"match_squad_playing_title": "Playing",
"match_squad_bench_title": "Bench",
"match_highlight_filter_all_text": "All",
"match_highlight_filter_fours_text": "Fours",
"match_highlight_filter_sixes_text": "Sixes",
Expand Down
12 changes: 1 addition & 11 deletions khelo/lib/components/app_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:style/text/app_text_style.dart';
class AppPage extends StatelessWidget {
final String? title;
final Widget? titleWidget;
final TabBar? tabBar;
final List<Widget>? actions;
final Widget? leading;
final Widget? floatingActionButton;
Expand All @@ -20,7 +19,6 @@ class AppPage extends StatelessWidget {
super.key,
this.title,
this.titleWidget,
this.tabBar,
this.actions,
this.leading,
this.body,
Expand Down Expand Up @@ -66,15 +64,7 @@ class AppPage extends StatelessWidget {
child: Stack(
alignment: Alignment.bottomRight,
children: [
Column(
children: [
Material(
type: MaterialType.transparency,
child: tabBar,
),
Flexible(child: body ?? const SizedBox()),
],
),
body ?? const SizedBox(),
SafeArea(
child: Padding(
padding: const EdgeInsets.only(right: 16, bottom: 16),
Expand Down
52 changes: 34 additions & 18 deletions khelo/lib/components/image_avatar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

Expand All @@ -21,27 +22,42 @@ class ImageAvatar extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
height: size,
width: size,
alignment: Alignment.center,
decoration: BoxDecoration(
return MediaQuery.withNoTextScaling(
child: Container(
height: size,
width: size,
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: backgroundColor ?? context.colorScheme.containerHigh,
border: Border.all(color: context.colorScheme.textDisabled),
image: (imageUrl != null)
? DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(imageUrl!))
: null),
child: imageUrl == null
? Text(
initial,
style: AppTextStyle.header2.copyWith(
color: foregroundColor ?? context.colorScheme.secondary,
),
child: imageUrl == null
? _initialView(context)
: CachedNetworkImage(
imageUrl: imageUrl!,
fit: BoxFit.cover,
errorWidget: (context, url, error) => _initialView(context),
placeholder: (context, url) => _initialView(context),
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
),
)
: null,
),
);
}

Widget _initialView(BuildContext context) {
return Text(
initial,
style: AppTextStyle.subtitle1.copyWith(
color: foregroundColor ?? context.colorScheme.textPrimary,
fontSize: size / 2.15),
);
}
}
Loading

0 comments on commit a32a415

Please sign in to comment.