296 lines
12 KiB
Dart
296 lines
12 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../services/odoo_service.dart';
|
|
import '../services/notification_service.dart';
|
|
import '../theme/app_theme.dart';
|
|
import 'login_screen.dart';
|
|
|
|
class SettingsScreen extends StatefulWidget {
|
|
const SettingsScreen({super.key});
|
|
|
|
@override
|
|
State<SettingsScreen> createState() => _SettingsScreenState();
|
|
}
|
|
|
|
class _SettingsScreenState extends State<SettingsScreen> {
|
|
final _phraseController = TextEditingController();
|
|
final _passwordController = TextEditingController();
|
|
bool _isLoading = false;
|
|
|
|
void _showDeleteConfirmationDialog() {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (context) {
|
|
return StatefulBuilder(
|
|
builder: (context, setDialogState) {
|
|
return AlertDialog(
|
|
title: const Text(
|
|
'Delete Account Permanently',
|
|
style: TextStyle(
|
|
color: Colors.red,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
content: SizedBox(
|
|
width: double.maxFinite,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const Text(
|
|
'WARNING: This is a permanent action. All your loyalty points, card tier history, and reward history will be deleted and cannot be recovered.',
|
|
style: TextStyle(
|
|
color: AppTheme.onSurface,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'To confirm, please type "DELETE MY ACCOUNT" in the field below:',
|
|
style: TextStyle(
|
|
color: AppTheme.onSurfaceVariant,
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
TextField(
|
|
controller: _phraseController,
|
|
decoration: const InputDecoration(
|
|
hintText: 'DELETE MY ACCOUNT',
|
|
),
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'Enter your current password:',
|
|
style: TextStyle(
|
|
color: AppTheme.onSurfaceVariant,
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
TextField(
|
|
controller: _passwordController,
|
|
obscureText: true,
|
|
decoration: const InputDecoration(
|
|
hintText: 'Password',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
_phraseController.clear();
|
|
_passwordController.clear();
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: const Text(
|
|
'Cancel',
|
|
style: TextStyle(
|
|
color: AppTheme.onSurface,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: _isLoading
|
|
? null
|
|
: () async {
|
|
final phrase = _phraseController.text.trim();
|
|
final password = _passwordController.text;
|
|
|
|
if (phrase != 'DELETE MY ACCOUNT') {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Verification phrase is incorrect.')),
|
|
);
|
|
return;
|
|
}
|
|
if (password.isEmpty) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Please enter your password.')),
|
|
);
|
|
return;
|
|
}
|
|
|
|
setDialogState(() => _isLoading = true);
|
|
|
|
try {
|
|
final service = OdooService();
|
|
final response = await service.deleteAccount(password);
|
|
|
|
if (response != null && response['status'] == 'success') {
|
|
// Success! Clear local cache and redirect
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.remove('odoo_session');
|
|
|
|
if (context.mounted) {
|
|
Navigator.of(context).pop(); // Close dialog
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(response['message'] ?? 'Account deleted successfully.')),
|
|
);
|
|
Navigator.of(context).pushAndRemoveUntil(
|
|
MaterialPageRoute(builder: (_) => const LoginScreen()),
|
|
(route) => false,
|
|
);
|
|
}
|
|
} else {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(response?['message'] ?? 'Deletion failed.')),
|
|
);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Error: $e')),
|
|
);
|
|
}
|
|
} finally {
|
|
setDialogState(() => _isLoading = false);
|
|
}
|
|
},
|
|
child: _isLoading
|
|
? const SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.red),
|
|
)
|
|
: const Text(
|
|
'Delete My Account',
|
|
style: TextStyle(
|
|
color: Colors.red,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _logout() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.remove('odoo_session');
|
|
await prefs.remove('last_seen_notification_id');
|
|
await prefs.remove('last_device_notified_id');
|
|
await prefs.remove('read_notification_ids');
|
|
await NotificationService().clearBadge();
|
|
if (mounted) {
|
|
Navigator.of(context).pushAndRemoveUntil(
|
|
MaterialPageRoute(builder: (_) => const LoginScreen()),
|
|
(route) => false,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_phraseController.dispose();
|
|
_passwordController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Account Settings'),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(
|
|
'Privacy & Security',
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
color: AppTheme.onSurface,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Card(
|
|
color: AppTheme.surfaceContainerLow,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(20.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Text(
|
|
'How Account Deletion Works',
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
color: AppTheme.onSurface,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
const Text(
|
|
'If you decide to delete your Mie Mapan loyalty account, please be aware that:\n\n'
|
|
'• All your loyalty cards and membership tiers will be permanently deactivated.\n'
|
|
'• All accumulated points balance will be reset to zero immediately.\n'
|
|
'• Your historical reward transactions and POS order line associations will be archived.\n'
|
|
'• Your personal profile information (Name, Phone, Birth Date, Gender, Email) will be anonymized in compliance with GDPR guidelines.\n\n'
|
|
'This process cannot be undone. Once deleted, you will have to register as a new member with zero points.',
|
|
style: TextStyle(
|
|
color: AppTheme.onSurfaceVariant,
|
|
fontSize: 14,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 40),
|
|
ElevatedButton(
|
|
onPressed: _logout,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.white,
|
|
foregroundColor: AppTheme.onSurface,
|
|
side: const BorderSide(color: AppTheme.surfaceContainer, width: 2),
|
|
),
|
|
child: const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Text(
|
|
'Log Out',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
ElevatedButton(
|
|
onPressed: _showDeleteConfirmationDialog,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFFFFDAD4),
|
|
foregroundColor: const Color(0xFF410002),
|
|
side: const BorderSide(color: Color(0xFFBA1A1A), width: 1.5),
|
|
),
|
|
child: const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Text(
|
|
'Delete Account',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|