first commit
This commit is contained in:
37
lib/modules/profile/bloc/logout/logout_cubit.dart
Normal file
37
lib/modules/profile/bloc/logout/logout_cubit.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/services/crashlytics_service.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/bloc/logout/logout_state.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/data/repositories/profile_repository.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@injectable
|
||||
class LogoutCubit extends Cubit<LogoutState> {
|
||||
LogoutCubit(this._repository) : super(LogoutInitial());
|
||||
|
||||
final ProfileRepository _repository;
|
||||
|
||||
Future<void> logout() async {
|
||||
emit(LogoutLoading());
|
||||
|
||||
try {
|
||||
final response = await _repository.logout();
|
||||
|
||||
if (response.status != 'success') {
|
||||
emit(LogoutFailure(response.message));
|
||||
return;
|
||||
}
|
||||
emit(LogoutSuccess());
|
||||
} on DioException catch (e) {
|
||||
emit(LogoutFailure(e.error?.toString()));
|
||||
} catch (e, s) {
|
||||
await CrashlyticsService.recordError(
|
||||
e,
|
||||
s,
|
||||
fatal: true,
|
||||
reason: 'Logout Unknown Error',
|
||||
);
|
||||
emit(const LogoutFailure());
|
||||
}
|
||||
}
|
||||
}
|
||||
25
lib/modules/profile/bloc/logout/logout_state.dart
Normal file
25
lib/modules/profile/bloc/logout/logout_state.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class LogoutState extends Equatable {
|
||||
const LogoutState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class LogoutInitial extends LogoutState {}
|
||||
|
||||
class LogoutLoading extends LogoutState {}
|
||||
|
||||
class LogoutSuccess extends LogoutState {}
|
||||
|
||||
class LogoutFailure extends LogoutState {
|
||||
const LogoutFailure([this.message]);
|
||||
|
||||
final String? message;
|
||||
|
||||
bool get hasMessage => message != null && message!.isNotEmpty;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
1
lib/modules/profile/bloc/profile/profile_cubit.dart
Normal file
1
lib/modules/profile/bloc/profile/profile_cubit.dart
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
1
lib/modules/profile/bloc/profile/profile_state.dart
Normal file
1
lib/modules/profile/bloc/profile/profile_state.dart
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/constants/dio_constant.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/network/api_endpoint.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/network/dio_client.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/data/model/logout/logout_response.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@lazySingleton
|
||||
class ProfileRemoteDataSource {
|
||||
final Dio _dio = DioClient.getInstance();
|
||||
|
||||
Future<LogoutResponse> logout() async {
|
||||
try {
|
||||
final response = await _dio.post<Map<String, dynamic>>(
|
||||
ApiEndpoint.logout,
|
||||
options: Options(
|
||||
extra: {DioExtraKey.noAuth: false},
|
||||
),
|
||||
);
|
||||
|
||||
final data = response.data;
|
||||
if (data == null) {
|
||||
throw Exception('EMPTY_RESPONSE');
|
||||
}
|
||||
|
||||
return LogoutResponse.fromJson(data);
|
||||
} on DioException catch (e) {
|
||||
final responseData = e.response?.data;
|
||||
if (responseData is Map<String, dynamic>) {
|
||||
return LogoutResponse.fromJson(responseData);
|
||||
}
|
||||
throw Exception(e.error?.toString() ?? 'LOGOUT_FAILED');
|
||||
}
|
||||
}
|
||||
}
|
||||
16
lib/modules/profile/data/model/logout/logout_response.dart
Normal file
16
lib/modules/profile/data/model/logout/logout_response.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
class LogoutResponse {
|
||||
LogoutResponse({
|
||||
required this.status,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
factory LogoutResponse.fromJson(Map<String, dynamic> json) {
|
||||
return LogoutResponse(
|
||||
status: json['status']?.toString() ?? '',
|
||||
message: json['message']?.toString() ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
final String status;
|
||||
final String message;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:frontend_eccp_mobile/modules/profile/data/datasources/profile_remote_datasource.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/data/model/logout/logout_response.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@lazySingleton
|
||||
class ProfileRepository {
|
||||
ProfileRepository(this._remoteDatasource);
|
||||
|
||||
final ProfileRemoteDataSource _remoteDatasource;
|
||||
|
||||
Future<LogoutResponse> logout() async {
|
||||
return _remoteDatasource.logout();
|
||||
}
|
||||
}
|
||||
160
lib/modules/profile/presentation/screen/profile_page.dart
Normal file
160
lib/modules/profile/presentation/screen/profile_page.dart
Normal file
@@ -0,0 +1,160 @@
|
||||
import 'package:clipboard/clipboard.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/constants/constants.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/constants/enum/snackbar_type_enum.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/di/injection.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/handler/auth_handler.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/navigation/app_navigator.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/navigation/app_routes.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/notification/fcm_token_manager.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/utils/show_message.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/utils/token_manager.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/widgets/app_button.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/widgets/layout/app_screen.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/bloc/logout/logout_cubit.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/bloc/logout/logout_state.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/presentation/widgets/profile_header_card.dart';
|
||||
import 'package:frontend_eccp_mobile/modules/profile/presentation/widgets/profile_menu_section.dart';
|
||||
import 'package:iconsax_plus/iconsax_plus.dart';
|
||||
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
|
||||
|
||||
class ProfilePage extends StatelessWidget {
|
||||
const ProfilePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => getIt<LogoutCubit>(),
|
||||
child: const ProfileUI(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ProfileUI extends StatefulWidget {
|
||||
const ProfileUI({super.key});
|
||||
|
||||
@override
|
||||
State<ProfileUI> createState() => _ProfileUIState();
|
||||
}
|
||||
|
||||
class _ProfileUIState extends State<ProfileUI> {
|
||||
final RefreshController _refreshController = RefreshController();
|
||||
|
||||
Future<void> _onRefresh() async {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 800));
|
||||
_refreshController.refreshCompleted();
|
||||
}
|
||||
|
||||
bool get isTablet => MediaQuery.of(context).size.width > 600;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<LogoutCubit, LogoutState>(
|
||||
listener: (context, state) async {
|
||||
if (state is LogoutLoading) return;
|
||||
|
||||
await TokenManager.clearToken();
|
||||
|
||||
if (!context.mounted) return;
|
||||
|
||||
await AppNavigator.clearAndPush(
|
||||
context,
|
||||
AppRoutes.login,
|
||||
);
|
||||
},
|
||||
builder: (context, state) {
|
||||
return AppScreen(
|
||||
title: 'PROFIL',
|
||||
backgroundColor: AppColors.neutral50,
|
||||
refreshController: _refreshController,
|
||||
enablePullDown: true,
|
||||
onRefresh: _onRefresh,
|
||||
refreshHeader: const ClassicHeader(),
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 900),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
AppSpacing.h16,
|
||||
|
||||
const Padding(
|
||||
padding: AppPadding.h16,
|
||||
child: ProfileHeaderCard(),
|
||||
),
|
||||
|
||||
AppSpacing.h24,
|
||||
|
||||
ProfileMenuSection(
|
||||
title: 'Personal Information',
|
||||
items: [
|
||||
ProfileMenuItem(
|
||||
icon: IconsaxPlusLinear.personalcard,
|
||||
label: 'My Details',
|
||||
iconColor: AppColors.neutral900,
|
||||
),
|
||||
ProfileMenuItem(
|
||||
icon: IconsaxPlusLinear.lock,
|
||||
label: 'Change Password',
|
||||
iconColor: AppColors.neutral900,
|
||||
),
|
||||
ProfileMenuItem(
|
||||
icon: IconsaxPlusLinear.notification_1,
|
||||
label: 'Copy FCM Token',
|
||||
iconColor: AppColors.neutral900,
|
||||
onTap: () async {
|
||||
final token = await FcmTokenManager.getToken();
|
||||
await FlutterClipboard.copy(token ?? '');
|
||||
if (!context.mounted) return;
|
||||
showMessage(
|
||||
context,
|
||||
'FCM Token copied : \n${token ?? ''}',
|
||||
SnackBarType.success,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
AppSpacing.h16,
|
||||
|
||||
Padding(
|
||||
padding: AppPadding.p16,
|
||||
child: AppButton(
|
||||
height: 48,
|
||||
paddingVertical: 0,
|
||||
label: '',
|
||||
customContent: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.logout_rounded,
|
||||
color: Colors.white,
|
||||
),
|
||||
AppSpacing.w6,
|
||||
Text(
|
||||
'Log Out',
|
||||
style: AppTextStyles.label.copyWith(
|
||||
color: AppColors.neutralWhite,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
isExpanded: true,
|
||||
onPressed: () async {
|
||||
await AuthHandler.logout(context);
|
||||
},
|
||||
isLoading: state is LogoutLoading,
|
||||
),
|
||||
),
|
||||
|
||||
AppSpacing.h32,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/constants/constants.dart';
|
||||
|
||||
class ProfileHeaderCard extends StatelessWidget {
|
||||
const ProfileHeaderCard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: AppPadding.p14,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.neutralWhite,
|
||||
borderRadius: AppRadius.r18,
|
||||
boxShadow: AppShadows.md,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: AppRadius.rFull,
|
||||
child: Image.network(
|
||||
'https://i.pravatar.cc/150?img=12',
|
||||
width: 64,
|
||||
height: 64,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
|
||||
AppSpacing.w14,
|
||||
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Rosaldo',
|
||||
style: AppTextStyles.h3,
|
||||
),
|
||||
|
||||
AppSpacing.h2,
|
||||
|
||||
Text(
|
||||
'NRP : 1882098',
|
||||
style: AppTextStyles.badge.copyWith(
|
||||
color: AppColors.neutral600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:frontend_eccp_mobile/app/core/constants/constants.dart';
|
||||
|
||||
class ProfileMenuSection extends StatelessWidget {
|
||||
const ProfileMenuSection({
|
||||
required this.title,
|
||||
required this.items,
|
||||
this.backgroundColor = Colors.white,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final List<ProfileMenuItem> items;
|
||||
final Color backgroundColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: AppPadding.h16,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.section,
|
||||
),
|
||||
|
||||
AppSpacing.h12,
|
||||
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
borderRadius: AppRadius.r14,
|
||||
boxShadow: AppShadows.md,
|
||||
),
|
||||
child: Column(
|
||||
children: List.generate(
|
||||
items.length,
|
||||
(index) {
|
||||
final item = items[index];
|
||||
final isLast = index == items.length - 1;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_ProfileMenuTile(item: item),
|
||||
|
||||
if (!isLast)
|
||||
Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: AppColors.neutral200,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ProfileMenuItem {
|
||||
ProfileMenuItem({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.iconColor,
|
||||
this.onTap,
|
||||
this.useArrow = true,
|
||||
this.color,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final bool useArrow;
|
||||
final VoidCallback? onTap;
|
||||
Color? color = AppColors.supportSteel600;
|
||||
Color iconColor;
|
||||
}
|
||||
|
||||
class _ProfileMenuTile extends StatelessWidget {
|
||||
const _ProfileMenuTile({
|
||||
required this.item,
|
||||
});
|
||||
|
||||
final ProfileMenuItem item;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
borderRadius: AppRadius.r14,
|
||||
onTap: item.onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 14,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
color: item.iconColor.withValues(alpha: 0.1),
|
||||
),
|
||||
padding: AppPadding.p6,
|
||||
child: Icon(
|
||||
item.icon,
|
||||
size: AppIconSizes.md,
|
||||
color: item.iconColor,
|
||||
),
|
||||
),
|
||||
|
||||
AppSpacing.w12,
|
||||
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.label,
|
||||
style: AppTextStyles.body.copyWith(
|
||||
color: item.color,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (item.useArrow)
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
size: AppIconSizes.lg,
|
||||
color: AppColors.neutral400,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user