diff --git a/khelo/lib/ui/app.dart b/khelo/lib/ui/app.dart index 4c4de1eb..6806ae18 100644 --- a/khelo/lib/ui/app.dart +++ b/khelo/lib/ui/app.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:data/storage/app_preferences.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; @@ -26,12 +27,16 @@ class _AppState extends ConsumerState { super.initState(); final AppRoute initialRoute; - initialRoute = AppRoute.intro; - // if (ref.read(hasUserSession)) { - // initialRoute = AppRoute.main; - // } else { - // initialRoute = AppRoute.intro; - // } + if (ref.read(hasUserSession)) { + final currentUser = ref.read(currentUserPod); + if (currentUser?.name == null || currentUser!.name!.isEmpty) { + initialRoute = AppRoute.editProfile(isToCreateAccount: true); + } else { + initialRoute = AppRoute.main; + } + } else { + initialRoute = AppRoute.intro; + } _router = GoRouter( initialLocation: initialRoute.path, diff --git a/khelo/lib/ui/flow/settings/profile/edit_profile_screen.dart b/khelo/lib/ui/flow/settings/profile/edit_profile_screen.dart index 3c3f89dd..8c719300 100644 --- a/khelo/lib/ui/flow/settings/profile/edit_profile_screen.dart +++ b/khelo/lib/ui/flow/settings/profile/edit_profile_screen.dart @@ -13,6 +13,7 @@ import 'package:khelo/ui/flow/settings/profile/edit_profile_view_model.dart'; import 'package:style/animations/on_tap_scale.dart'; import 'package:style/button/primary_button.dart'; import 'package:style/extensions/context_extensions.dart'; +import 'package:style/indicator/progress_indicator.dart'; import 'package:style/text/app_text_style.dart'; class EditProfileScreen extends ConsumerWidget { @@ -182,7 +183,7 @@ class EditProfileScreen extends ConsumerWidget { context.l10n.edit_profile_save_title, expanded: false, progress: state.isSaveInProgress, - enabled: state.isButtonEnable, + enabled: state.isButtonEnable && !state.isImageUploading, onPressed: () => notifier.onSubmitTap(), ) ], @@ -208,19 +209,23 @@ class EditProfileScreen extends ConsumerWidget { alignment: Alignment.center, decoration: BoxDecoration( shape: BoxShape.circle, - image: state.imageUrl != null + image: state.imageUrl != null && !state.isImageUploading ? DecorationImage( image: CachedNetworkImageProvider(state.imageUrl!), fit: BoxFit.cover) : null, color: context.colorScheme.primary), - child: state.imageUrl == null + child: state.imageUrl == null && !state.isImageUploading ? Icon( Icons.person, size: profileViewHeight / 2, color: context.colorScheme.textSecondary, ) - : null, + : state.isImageUploading + ? AppProgressIndicator( + color: context.colorScheme.surface, + ) + : null, ), OnTapScale( onTap: () { diff --git a/khelo/lib/ui/flow/settings/profile/edit_profile_view_model.dart b/khelo/lib/ui/flow/settings/profile/edit_profile_view_model.dart index d5d119fd..6a91abf5 100644 --- a/khelo/lib/ui/flow/settings/profile/edit_profile_view_model.dart +++ b/khelo/lib/ui/flow/settings/profile/edit_profile_view_model.dart @@ -80,19 +80,33 @@ class EditProfileViewNotifier extends StateNotifier { Future onImageChange(String path) async { try { + state = state.copyWith(isImageUploading: true); final imageUrl = await fileUploadService.uploadProfileImage(path); final prevUrl = state.imageUrl; if (prevUrl != null && prevUrl != state.currentUser?.profile_img_url) { await fileUploadService.deleteUploadedProfileImage(prevUrl); } - state = state.copyWith(imageUrl: imageUrl); + state = state.copyWith(imageUrl: imageUrl, isImageUploading: false); onValueChange(); } catch (e) { + state = state.copyWith(isImageUploading: false); debugPrint("EditProfileViewNotifier: error while image upload -> $e"); } } + Future onBackBtnPressed() async { + try { + if (state.imageUrl != state.currentUser?.profile_img_url && + state.imageUrl != null) { + await fileUploadService.deleteUploadedProfileImage(state.imageUrl!); + } + } catch (e) { + debugPrint( + "EditProfileViewNotifier: error while delete image on back btn press -> $e"); + } + } + Future onSubmitTap() async { if (state.currentUser == null) { return; @@ -176,18 +190,6 @@ class EditProfileViewNotifier extends StateNotifier { "EditProfileViewNotifier: error in reAuthenticate And Delete -> $e"); } } - - void onBackBtnPressed() { - try { - if (state.imageUrl != state.currentUser?.profile_img_url && - state.imageUrl != null) { - fileUploadService.deleteUploadedProfileImage(state.imageUrl!); - } - } catch (e) { - debugPrint( - "EditProfileViewNotifier: error while delete image on back btn press -> $e"); - } - } } @freezed @@ -203,6 +205,7 @@ class EditProfileState with _$EditProfileState { @Default(null) BowlingStyle? bowlingStyle, @Default(null) PlayerRole? playerRole, @Default(false) bool isButtonEnable, + @Default(false) bool isImageUploading, @Default(false) bool isSaved, @Default(false) bool isSaveInProgress, UserModel? currentUser, diff --git a/khelo/lib/ui/flow/settings/profile/edit_profile_view_model.freezed.dart b/khelo/lib/ui/flow/settings/profile/edit_profile_view_model.freezed.dart index 17a04629..0bdb25a1 100644 --- a/khelo/lib/ui/flow/settings/profile/edit_profile_view_model.freezed.dart +++ b/khelo/lib/ui/flow/settings/profile/edit_profile_view_model.freezed.dart @@ -29,6 +29,7 @@ mixin _$EditProfileState { BowlingStyle? get bowlingStyle => throw _privateConstructorUsedError; PlayerRole? get playerRole => throw _privateConstructorUsedError; bool get isButtonEnable => throw _privateConstructorUsedError; + bool get isImageUploading => throw _privateConstructorUsedError; bool get isSaved => throw _privateConstructorUsedError; bool get isSaveInProgress => throw _privateConstructorUsedError; UserModel? get currentUser => throw _privateConstructorUsedError; @@ -55,6 +56,7 @@ abstract class $EditProfileStateCopyWith<$Res> { BowlingStyle? bowlingStyle, PlayerRole? playerRole, bool isButtonEnable, + bool isImageUploading, bool isSaved, bool isSaveInProgress, UserModel? currentUser}); @@ -85,6 +87,7 @@ class _$EditProfileStateCopyWithImpl<$Res, $Val extends EditProfileState> Object? bowlingStyle = freezed, Object? playerRole = freezed, Object? isButtonEnable = null, + Object? isImageUploading = null, Object? isSaved = null, Object? isSaveInProgress = null, Object? currentUser = freezed, @@ -130,6 +133,10 @@ class _$EditProfileStateCopyWithImpl<$Res, $Val extends EditProfileState> ? _value.isButtonEnable : isButtonEnable // ignore: cast_nullable_to_non_nullable as bool, + isImageUploading: null == isImageUploading + ? _value.isImageUploading + : isImageUploading // ignore: cast_nullable_to_non_nullable + as bool, isSaved: null == isSaved ? _value.isSaved : isSaved // ignore: cast_nullable_to_non_nullable @@ -177,6 +184,7 @@ abstract class _$$EditProfileStateImplCopyWith<$Res> BowlingStyle? bowlingStyle, PlayerRole? playerRole, bool isButtonEnable, + bool isImageUploading, bool isSaved, bool isSaveInProgress, UserModel? currentUser}); @@ -206,6 +214,7 @@ class __$$EditProfileStateImplCopyWithImpl<$Res> Object? bowlingStyle = freezed, Object? playerRole = freezed, Object? isButtonEnable = null, + Object? isImageUploading = null, Object? isSaved = null, Object? isSaveInProgress = null, Object? currentUser = freezed, @@ -251,6 +260,10 @@ class __$$EditProfileStateImplCopyWithImpl<$Res> ? _value.isButtonEnable : isButtonEnable // ignore: cast_nullable_to_non_nullable as bool, + isImageUploading: null == isImageUploading + ? _value.isImageUploading + : isImageUploading // ignore: cast_nullable_to_non_nullable + as bool, isSaved: null == isSaved ? _value.isSaved : isSaved // ignore: cast_nullable_to_non_nullable @@ -281,6 +294,7 @@ class _$EditProfileStateImpl implements _EditProfileState { this.bowlingStyle = null, this.playerRole = null, this.isButtonEnable = false, + this.isImageUploading = false, this.isSaved = false, this.isSaveInProgress = false, this.currentUser}); @@ -313,6 +327,9 @@ class _$EditProfileStateImpl implements _EditProfileState { final bool isButtonEnable; @override @JsonKey() + final bool isImageUploading; + @override + @JsonKey() final bool isSaved; @override @JsonKey() @@ -322,7 +339,7 @@ class _$EditProfileStateImpl implements _EditProfileState { @override String toString() { - return 'EditProfileState(dob: $dob, nameController: $nameController, emailController: $emailController, locationController: $locationController, imageUrl: $imageUrl, gender: $gender, battingStyle: $battingStyle, bowlingStyle: $bowlingStyle, playerRole: $playerRole, isButtonEnable: $isButtonEnable, isSaved: $isSaved, isSaveInProgress: $isSaveInProgress, currentUser: $currentUser)'; + return 'EditProfileState(dob: $dob, nameController: $nameController, emailController: $emailController, locationController: $locationController, imageUrl: $imageUrl, gender: $gender, battingStyle: $battingStyle, bowlingStyle: $bowlingStyle, playerRole: $playerRole, isButtonEnable: $isButtonEnable, isImageUploading: $isImageUploading, isSaved: $isSaved, isSaveInProgress: $isSaveInProgress, currentUser: $currentUser)'; } @override @@ -348,6 +365,8 @@ class _$EditProfileStateImpl implements _EditProfileState { other.playerRole == playerRole) && (identical(other.isButtonEnable, isButtonEnable) || other.isButtonEnable == isButtonEnable) && + (identical(other.isImageUploading, isImageUploading) || + other.isImageUploading == isImageUploading) && (identical(other.isSaved, isSaved) || other.isSaved == isSaved) && (identical(other.isSaveInProgress, isSaveInProgress) || other.isSaveInProgress == isSaveInProgress) && @@ -368,6 +387,7 @@ class _$EditProfileStateImpl implements _EditProfileState { bowlingStyle, playerRole, isButtonEnable, + isImageUploading, isSaved, isSaveInProgress, currentUser); @@ -392,6 +412,7 @@ abstract class _EditProfileState implements EditProfileState { final BowlingStyle? bowlingStyle, final PlayerRole? playerRole, final bool isButtonEnable, + final bool isImageUploading, final bool isSaved, final bool isSaveInProgress, final UserModel? currentUser}) = _$EditProfileStateImpl; @@ -417,6 +438,8 @@ abstract class _EditProfileState implements EditProfileState { @override bool get isButtonEnable; @override + bool get isImageUploading; + @override bool get isSaved; @override bool get isSaveInProgress; diff --git a/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_view_model.dart b/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_view_model.dart index e4f44d91..3b120a62 100644 --- a/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_view_model.dart +++ b/khelo/lib/ui/flow/sign_in/phone_verification/phone_verification_view_model.dart @@ -99,7 +99,6 @@ class PhoneVerificationViewNotifier await userService.updateUser(user); state = state.copyWith(verifying: false, credential: credential); } else { - // get user await userService.getUser(credential.user?.uid ?? "INVALID ID"); state = state.copyWith(verifying: false, credential: credential); }