98 lines
4.2 KiB
Dart
98 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../utils/constants.dart';
|
|
import '../services/auth_service.dart';
|
|
import 'login_screen.dart';
|
|
|
|
class ProfileScreen extends StatelessWidget {
|
|
const ProfileScreen({super.key});
|
|
|
|
Future<void> _handleLogout(BuildContext context) async {
|
|
final confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Conferma Logout'),
|
|
content: const Text('Sei sicuro di voler uscire?'),
|
|
actions: [
|
|
TextButton(onPressed: () => Navigator.pop(context, false), child: const Text('Annulla')),
|
|
ElevatedButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
style: ElevatedButton.styleFrom(backgroundColor: AppColors.critical),
|
|
child: const Text('Esci'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (confirmed == true && context.mounted) {
|
|
await AuthService().logout();
|
|
if (context.mounted) {
|
|
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (_) => const LoginScreen()), (_) => false);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final user = AuthService().currentUser;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Profilo')),
|
|
body: user == null
|
|
? const Center(child: CircularProgressIndicator())
|
|
: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(AppSizes.paddingM),
|
|
child: Column(
|
|
children: [
|
|
Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(AppSizes.paddingL),
|
|
child: Column(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 50,
|
|
backgroundColor: AppColors.primary,
|
|
child: Text('${user.nome[0]}${user.cognome[0]}'.toUpperCase(), style: const TextStyle(fontSize: 32, fontWeight: FontWeight.bold, color: Colors.white)),
|
|
),
|
|
const SizedBox(height: AppSizes.paddingM),
|
|
Text(user.nomeCompleto, style: AppTextStyles.h2, textAlign: TextAlign.center),
|
|
Text(user.email, style: AppTextStyles.bodyMedium.copyWith(color: AppColors.textSecondary)),
|
|
const SizedBox(height: AppSizes.paddingM),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: AppSizes.paddingM, vertical: AppSizes.paddingS),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.primary.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(AppSizes.radiusL),
|
|
),
|
|
child: Text(user.ruolo.toUpperCase(), style: const TextStyle(color: AppColors.primary, fontWeight: FontWeight.w600)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: AppSizes.paddingM),
|
|
Card(
|
|
child: Column(
|
|
children: [
|
|
ListTile(leading: const Icon(Icons.business_outlined), title: const Text('ID Cliente'), trailing: Text(user.clienteId.toString())),
|
|
ListTile(leading: const Icon(Icons.verified_outlined), title: const Text('Versione'), trailing: Text(AppConstants.appVersion)),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: AppSizes.paddingM),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: AppSizes.buttonHeight,
|
|
child: ElevatedButton.icon(
|
|
onPressed: () => _handleLogout(context),
|
|
icon: const Icon(Icons.logout),
|
|
label: const Text('Esci'),
|
|
style: ElevatedButton.styleFrom(backgroundColor: AppColors.critical),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|