update forgot password
This commit is contained in:
@@ -9,20 +9,23 @@
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:worker/core/constants/ui_constants.dart';
|
||||
import 'package:worker/core/database/hive_initializer.dart';
|
||||
import 'package:worker/core/router/app_router.dart';
|
||||
import 'package:worker/core/theme/colors.dart';
|
||||
import 'package:worker/features/account/presentation/widgets/account_menu_item.dart';
|
||||
import 'package:worker/features/auth/presentation/providers/auth_provider.dart';
|
||||
|
||||
/// Account Page
|
||||
///
|
||||
/// Main account/settings page accessible from the bottom navigation bar.
|
||||
class AccountPage extends StatelessWidget {
|
||||
class AccountPage extends ConsumerWidget {
|
||||
const AccountPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF4F6F8),
|
||||
body: SafeArea(
|
||||
@@ -43,7 +46,7 @@ class AccountPage extends StatelessWidget {
|
||||
_buildSupportSection(context),
|
||||
|
||||
// Logout Button
|
||||
_buildLogoutButton(context),
|
||||
_buildLogoutButton(context, ref),
|
||||
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
],
|
||||
@@ -299,13 +302,13 @@ class AccountPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Build logout button
|
||||
Widget _buildLogoutButton(BuildContext context) {
|
||||
Widget _buildLogoutButton(BuildContext context, WidgetRef ref) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: AppSpacing.md),
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
_showLogoutConfirmation(context);
|
||||
_showLogoutConfirmation(context, ref);
|
||||
},
|
||||
icon: const Icon(Icons.logout),
|
||||
label: const Text('Đăng xuất'),
|
||||
@@ -333,7 +336,7 @@ class AccountPage extends StatelessWidget {
|
||||
|
||||
/// Show about dialog
|
||||
void _showAboutDialog(BuildContext context) {
|
||||
showDialog(
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Về ứng dụng'),
|
||||
@@ -365,8 +368,8 @@ class AccountPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Show logout confirmation dialog
|
||||
void _showLogoutConfirmation(BuildContext context) {
|
||||
showDialog(
|
||||
void _showLogoutConfirmation(BuildContext context, WidgetRef ref) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Đăng xuất'),
|
||||
@@ -377,15 +380,7 @@ class AccountPage extends StatelessWidget {
|
||||
child: const Text('Hủy'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Đã đăng xuất'),
|
||||
duration: Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
},
|
||||
onPressed: () => _performLogout(context, ref),
|
||||
style: TextButton.styleFrom(foregroundColor: AppColors.danger),
|
||||
child: const Text('Đăng xuất'),
|
||||
),
|
||||
@@ -393,4 +388,87 @@ class AccountPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Perform logout operation
|
||||
///
|
||||
/// Handles the complete logout process:
|
||||
/// 1. Close confirmation dialog
|
||||
/// 2. Show loading indicator
|
||||
/// 3. Clear Hive local data
|
||||
/// 4. Call auth provider logout (clears session, gets new public session)
|
||||
/// 5. Navigate to login screen (handled by router redirect)
|
||||
/// 6. Show success message
|
||||
Future<void> _performLogout(BuildContext context, WidgetRef ref) async {
|
||||
// Close confirmation dialog
|
||||
Navigator.of(context).pop();
|
||||
|
||||
// Show loading dialog
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => const Center(
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 16),
|
||||
Text('Đang đăng xuất...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
// Clear Hive local data (cart, favorites, cached data)
|
||||
await HiveInitializer.logout();
|
||||
|
||||
// Call auth provider logout
|
||||
// This will:
|
||||
// - Clear FlutterSecureStorage session
|
||||
// - Clear FrappeAuthService session
|
||||
// - Get new public session for login/registration
|
||||
// - Update auth state to null (logged out)
|
||||
await ref.read(authProvider.notifier).logout();
|
||||
|
||||
// Close loading dialog
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
// Show success message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Đã đăng xuất thành công'),
|
||||
duration: Duration(seconds: 2),
|
||||
backgroundColor: AppColors.success,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Navigation to login screen is handled automatically by GoRouter redirect
|
||||
// when auth state becomes null
|
||||
} catch (e) {
|
||||
// Close loading dialog
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
// Show error message
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Lỗi đăng xuất: ${e.toString()}'),
|
||||
duration: const Duration(seconds: 3),
|
||||
backgroundColor: AppColors.danger,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user