diff --git a/lib/application/bottom_navbar_cubit/bottom_navbar_cubit.dart b/lib/application/bottom_navbar_cubit/bottom_navbar_cubit.dart index 55e20ca..e925292 100644 --- a/lib/application/bottom_navbar_cubit/bottom_navbar_cubit.dart +++ b/lib/application/bottom_navbar_cubit/bottom_navbar_cubit.dart @@ -1,10 +1,7 @@ -// navigation_cubit.dart - import 'package:flutter_bloc/flutter_bloc.dart'; import '../../core/enums/enums.dart'; - class NavigationCubit extends Cubit { NavigationCubit() : super(NavigationTab.homeTab); diff --git a/lib/application/user_bloc/user_bloc.dart b/lib/application/user_bloc/user_bloc.dart index ffc5dbd..0d809e0 100644 --- a/lib/application/user_bloc/user_bloc.dart +++ b/lib/application/user_bloc/user_bloc.dart @@ -12,18 +12,18 @@ part 'user_state.dart'; class UserBloc extends Bloc { final GetCachedUserUseCase _getCachedUserUseCase; + final GetRemoteUserUsecase _getRemoteUserUseCase; final SignInUseCase _signInUseCase; - final SignUpUseCase _signUpUseCase; final SignOutUseCase _signOutUseCase; UserBloc( this._signInUseCase, this._getCachedUserUseCase, + this._getRemoteUserUseCase, this._signOutUseCase, - this._signUpUseCase, ) : super(UserInitial()) { on(_onSignIn); - on(_onSignUp); on(_onCheckUser); + on(_onGetRemoteUser); on(_onSignOut); } @@ -33,7 +33,7 @@ class UserBloc extends Bloc { final result = await _signInUseCase(event.params); result.fold( (failure) => emit(UserLoggedFail(failure)), - (user) => emit(UserLogged(user)), + (token) => emit(UserLogged(token)), ); } catch (e) { emit(UserLoggedFail(ExceptionFailure())); @@ -46,20 +46,7 @@ class UserBloc extends Bloc { final result = await _getCachedUserUseCase(NoParams()); result.fold( (failure) => emit(UserLoggedFail(failure)), - (user) => emit(UserLogged(user)), - ); - } catch (e) { - emit(UserLoggedFail(ExceptionFailure())); - } - } - - FutureOr _onSignUp(SignUpUser event, Emitter emit) async { - try { - emit(UserLoading()); - final result = await _signUpUseCase(event.params); - result.fold( - (failure) => emit(UserLoggedFail(failure)), - (user) => emit(UserLogged(user)), + (user) => emit(UserFetched(user)), ); } catch (e) { emit(UserLoggedFail(ExceptionFailure())); @@ -75,4 +62,36 @@ class UserBloc extends Bloc { emit(UserLoggedFail(ExceptionFailure())); } } + + FutureOr _onGetRemoteUser( + GetRemoteUser event, + Emitter emit, + ) async { + try { + emit(UserLoading()); + final result = await _getRemoteUserUseCase(NoParams()); + result.fold( + (failure) => emit(_mapFailureToState(failure)), + (user) => emit(UserFetched(user)), + ); + } catch (e) { + emit(UserLoggedFail(ExceptionFailure())); + } + } + + UserState _mapFailureToState(Failure failure) { + if (failure is ServerFailure) { + return UserLoggedFail(ServerFailure()); + } else if (failure is CacheFailure) { + return UserLoggedFail(CacheFailure()); + } else if (failure is NetworkFailure) { + return UserLoggedFail(NetworkFailure()); + } else if (failure is CredentialFailure) { + return UserLoggedFail(CredentialFailure()); + } else if (failure is AuthenticationFailure) { + return UserLoggedFail(AuthenticationFailure()); + } else { + return UserLoggedFail(ExceptionFailure()); + } + } } diff --git a/lib/application/user_bloc/user_event.dart b/lib/application/user_bloc/user_event.dart index 82910ca..757b795 100644 --- a/lib/application/user_bloc/user_event.dart +++ b/lib/application/user_bloc/user_event.dart @@ -8,11 +8,8 @@ class SignInUser extends UserEvent { SignInUser(this.params); } -class SignUpUser extends UserEvent { - final SignUpParams params; - SignUpUser(this.params); -} - class SignOutUser extends UserEvent {} class CheckUser extends UserEvent {} + +class GetRemoteUser extends UserEvent {} diff --git a/lib/application/user_bloc/user_state.dart b/lib/application/user_bloc/user_state.dart index 3868f38..f61435a 100644 --- a/lib/application/user_bloc/user_state.dart +++ b/lib/application/user_bloc/user_state.dart @@ -14,8 +14,15 @@ class UserLoading extends UserState { } class UserLogged extends UserState { + final String token; + UserLogged(this.token); + @override + List get props => [token]; +} + +class UserFetched extends UserState { final User user; - UserLogged(this.user); + UserFetched(this.user); @override List get props => [user]; } diff --git a/lib/core/enums/enums.dart b/lib/core/enums/enums.dart index 546b205..f25d7bd 100644 --- a/lib/core/enums/enums.dart +++ b/lib/core/enums/enums.dart @@ -1 +1 @@ -enum NavigationTab { homeTab, categoriesTab, productsTap, cartTab, profileTab } +enum NavigationTab { homeTab, history, profileTab } diff --git a/lib/data/data_sources/remote/user_remote_data_source.dart b/lib/data/data_sources/remote/user_remote_data_source.dart index 2d1ae4b..6cd61d3 100644 --- a/lib/data/data_sources/remote/user_remote_data_source.dart +++ b/lib/data/data_sources/remote/user_remote_data_source.dart @@ -1,6 +1,5 @@ import 'dart:convert'; -import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import '../../../core/core.dart'; @@ -8,8 +7,8 @@ import '../../../domain/domain.dart'; import '../../data.dart'; abstract class UserRemoteDataSource { - Future signIn(SignInParams params); - Future signUp(SignUpParams params); + Future signIn(SignInParams params); + Future getUser(String token); } class UserRemoteDataSourceImpl implements UserRemoteDataSource { @@ -17,66 +16,46 @@ class UserRemoteDataSourceImpl implements UserRemoteDataSource { UserRemoteDataSourceImpl({required this.client}); @override - Future signIn(SignInParams params) async { - debugPrint('signIn'); - - try { - final response = await client.post(Uri.parse('$baseUrl/Authentication/Authenticate'), - headers: { - 'Content-Type': 'application/json', - 'accept': '*/*', - }, - body: json.encode({ - 'UserName': params.username, - 'Password': '', // params.password, - })); - if (response.statusCode == 200) { - const userData = ''' - { - "token": "", - "user": { - "_id": "user123", - "firstName": "John", - "lastName": "Doe", - "email": "john.doe@example.com" - } - } - '''; - AuthenticationResponseModel user = authenticationResponseModelFromJson(userData); - - // Update the token value - AuthenticationResponseModel updatedUser = user.copyWith(token: response.body); - - return updatedUser; - } else if (response.statusCode == 400 || response.statusCode == 401) { - throw CredentialFailure(); - } else { - throw ServerException(); - } - } catch (e) { - debugPrint('e $e'); - throw ServerException(); - } - } - - @override - Future signUp(SignUpParams params) async { - final response = await client.post(Uri.parse('$baseUrl/authentication/local/sign-up'), - headers: { - 'Content-Type': 'application/json', + Future signIn(SignInParams params) async { + final response = await client.post( + Uri.parse('$baseUrl/Authentication/Authenticate'), + headers: { + 'Content-Type': 'application/json', + 'accept': '*/*', + }, + body: json.encode( + { + 'UserName': params.username, + 'Password': params.password, }, - body: json.encode({ - 'firstName': params.firstName, - 'lastName': params.lastName, - 'email': params.email, - 'password': params.password, - })); - if (response.statusCode == 201) { - return authenticationResponseModelFromJson(response.body); + ), + ); + + if (response.statusCode == 200) { + return response.body; } else if (response.statusCode == 400 || response.statusCode == 401) { throw CredentialFailure(); } else { throw ServerException(); } } + + @override + Future getUser(String token) async { + final response = await client.get( + Uri.parse('$baseUrl/Client/GetClient'), + headers: { + 'Content-Type': 'application/json', + 'accept': '*/*', + 'Authorization': 'Bearer $token', + }, + ); + + if (response.statusCode == 200) { + final user = UserModel.fromJson(json.decode(response.body)); + return user; + } else { + throw ServerException(); + } + } } diff --git a/lib/data/models/user/authentication_response_model.dart b/lib/data/models/user/authentication_response_model.dart index ccc984c..5f57ca1 100644 --- a/lib/data/models/user/authentication_response_model.dart +++ b/lib/data/models/user/authentication_response_model.dart @@ -1,38 +1,38 @@ -import 'dart:convert'; +// import 'dart:convert'; -import 'user_model.dart'; +// import 'user_model.dart'; -AuthenticationResponseModel authenticationResponseModelFromJson(String str) => - AuthenticationResponseModel.fromJson(json.decode(str)); +// AuthenticationResponseModel authenticationResponseModelFromJson(String str) => +// AuthenticationResponseModel.fromJson(json.decode(str)); -String authenticationResponseModelToJson(AuthenticationResponseModel data) => json.encode(data.toJson()); +// String authenticationResponseModelToJson(AuthenticationResponseModel data) => json.encode(data.toJson()); -class AuthenticationResponseModel { - final String token; - final UserModel user; +// class AuthenticationResponseModel { +// final String token; +// final UserModel user; - const AuthenticationResponseModel({ - required this.token, - required this.user, - }); +// const AuthenticationResponseModel({ +// required this.token, +// required this.user, +// }); - factory AuthenticationResponseModel.fromJson(Map json) => AuthenticationResponseModel( - token: json['token'], - user: UserModel.fromJson(json['user']), - ); +// factory AuthenticationResponseModel.fromJson(Map json) => AuthenticationResponseModel( +// token: json['token'], +// user: UserModel.fromJson(json['user']), +// ); - Map toJson() => { - 'token': token, - 'user': user.toJson(), - }; +// Map toJson() => { +// 'token': token, +// 'user': user.toJson(), +// }; - AuthenticationResponseModel copyWith({ - String? token, - UserModel? user, - }) { - return AuthenticationResponseModel( - token: token ?? this.token, - user: user ?? this.user, - ); - } -} +// AuthenticationResponseModel copyWith({ +// String? token, +// UserModel? user, +// }) { +// return AuthenticationResponseModel( +// token: token ?? this.token, +// user: user ?? this.user, +// ); +// } +// } diff --git a/lib/data/models/user/user_model.dart b/lib/data/models/user/user_model.dart index 07db3e2..33fbb35 100644 --- a/lib/data/models/user/user_model.dart +++ b/lib/data/models/user/user_model.dart @@ -8,23 +8,28 @@ String userModelToJson(UserModel data) => json.encode(data.toJson()); class UserModel extends User { const UserModel({ - required super.id, - required super.firstName, - required super.lastName, - required super.email, + required super.oid, + required super.fullName, + required super.phone, }); + factory UserModel.fromUser(User user) { + return UserModel( + oid: user.oid, + fullName: user.fullName, + phone: user.phone, + ); + } + factory UserModel.fromJson(Map json) => UserModel( - id: json['_id'], - firstName: json['firstName'], - lastName: json['lastName'], - email: json['email'], + oid: json['Oid'], + fullName: json['FullName'], + phone: json['PhoneNo'], ); Map toJson() => { - '_id': id, - 'firstName': firstName, - 'lastName': lastName, - 'email': email, + 'Oid': oid, + 'FullName': fullName, + 'PhoneNo': phone, }; } diff --git a/lib/data/repositories/user_repository_impl.dart b/lib/data/repositories/user_repository_impl.dart index d30ab5d..034ef76 100644 --- a/lib/data/repositories/user_repository_impl.dart +++ b/lib/data/repositories/user_repository_impl.dart @@ -2,10 +2,7 @@ import 'package:dartz/dartz.dart'; import '../../core/core.dart'; import '../../domain/domain.dart'; -import '../data_sources/data_sources.dart'; -import '../models/user/authentication_response_model.dart'; - -typedef _DataSourceChooser = Future Function(); +import '../data.dart'; class UserRepositoryImpl implements UserRepository { final UserRemoteDataSource remoteDataSource; @@ -19,17 +16,18 @@ class UserRepositoryImpl implements UserRepository { }); @override - Future> signIn(params) async { - return await _authenticate(() { - return remoteDataSource.signIn(params); - }); - } - - @override - Future> signUp(params) async { - return await _authenticate(() { - return remoteDataSource.signUp(params); - }); + Future> signIn(params) async { + if (await networkInfo.isConnected) { + try { + final token = await remoteDataSource.signIn(params); + localDataSource.saveToken(token); + return Right(token); + } on Failure catch (failure) { + return Left(failure); + } + } else { + return Left(NetworkFailure()); + } } @override @@ -52,20 +50,23 @@ class UserRepositoryImpl implements UserRepository { } } - Future> _authenticate( - _DataSourceChooser getDataSource, - ) async { - if (await networkInfo.isConnected) { - try { - final remoteResponse = await getDataSource(); - localDataSource.saveToken(remoteResponse.token); - localDataSource.saveUser(remoteResponse.user); - return Right(remoteResponse.user); - } on Failure catch (failure) { - return Left(failure); - } - } else { + @override + Future> getRemoteUser() async { + if (!await networkInfo.isConnected) { return Left(NetworkFailure()); } + + if (!await localDataSource.isTokenAvailable()) { + return Left(AuthenticationFailure()); + } + + try { + final String token = await localDataSource.getToken(); + final user = await remoteDataSource.getUser(token); + await localDataSource.saveUser(UserModel.fromUser(user)); + return Right(user); + } on Failure catch (failure) { + return Left(failure); + } } } diff --git a/lib/di/user.dart b/lib/di/user.dart index 04ba987..5035cd8 100644 --- a/lib/di/user.dart +++ b/lib/di/user.dart @@ -10,8 +10,8 @@ void registerUserFeature() { sl.registerFactory(() => UserBloc(sl(), sl(), sl(), sl())); sl.registerLazySingleton(() => GetCachedUserUseCase(sl())); sl.registerLazySingleton(() => SignInUseCase(sl())); - sl.registerLazySingleton(() => SignUpUseCase(sl())); sl.registerLazySingleton(() => SignOutUseCase(sl())); + sl.registerLazySingleton(() => GetRemoteUserUsecase(sl())); // User Repository and Data Sources sl.registerLazySingleton( diff --git a/lib/domain/entities/user/user.dart b/lib/domain/entities/user/user.dart index 9660f48..d586d9a 100644 --- a/lib/domain/entities/user/user.dart +++ b/lib/domain/entities/user/user.dart @@ -1,25 +1,20 @@ import 'package:equatable/equatable.dart'; class User extends Equatable { - final String id; - final String firstName; - final String lastName; - final String? image; - final String email; + final String oid; + final String fullName; + final String phone; const User({ - required this.id, - required this.firstName, - required this.lastName, - this.image, - required this.email, + required this.oid, + required this.fullName, + required this.phone, }); @override List get props => [ - id, - firstName, - lastName, - email, + oid, + fullName, + phone, ]; } diff --git a/lib/domain/repositories/user_repository.dart b/lib/domain/repositories/user_repository.dart index 8fe325f..8245bb6 100644 --- a/lib/domain/repositories/user_repository.dart +++ b/lib/domain/repositories/user_repository.dart @@ -4,8 +4,8 @@ import '../../core/core.dart'; import '../domain.dart'; abstract class UserRepository { - Future> signIn(SignInParams params); - Future> signUp(SignUpParams params); + Future> signIn(SignInParams params); Future> signOut(); Future> getCachedUser(); + Future> getRemoteUser(); } diff --git a/lib/domain/usecases/user/get_remote_user_usecase.dart b/lib/domain/usecases/user/get_remote_user_usecase.dart new file mode 100644 index 0000000..e54945a --- /dev/null +++ b/lib/domain/usecases/user/get_remote_user_usecase.dart @@ -0,0 +1,14 @@ +import 'package:dartz/dartz.dart'; + +import '../../../core/core.dart'; +import '../../domain.dart'; + +class GetRemoteUserUsecase implements UseCase { + final UserRepository repository; + GetRemoteUserUsecase(this.repository); + + @override + Future> call(NoParams params) async { + return await repository.getRemoteUser(); + } +} diff --git a/lib/domain/usecases/user/sign_in_usecase.dart b/lib/domain/usecases/user/sign_in_usecase.dart index c7387e6..f36257e 100644 --- a/lib/domain/usecases/user/sign_in_usecase.dart +++ b/lib/domain/usecases/user/sign_in_usecase.dart @@ -3,12 +3,12 @@ import 'package:dartz/dartz.dart'; import '../../../core/core.dart'; import '../../domain.dart'; -class SignInUseCase implements UseCase { +class SignInUseCase implements UseCase { final UserRepository repository; SignInUseCase(this.repository); @override - Future> call(SignInParams params) async { + Future> call(SignInParams params) async { return await repository.signIn(params); } } diff --git a/lib/domain/usecases/user/sign_up_usecase.dart b/lib/domain/usecases/user/sign_up_usecase.dart index f247a93..abeaf13 100644 --- a/lib/domain/usecases/user/sign_up_usecase.dart +++ b/lib/domain/usecases/user/sign_up_usecase.dart @@ -1,27 +1,27 @@ -import 'package:dartz/dartz.dart'; +// import 'package:dartz/dartz.dart'; -import '../../../core/core.dart'; -import '../../domain.dart'; +// import '../../../core/core.dart'; +// import '../../domain.dart'; -class SignUpUseCase implements UseCase { - final UserRepository repository; - SignUpUseCase(this.repository); +// class SignUpUseCase implements UseCase { +// final UserRepository repository; +// SignUpUseCase(this.repository); - @override - Future> call(SignUpParams params) async { - return await repository.signUp(params); - } -} +// @override +// Future> call(SignUpParams params) async { +// return await repository.signUp(params); +// } +// } -class SignUpParams { - final String firstName; - final String lastName; - final String email; - final String password; - const SignUpParams({ - required this.firstName, - required this.lastName, - required this.email, - required this.password, - }); -} +// class SignUpParams { +// final String firstName; +// final String lastName; +// final String email; +// final String password; +// const SignUpParams({ +// required this.firstName, +// required this.lastName, +// required this.email, +// required this.password, +// }); +// } diff --git a/lib/domain/usecases/user/user.dart b/lib/domain/usecases/user/user.dart index c74d27d..f58e643 100644 --- a/lib/domain/usecases/user/user.dart +++ b/lib/domain/usecases/user/user.dart @@ -2,3 +2,4 @@ export 'get_cached_user_usecase.dart'; export 'sign_in_usecase.dart'; export 'sign_out_usecase.dart'; export 'sign_up_usecase.dart'; +export 'get_remote_user_usecase.dart'; diff --git a/lib/presentation/screens/profile.dart b/lib/presentation/screens/profile.dart index ab62304..f474006 100644 --- a/lib/presentation/screens/profile.dart +++ b/lib/presentation/screens/profile.dart @@ -1,166 +1,380 @@ -import 'package:cargo/presentation/presentation.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../application/user_bloc/user_bloc.dart'; import '../../configs/configs.dart'; import '../../core/core.dart'; +import '../../domain/entities/user/user.dart'; +import '../widgets/lang_selection.dart'; -class ProfileScreen extends StatelessWidget { +class ProfileScreen extends StatefulWidget { const ProfileScreen({super.key}); + @override + State createState() => _ProfileScreenState(); +} + +class _ProfileScreenState extends State { + @override + void initState() { + context.read().add(GetRemoteUser()); + super.initState(); + } + @override Widget build(BuildContext context) { App.init(context); return Scaffold( - // appBar: AppBar(), backgroundColor: AppColors.surface, - body: SingleChildScrollView( - child: Padding( - padding: Space.all(1, 1), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - /// gap - Space.yf(1), + body: BlocBuilder( + builder: (context, state) { + if (state is UserLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is UserFetched) { + return _buildProfileContent(context, state.user); + } else if (state is UserLoggedFail) { + return _buildErrorContent(context, state.failure); + } else { + return const SizedBox.shrink(); + } + }, + ), + ); + } - /// header - Text( - 'Şahsy otagym', - style: AppText.h1b, - ), + Widget _buildProfileContent(BuildContext context, User user) { + return SingleChildScrollView( + child: Padding( + padding: Space.all(1, 1), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + /// gap + Space.yf(1), - Space.y!, + /// header + Text( + 'Şahsy otagym', + style: AppText.h1b, + ), - /// card - SizedBox( - width: double.infinity, - child: Card( - color: Colors.white, - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - children: [ - /// identity - const RowWidget( - text: 'ABC1234567890!@#', - leadingIcon: Icons.verified_user_outlined, - ), + Space.y!, - /// gap - Space.yf(1), + /// card + SizedBox( + width: double.infinity, + child: Card( + color: Colors.white, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + /// name surname + RowWidget( + text: user.fullName, + leadingIcon: Icons.person_2_outlined, + trailingIcon: Icons.mode_edit_outlined, + ), - /// name surname - const RowWidget( - text: 'Maksat Üstünlikow', - leadingIcon: Icons.person_2_outlined, - trailingIcon: Icons.mode_edit_outlined, - ), + /// gap + Space.yf(1), - /// gap - Space.yf(1), - - /// phone - const RowWidget( - text: '+993 (XX) XX-XX-XX', - leadingIcon: Icons.phone_android_outlined, - trailingIcon: Icons.mode_edit_outlined, - ), - ], - ), + /// phone + RowWidget( + text: user.phone, + leadingIcon: Icons.phone_android_outlined, + trailingIcon: Icons.mode_edit_outlined, + ), + ], ), ), ), + ), - ///gap - Space.yf(2), + ///gap + Space.yf(2), - /// card - const SizedBox( - width: double.infinity, - child: Card( - color: Colors.white, - child: Padding( - padding: EdgeInsets.all(16.0), - child: RowWidget( - text: 'Tehniki goldaw bilen habarlaşmak', - leadingIcon: Icons.contact_support_outlined, - trailingIcon: Icons.arrow_forward_ios, - ), + /// card + const SizedBox( + width: double.infinity, + child: Card( + color: Colors.white, + child: Padding( + padding: EdgeInsets.all(16.0), + child: RowWidget( + text: 'Tehniki goldaw bilen habarlaşmak', + leadingIcon: Icons.contact_support_outlined, + trailingIcon: Icons.arrow_forward_ios, ), ), ), + ), - ///gap - Space.yf(2), + ///gap + Space.yf(2), - /// card - SizedBox( - width: double.infinity, - child: Card( - color: Colors.white, - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - children: [ - /// language - GestureDetector( - onTap: () => onSelectLang(context), - child: Container( - color: Colors.transparent, - child: RowWidget( - text: 'profile_select_lang'.tr(), - leadingIcon: Icons.language_outlined, - trailingIcon: Icons.arrow_forward_ios, - ), + /// card + SizedBox( + width: double.infinity, + child: Card( + color: Colors.white, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + /// language + GestureDetector( + onTap: () => onSelectLang(context), + child: Container( + color: Colors.transparent, + child: RowWidget( + text: 'profile_select_lang'.tr(), + leadingIcon: Icons.language_outlined, + trailingIcon: Icons.arrow_forward_ios, ), ), + ), - /// name surname - const RowWidget( - text: 'Gizlinlik syýasaty', - leadingIcon: Icons.gpp_maybe_outlined, - trailingIcon: Icons.arrow_forward_ios, - ), + /// name surname + const RowWidget( + text: 'Gizlinlik syýasaty', + leadingIcon: Icons.gpp_maybe_outlined, + trailingIcon: Icons.arrow_forward_ios, + ), - /// phone - const RowWidget( - text: 'Ulanyş şertleri', - leadingIcon: Icons.file_copy_outlined, - trailingIcon: Icons.arrow_forward_ios, - ), - ], - ), + /// phone + const RowWidget( + text: 'Ulanyş şertleri', + leadingIcon: Icons.file_copy_outlined, + trailingIcon: Icons.arrow_forward_ios, + ), + ], ), ), ), + ), - ///gap - Space.yf(2), + ///gap + Space.yf(2), - /// logout - Align( - alignment: Alignment.center, - child: TextButton( - onPressed: () {}, - child: Text( - 'Şahsy otagdan çykmak', - style: AppText.b1!.copyWith( - color: Colors.red, - ), + /// logout + Align( + alignment: Alignment.center, + child: TextButton( + onPressed: () {}, + child: Text( + 'Şahsy otagdan çykmak', + style: AppText.b1!.copyWith( + color: Colors.red, ), ), ), + ), - ///gap - Space.yf(2), - ], - ), + ///gap + Space.yf(2), + ], ), ), ); } + + Widget _buildErrorContent(BuildContext context, Failure failure) { + String errorMessage; + if (failure is ServerFailure) { + errorMessage = 'Server failure. Please try again later.'; + } else if (failure is CacheFailure) { + errorMessage = 'Cache failure. Please try again later.'; + } else if (failure is NetworkFailure) { + errorMessage = 'No network connection. Please check your internet.'; + } else if (failure is CredentialFailure) { + errorMessage = 'Invalid credentials. Please try again.'; + } else if (failure is AuthenticationFailure) { + errorMessage = 'Authentication failure. Please log in again.'; + } else { + errorMessage = 'An unknown error occurred. Please try again.'; + } + + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + errorMessage, + style: const TextStyle(color: Colors.red), + textAlign: TextAlign.center, + ), + const SizedBox(height: 20), + ElevatedButton( + onPressed: () { + // Optionally, you can provide a retry mechanism + context.read().add(GetRemoteUser()); + }, + child: const Text('Retry'), + ), + ], + ), + ); + } } +// class ProfileScreen extends StatelessWidget { +// const ProfileScreen({super.key}); + +// @override +// Widget build(BuildContext context) { +// App.init(context); +// return Scaffold( +// // appBar: AppBar(), +// backgroundColor: AppColors.surface, +// body: SingleChildScrollView( +// child: Padding( +// padding: Space.all(1, 1), +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// /// gap +// Space.yf(1), + +// /// header +// Text( +// 'Şahsy otagym', +// style: AppText.h1b, +// ), + +// Space.y!, + +// /// card +// SizedBox( +// width: double.infinity, +// child: Card( +// color: Colors.white, +// child: Padding( +// padding: const EdgeInsets.all(16.0), +// child: Column( +// children: [ +// /// identity +// // const RowWidget( +// // text: 'ABC1234567890!@#', +// // leadingIcon: Icons.verified_user_outlined, +// // ), + +// /// gap +// // Space.yf(1), + +// /// name surname +// const RowWidget( +// text: 'Maksat Üstünlikow', +// leadingIcon: Icons.person_2_outlined, +// trailingIcon: Icons.mode_edit_outlined, +// ), + +// /// gap +// Space.yf(1), + +// /// phone +// const RowWidget( +// text: '+993 (XX) XX-XX-XX', +// leadingIcon: Icons.phone_android_outlined, +// trailingIcon: Icons.mode_edit_outlined, +// ), +// ], +// ), +// ), +// ), +// ), + +// ///gap +// Space.yf(2), + +// /// card +// const SizedBox( +// width: double.infinity, +// child: Card( +// color: Colors.white, +// child: Padding( +// padding: EdgeInsets.all(16.0), +// child: RowWidget( +// text: 'Tehniki goldaw bilen habarlaşmak', +// leadingIcon: Icons.contact_support_outlined, +// trailingIcon: Icons.arrow_forward_ios, +// ), +// ), +// ), +// ), + +// ///gap +// Space.yf(2), + +// /// card +// SizedBox( +// width: double.infinity, +// child: Card( +// color: Colors.white, +// child: Padding( +// padding: const EdgeInsets.all(16.0), +// child: Column( +// children: [ +// /// language +// GestureDetector( +// onTap: () => onSelectLang(context), +// child: Container( +// color: Colors.transparent, +// child: RowWidget( +// text: 'profile_select_lang'.tr(), +// leadingIcon: Icons.language_outlined, +// trailingIcon: Icons.arrow_forward_ios, +// ), +// ), +// ), + +// /// name surname +// const RowWidget( +// text: 'Gizlinlik syýasaty', +// leadingIcon: Icons.gpp_maybe_outlined, +// trailingIcon: Icons.arrow_forward_ios, +// ), + +// /// phone +// const RowWidget( +// text: 'Ulanyş şertleri', +// leadingIcon: Icons.file_copy_outlined, +// trailingIcon: Icons.arrow_forward_ios, +// ), +// ], +// ), +// ), +// ), +// ), + +// ///gap +// Space.yf(2), + +// /// logout +// Align( +// alignment: Alignment.center, +// child: TextButton( +// onPressed: () {}, +// child: Text( +// 'Şahsy otagdan çykmak', +// style: AppText.b1!.copyWith( +// color: Colors.red, +// ), +// ), +// ), +// ), + +// ///gap +// Space.yf(2), +// ], +// ), +// ), +// ), +// ); +// } +// } + class RowWidget extends StatelessWidget { final String text; final IconData leadingIcon; diff --git a/lib/presentation/screens/root.dart b/lib/presentation/screens/root.dart index 669d39d..dfc4c22 100644 --- a/lib/presentation/screens/root.dart +++ b/lib/presentation/screens/root.dart @@ -66,9 +66,9 @@ class RootScreen extends StatelessWidget { switch (activeTab) { case NavigationTab.homeTab: return const OrdersScreen(); - case NavigationTab.categoriesTab: + case NavigationTab.history: return const Text(' CategoriesScreen()'); - case NavigationTab.productsTap: + case NavigationTab.profileTab: return const ProfileScreen(); default: return const OrdersScreen();