Skip to content

Commit

Permalink
Merge pull request #144 from canopas/Mayank/minor-changes
Browse files Browse the repository at this point in the history
Minor refactors
  • Loading branch information
cp-mayank authored Nov 22, 2024
2 parents 83af9f6 + f4b59e3 commit c477c68
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 76 deletions.
6 changes: 3 additions & 3 deletions data/lib/api/ball_score/ball_score_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,9 @@ extension BallScoreList on List<BallScoreModel> {
.where(
(element) =>
element.wicket_type != null &&
(element.wicket_type == WicketType.retired ||
element.wicket_type == WicketType.retiredHurt ||
element.wicket_type == WicketType.timedOut),
element.wicket_type != WicketType.retired &&
element.wicket_type != WicketType.retiredHurt &&
element.wicket_type != WicketType.timedOut,
)
.length;

Expand Down
15 changes: 15 additions & 0 deletions data/lib/service/tournament/tournament_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ class TournamentService {
return keyStats.where((element) => element.player.isActive).toList();
}

Future<int> getUserOwnedTournamentsCount(String userId) {
final currentPlayer = TournamentMember(
id: userId,
role: TournamentMemberRole.organizer,
);

final filter = Filter.or(
Filter(FireStoreConst.createdBy, isEqualTo: userId),
Filter(FireStoreConst.members, arrayContains: currentPlayer.toJson()),
);
return _tournamentCollection.where(filter).count().get().then((snapshot) {
return snapshot.count ?? 0;
}).catchError((error, stack) => throw AppError.fromError(error, stack));
}

Stream<List<TournamentModel>> streamActiveTournaments() {
final currentDate = DateTime.now();
final past30DaysDate = currentDate.subtract(Duration(days: 30));
Expand Down
2 changes: 1 addition & 1 deletion khelo/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<uses-permission android:name="android.permission.WRITE_CONTACTS" />

<application
android:label="khelo"
android:label="Khelo"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
2 changes: 1 addition & 1 deletion khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@
"edit_profile_delete_account_btn_title": "Delete account",
"edit_profile_delete_account_description_text": "This can not undone. if you delete your account, your data will be gone forever.",
"transfer_teams_title" : "Before You Go...",
"transfer_teams_description" : "We're sorry to see you go. Before deleting your account, please:\n• Assign new owners and admins for your teams or delete the teams\n• Transfer scoring for ongoing matches\n• Remove any scheduled matches\nThis will ensure everything is properly managed after you leave.",
"transfer_teams_description" : "We're sorry to see you go. Before deleting your account, please:\n• Assign new owners and admins for your teams or delete the teams\n• Transfer scoring for ongoing matches\n• Remove any scheduled matches\n•Transfer or assign responsibilities for ongoing tournaments\nThis will ensure everything is properly managed after you leave.",
"transfer_teams_go_to_my_cricket" : "Go to My Cricket",

"profile_settings_title": "Settings",
Expand Down
27 changes: 23 additions & 4 deletions khelo/lib/components/image_picker_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import 'package:style/text/app_text_style.dart';
import '../gen/assets.gen.dart';

class ImagePickerSheet extends ConsumerWidget {
static Future<T?> show<T>(BuildContext context, bool allowCrop) {
static Future<T?> show<T>(
BuildContext context, {
required bool allowCrop,
bool cropOriginal = false,
}) {
HapticFeedback.mediumImpact();
return showModalBottomSheet(
context: context,
Expand All @@ -22,6 +26,7 @@ class ImagePickerSheet extends ConsumerWidget {
builder: (context) {
return ImagePickerSheet(
allowCrop: allowCrop,
cropOriginal: cropOriginal,
onPop: (String? imagePath) {
context.pop(imagePath);
});
Expand All @@ -30,9 +35,15 @@ class ImagePickerSheet extends ConsumerWidget {
}

final bool allowCrop;
final bool cropOriginal;
final void Function(String? imagePath) onPop;

ImagePickerSheet({super.key, required this.allowCrop, required this.onPop});
ImagePickerSheet({
super.key,
required this.allowCrop,
required this.onPop,
this.cropOriginal = false,
});

final ImagePicker _picker = ImagePicker();

Expand Down Expand Up @@ -150,11 +161,19 @@ class ImagePickerSheet extends ConsumerWidget {
toolbarWidgetColor: context.colorScheme.onPrimary,
initAspectRatio: CropAspectRatioPreset.square,
lockAspectRatio: true,
aspectRatioPresets: [CropAspectRatioPreset.square],
aspectRatioPresets: [
cropOriginal
? CropAspectRatioPreset.original
: CropAspectRatioPreset.square
],
),
IOSUiSettings(
title: context.l10n.image_picker_crop_image_title,
aspectRatioPresets: [CropAspectRatioPreset.square],
aspectRatioPresets: [
cropOriginal
? CropAspectRatioPreset.original
: CropAspectRatioPreset.square
],
),
WebUiSettings(context: context),
],
Expand Down
2 changes: 1 addition & 1 deletion khelo/lib/ui/flow/home/components/match_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MatchItem extends StatelessWidget {
onTap: () => AppRoute.matchDetailTab(matchId: match.id).push(context),
child: MediaQuery.withNoTextScaling(
child: Container(
width: context.mediaQuerySize.width * 0.83,
width: 360,
padding: const EdgeInsets.all(16),
margin: const EdgeInsets.all(8),
decoration: BoxDecoration(
Expand Down
3 changes: 2 additions & 1 deletion khelo/lib/ui/flow/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class _HomeScreenState extends ConsumerState<HomeScreen> {
? _content(context, state)
: SizedBox(
height: context.mediaQuerySize.height /
(state.tournaments.isEmpty ? 0.5 : 2),
(state.tournaments.isEmpty ? 1.3 : 2),
child: EmptyScreen(
title: context.l10n.home_screen_no_matches_title,
description:
Expand Down Expand Up @@ -145,6 +145,7 @@ class _HomeScreenState extends ConsumerState<HomeScreen> {
List<TournamentModel> tournaments,
) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_header(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class EditProfileScreen extends ConsumerWidget {
filePath: state.filePath,
isLoading: state.isImageUploading,
onEditButtonTap: () async {
final imagePath =
await ImagePickerSheet.show<String>(context, true);
final imagePath = await ImagePickerSheet.show<String>(
context,
allowCrop: true,
);
if (imagePath != null) {
notifier.onImageChange(imagePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:data/service/auth/auth_service.dart';
import 'package:data/service/file_upload/file_upload_service.dart';
import 'package:data/service/match/match_service.dart';
import 'package:data/service/team/team_service.dart';
import 'package:data/service/tournament/tournament_service.dart';
import 'package:data/service/user/user_service.dart';
import 'package:data/storage/app_preferences.dart';
import 'package:data/storage/provider/preferences_provider.dart';
Expand All @@ -27,6 +28,7 @@ final editProfileStateProvider = StateNotifierProvider.autoDispose<
ref.read(authServiceProvider),
ref.read(teamServiceProvider),
ref.read(matchServiceProvider),
ref.read(tournamentServiceProvider),
ref.read(currentUserPod),
ref.read(currentUserJsonPod.notifier),
);
Expand All @@ -40,6 +42,7 @@ class EditProfileViewNotifier extends StateNotifier<EditProfileState> {
final AuthService _authService;
final TeamService _teamService;
final MatchService _matchService;
final TournamentService _tournamentService;
final PreferenceNotifier<String?> _userJsonController;

EditProfileViewNotifier(
Expand All @@ -48,6 +51,7 @@ class EditProfileViewNotifier extends StateNotifier<EditProfileState> {
this._authService,
this._teamService,
this._matchService,
this._tournamentService,
UserModel? user,
this._userJsonController,
) : super(EditProfileState(
Expand Down Expand Up @@ -190,11 +194,12 @@ class EditProfileViewNotifier extends StateNotifier<EditProfileState> {
showTransferTeamsSheet: false,
);

final [matchCount, teamCount] = await Future.wait([
final [matchCount, teamCount, tournamentCount] = await Future.wait([
_matchService.getUserOwnedMatchesCount(userId),
_teamService.getUserOwnedTeamsCount(userId)
_teamService.getUserOwnedTeamsCount(userId),
_tournamentService.getUserOwnedTournamentsCount(userId)
]);
if (teamCount == 0 && matchCount == 0) {
if (teamCount == 0 && matchCount == 0 && tournamentCount == 0) {
state = state.copyWith(showDeleteConfirmationDialog: true);
} else {
state = state.copyWith(showTransferTeamsSheet: true);
Expand Down
10 changes: 7 additions & 3 deletions khelo/lib/ui/flow/team/add_team/add_team_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ class _AddTeamScreenState extends ConsumerState<AddTeamScreen> {
return Stack(
children: [
ListView(
padding: context.mediaQueryPadding + const EdgeInsets.all(16) + BottomStickyOverlay.padding,
padding: context.mediaQueryPadding +
const EdgeInsets.all(16) +
BottomStickyOverlay.padding,
children: [
ProfileImageAvatar(
size: profileViewHeight,
Expand All @@ -105,8 +107,10 @@ class _AddTeamScreenState extends ConsumerState<AddTeamScreen> {
imageUrl: state.editTeam?.profile_img_url,
filePath: state.filePath,
onEditButtonTap: () async {
final imagePath =
await ImagePickerSheet.show<String>(context, true);
final imagePath = await ImagePickerSheet.show<String>(
context,
allowCrop: true,
);
if (imagePath != null) {
notifier.onImageSelect(imagePath);
}
Expand Down
6 changes: 5 additions & 1 deletion khelo/lib/ui/flow/tournament/add/add_tournament_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ class _AddTournamentScreenState extends ConsumerState<AddTournamentScreen> {
}

void _pickImage({bool isBanner = false}) async {
final imagePath = await ImagePickerSheet.show<String>(context, true);
final imagePath = await ImagePickerSheet.show<String>(
context,
allowCrop: true,
cropOriginal: isBanner,
);
if (imagePath != null) {
notifier.onImageChange(imagePath: imagePath, isBanner: isBanner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:khelo/components/image_avatar.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/string_extensions.dart';
import 'package:khelo/ui/app_route.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

Expand Down Expand Up @@ -94,21 +96,24 @@ class TournamentDetailPointsTableTab extends ConsumerWidget {
}

DataCell _teamProfileDataCell(BuildContext context, TeamModel team) {
return DataCell(Row(
children: [
ImageAvatar(
initial: team.name_initial ?? team.name.initials(limit: 1),
imageUrl: team.profile_img_url,
size: 32,
),
const SizedBox(width: 16),
Text(
team.name_initial ?? team.name.initials(limit: 2),
style: AppTextStyle.subtitle2.copyWith(
color: context.colorScheme.textPrimary,
return DataCell(OnTapScale(
onTap: () => AppRoute.teamDetail(teamId: team.id).push(context),
child: Row(
children: [
ImageAvatar(
initial: team.name_initial ?? team.name.initials(limit: 1),
imageUrl: team.profile_img_url,
size: 32,
),
)
],
const SizedBox(width: 16),
Text(
team.name_initial ?? team.name.initials(limit: 2),
style: AppTextStyle.subtitle2.copyWith(
color: context.colorScheme.textPrimary,
),
)
],
),
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:khelo/domain/extensions/context_extensions.dart';
import 'package:khelo/domain/extensions/enum_extensions.dart';
import 'package:style/animations/on_tap_scale.dart';
import 'package:style/button/chip_button.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/text/app_text_style.dart';

import '../../../../../components/empty_screen.dart';
import '../../../../../components/image_avatar.dart';
import '../../../../app_route.dart';
import '../components/filter_tab_view.dart';
import '../tournament_detail_view_model.dart';

Expand Down Expand Up @@ -148,38 +150,41 @@ class TournamentDetailStatsTab extends ConsumerWidget {

DataCell _playerProfileDataCell(BuildContext context, UserModel player) {
return DataCell(
Row(
children: [
ImageAvatar(
size: 40,
initial: player.nameInitial,
imageUrl: player.profile_img_url,
),
const SizedBox(width: 16),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
player.name ?? '',
style: AppTextStyle.body1.copyWith(
color: context.colorScheme.textPrimary,
overflow: TextOverflow.ellipsis,
),
),
if (player.player_role != null) ...[
const SizedBox(height: 4),
OnTapScale(
onTap: () => AppRoute.userDetail(userId: player.id).push(context),
child: Row(
children: [
ImageAvatar(
size: 40,
initial: player.nameInitial,
imageUrl: player.profile_img_url,
),
const SizedBox(width: 16),
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
player.player_role!.getString(context),
style: AppTextStyle.caption
.copyWith(color: context.colorScheme.textSecondary),
)
player.name ?? '',
style: AppTextStyle.body1.copyWith(
color: context.colorScheme.textPrimary,
overflow: TextOverflow.ellipsis,
),
),
if (player.player_role != null) ...[
const SizedBox(height: 4),
Text(
player.player_role!.getString(context),
style: AppTextStyle.caption
.copyWith(color: context.colorScheme.textSecondary),
)
],
],
],
),
),
),
],
],
),
),
);
}
Expand Down
Loading

0 comments on commit c477c68

Please sign in to comment.