Skip to content

Commit

Permalink
show running matches in home
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sidhdhi-p committed Apr 2, 2024
1 parent ca540fd commit 7326bbb
Show file tree
Hide file tree
Showing 67 changed files with 1,537 additions and 778 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Khelo is an open-source Flutter project written in Dart using Firestore database
## Features 🌟🌟

- **Profile Management**: Create and manage profiles for players, coaches, and team managers effortlessly.
- **Team Creation**: Form your dream team by adding players and managing team compositions with ease..
- **Team Creation**: Form your dream team by adding players and managing team compositions with ease.
- **Player Management**: Keep track of player details, including statistics, performance history, and personal information.
- **Match Data Recording**: Record detailed match data, including scores, wickets, runs, and other custom metrics, providing a comprehensive overview of each game.
- **Performance Tracking**: Monitor and analyze player performance over time, enabling informed decision-making and strategic planning.
Expand Down
177 changes: 131 additions & 46 deletions data/lib/service/match/match_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:data/api/match/match_model.dart';
import 'package:data/api/team/team_model.dart';
Expand Down Expand Up @@ -68,52 +70,45 @@ class MatchService {
return matches;
}

Future<MatchModel> getMatchById(String id) async {
DocumentReference matchRef = _firestore.collection(_collectionName).doc(id);
DocumentSnapshot snapshot = await matchRef.get();

AddEditMatchRequest match =
AddEditMatchRequest.fromJson(snapshot.data() as Map<String, dynamic>);
Future<List<MatchModel>> getCurrentUserPlayedMatches() async {
if (_currentUserId == null) {
return [];
}

List<MatchTeamModel> teams = await getTeamsList(match.teams);
List<UserModel>? umpires = await getUserListFromUserIds(match.umpire_ids);
List<UserModel>? commentators =
await getUserListFromUserIds(match.commentator_ids);
List<UserModel>? scorers = await getUserListFromUserIds(match.scorer_ids);
QuerySnapshot snapshot = await _firestore.collection(_collectionName).get();
List<MatchModel> matches = [];

UserModel? referee;
if (match.referee_id != null) {
referee = await _userService.getUserById(match.referee_id!);
for (QueryDocumentSnapshot mainDoc in snapshot.docs) {
Map<String, dynamic> mainDocData = mainDoc.data() as Map<String, dynamic>;
AddEditMatchRequest match = AddEditMatchRequest.fromJson(mainDocData);
if (match.teams
.map((e) => e.squad.map((e) => e.id).contains(_currentUserId))
.contains(true) &&
match.match_status == MatchStatus.finish) {
List<MatchTeamModel> teams = await getTeamsList(match.teams);
matches.add(MatchModel(
id: match.id,
teams: teams,
match_type: match.match_type,
number_of_over: match.number_of_over,
over_per_bowler: match.over_per_bowler,
city: match.city,
ground: match.ground,
start_time: match.start_time,
ball_type: match.ball_type,
pitch_type: match.pitch_type,
match_status: match.match_status,
toss_winner_id: match.toss_winner_id,
toss_decision: match.toss_decision,
current_playing_team_id: match.current_playing_team_id,
));
}
}

var matchModel = MatchModel(
id: match.id,
teams: teams,
match_type: match.match_type,
number_of_over: match.number_of_over,
over_per_bowler: match.over_per_bowler,
city: match.city,
ground: match.ground,
start_time: match.start_time,
ball_type: match.ball_type,
pitch_type: match.pitch_type,
match_status: match.match_status,
commentators: commentators,
referee: referee,
scorers: scorers,
umpires: umpires,
power_play_overs1: match.power_play_overs1 ?? [],
power_play_overs2: match.power_play_overs2 ?? [],
power_play_overs3: match.power_play_overs3 ?? [],
toss_decision: match.toss_decision,
toss_winner_id: match.toss_winner_id,
current_playing_team_id: match.current_playing_team_id,
);

return matchModel;
return matches;
}

Future<List<MatchModel>> getCurrentUserMatches() async {
Future<List<MatchModel>> getCurrentUserRelatedMatches() async {
if (_currentUserId == null) {
return [];
}
Expand All @@ -124,11 +119,14 @@ class MatchService {
for (QueryDocumentSnapshot mainDoc in snapshot.docs) {
Map<String, dynamic> mainDocData = mainDoc.data() as Map<String, dynamic>;
AddEditMatchRequest match = AddEditMatchRequest.fromJson(mainDocData);
if (match.teams
.map((e) => e.squad.map((e) => e.id).contains(_currentUserId))
.contains(true) &&
match.match_status == MatchStatus.finish) {
List<MatchTeamModel> teams = await getTeamsList(match.teams);
List<MatchTeamModel> teams = await getTeamsList(match.teams);
if (teams
.map((e) =>
e.team.players?.map((e) => e.id).contains(_currentUserId))
.contains(true) ||
teams
.map((e) => e.team.created_by == _currentUserId)
.contains(true)) {
matches.add(MatchModel(
id: match.id,
teams: teams,
Expand All @@ -152,7 +150,8 @@ class MatchService {
}

Future<List<MatchModel>> getMatchesByTeamId(String teamId) async {
CollectionReference matchCollection = _firestore.collection(_collectionName);
CollectionReference matchCollection =
_firestore.collection(_collectionName);

QuerySnapshot mainCollectionSnapshot = await matchCollection.get();

Expand Down Expand Up @@ -185,6 +184,92 @@ class MatchService {
return matches;
}

Stream<List<MatchModel>> getRunningMatches() {
StreamController<List<MatchModel>> controller =
StreamController<List<MatchModel>>();

_firestore
.collection(_collectionName)
.where('match_status', isEqualTo: 2)
.snapshots()
.listen((QuerySnapshot<Map<String, dynamic>> snapshot) async {
List<MatchModel> matches = [];

for (QueryDocumentSnapshot mainDoc in snapshot.docs) {
Map<String, dynamic> mainDocData =
mainDoc.data() as Map<String, dynamic>;
AddEditMatchRequest match = AddEditMatchRequest.fromJson(mainDocData);

List<MatchTeamModel> teams = await getTeamsList(match.teams);
matches.add(MatchModel(
id: match.id,
teams: teams,
match_type: match.match_type,
number_of_over: match.number_of_over,
over_per_bowler: match.over_per_bowler,
city: match.city,
ground: match.ground,
start_time: match.start_time,
ball_type: match.ball_type,
pitch_type: match.pitch_type,
match_status: match.match_status,
toss_winner_id: match.toss_winner_id,
toss_decision: match.toss_decision,
current_playing_team_id: match.current_playing_team_id,
));
}

controller.add(matches);
});

return controller.stream;
}

Future<MatchModel> getMatchById(String id) async {
DocumentReference matchRef = _firestore.collection(_collectionName).doc(id);
DocumentSnapshot snapshot = await matchRef.get();

AddEditMatchRequest match =
AddEditMatchRequest.fromJson(snapshot.data() as Map<String, dynamic>);

List<MatchTeamModel> teams = await getTeamsList(match.teams);
List<UserModel>? umpires = await getUserListFromUserIds(match.umpire_ids);
List<UserModel>? commentators =
await getUserListFromUserIds(match.commentator_ids);
List<UserModel>? scorers = await getUserListFromUserIds(match.scorer_ids);

UserModel? referee;
if (match.referee_id != null) {
referee = await _userService.getUserById(match.referee_id!);
}

var matchModel = MatchModel(
id: match.id,
teams: teams,
match_type: match.match_type,
number_of_over: match.number_of_over,
over_per_bowler: match.over_per_bowler,
city: match.city,
ground: match.ground,
start_time: match.start_time,
ball_type: match.ball_type,
pitch_type: match.pitch_type,
match_status: match.match_status,
commentators: commentators,
referee: referee,
scorers: scorers,
umpires: umpires,
power_play_overs1: match.power_play_overs1 ?? [],
power_play_overs2: match.power_play_overs2 ?? [],
power_play_overs3: match.power_play_overs3 ?? [],
toss_decision: match.toss_decision,
toss_winner_id: match.toss_winner_id,
current_playing_team_id: match.current_playing_team_id,
);

return matchModel;
}

Future<String> updateMatch(AddEditMatchRequest match) async {
DocumentReference matchRef =
_firestore.collection(_collectionName).doc(match.id);
Expand Down
17 changes: 14 additions & 3 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
"common_next_title": "Next",
"common_yes_title": "Yes",
"common_no_title": "No",
"common_no_title": "No",
"common_wicket_taken_title" : " Wicket taken",
"common_not_specified_title": "Not Specified",
"common_obscure_phone_number_text": "+{countryCode} ***** ***{lastDigits}",
"common_obscure_phone_number_text": "{countryCode} ***** ***{lastDigits}",
"@common_obscure_phone_number_text": {
"description": "+{countryCode} ***** ***{lastDigits}",
"placeholders": {
Expand Down Expand Up @@ -71,6 +73,8 @@
"edit_profile_gender_other_title": "Other",
"edit_profile_save_title": "SAVE",

"home_screen_title": "Home",

"image_picker_choose_option_title": "Choose an option.",
"image_picker_crop_image_title": "Crop Image",

Expand Down Expand Up @@ -170,6 +174,7 @@
"add_match_start_match_title": "Start Match",
"add_match_no_of_over_title": "no. of over",
"add_match_over_per_bowler_title": "over per bowler",
"add_match_joined_on_title": "Joined on",

"add_match_officials_screen_title": "Add Match Officials",
"add_match_officials_add_officials_title": "Add Officials",
Expand All @@ -178,6 +183,12 @@
"search_team_search_placeholder_title": "Search team name",
"search_team_your_teams_title": "Your Teams",
"search_team_select_title": "Select",
"search_team_member_title" : "{count, plural, =0{{count} Members} =1{{count} Member} other{{count} Members}}",
"@search_team_member_title": {
"placeholders": {
"count": {}
}
},

"search_user_hint_title": "Search user name",
"search_user_empty_text": "Search the person name in above input area.",
Expand Down Expand Up @@ -267,6 +278,7 @@
}
},
"score_board_choose_fielder_title" : "choose Fielder",
"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.",
Expand Down Expand Up @@ -319,6 +331,7 @@
"team_detail_run_rate_title": "Run Rate",
"team_detail_match_played_title": "\nMatch played",
"team_detail_matches_played_title": "\nMatches played",
"team_detail_overs_title": "Overs:",

"match_status_yet_to_start_title" : "Yet to start",
"match_status_running_title" : "Running",
Expand Down Expand Up @@ -350,15 +363,13 @@
"my_stat_stats_strike_rate_title": "\nStrike rate",
"my_stat_stats_ball_faced_title": " Ball faced",
"my_stat_stats_bowling_statics_title": "Bowling Statistics",
"my_stat_stats_wicket_taken_title": "Wicket taken",
"my_stat_stats_economy_rate_title": " Economy rate",
"my_stat_stats_fielding_statics_title": "Fielding Statistics",
"my_stat_stats_catches_title": "Catches",
"my_stat_stats_run_out_title": " Run out",
"my_stat_stats_stumping_title": " Stumping",

"match_stat_screen_title" : "Match Stat",
"match_stat_wicket_taken_title" : " Wicket taken",
"match_stat_in_over_text" : " (in {count} Over)",
"@match_stat_in_over_text": {
"description": " (in {count} Over)",
Expand Down
18 changes: 18 additions & 0 deletions khelo/lib/domain/formatter/date_formatter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter/cupertino.dart';
import 'package:intl/intl.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';

enum DateFormatType { dateAndTime, }

extension DateFormatter on DateTime {
String format(BuildContext context, DateFormatType type) {
if (isUtc) return toLocal().format(context, type);

switch (type) {
case DateFormatType.dateAndTime:
return DateFormat(
'EEE, MMM dd yyyy ${context.is24HourFormat ? 'HH:mm' : 'hh:mm a'}')
.format(this);
}
}
}
28 changes: 28 additions & 0 deletions khelo/lib/domain/formatter/string_formatter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/cupertino.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';

const _missing = '-';

extension StringExtension on String? {
String format(BuildContext context, StringFormats formatType) {
if (this == null) return _missing;

switch (formatType) {
case StringFormats.obscurePhoneNumber:
if (this!.length < 13) {
return _missing;
}
return context.l10n.common_obscure_phone_number_text(
this!.substring(0, 3),
this!.substring(this!.length - 2)); // TODO: change to 1 if needed
}
}
}

enum StringFormats {
obscurePhoneNumber('+## ***** ***##');

const StringFormats(this.value);

final String value;
}
2 changes: 1 addition & 1 deletion khelo/lib/ui/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ class _AppState extends ConsumerState<App> {
},
));
}
}
}
Loading

0 comments on commit 7326bbb

Please sign in to comment.