431 lines
14 KiB
Dart
431 lines
14 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../constants/app_colors.dart';
|
|
import '../constants/app_strings.dart';
|
|
import '../services/supabase_service.dart';
|
|
|
|
class SettingsScreen extends StatefulWidget {
|
|
const SettingsScreen({super.key});
|
|
|
|
@override
|
|
State<SettingsScreen> createState() => _SettingsScreenState();
|
|
}
|
|
|
|
class _SettingsScreenState extends State<SettingsScreen> {
|
|
bool _isNightMode = true;
|
|
bool _notificationsEnabled = true;
|
|
String _selectedLanguage = 'Português';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final user = SupabaseService.currentUser;
|
|
final userName =
|
|
user?.userMetadata?['name'] ?? user?.email?.split('@')[0] ?? AppStrings.userPlaceholder;
|
|
final userEmail = user?.email ?? 'usuario@exemplo.com';
|
|
|
|
return Scaffold(
|
|
backgroundColor: AppColors.background,
|
|
appBar: AppBar(
|
|
title: Text(
|
|
AppStrings.settingsTitle,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
backgroundColor: AppColors.background,
|
|
elevation: 0,
|
|
iconTheme: const IconThemeData(color: Colors.white),
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
children: [
|
|
// User Profile Section
|
|
Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.backgroundGrey,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 60,
|
|
height: 60,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.buttonColor,
|
|
borderRadius: BorderRadius.circular(30),
|
|
),
|
|
child: const Icon(
|
|
Icons.person,
|
|
color: Colors.white,
|
|
size: 30,
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
userName,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
userEmail,
|
|
style: TextStyle(
|
|
color: Colors.white.withValues(alpha: 0.7),
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.edit, color: AppColors.buttonColor),
|
|
onPressed: () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(AppStrings.editProfile),
|
|
backgroundColor: AppColors.buttonColor,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// Settings Items
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: AppColors.backgroundGrey,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildSettingsItem(
|
|
icon: Icons.schedule,
|
|
title: AppStrings.adjustDateTime,
|
|
onTap: () {
|
|
_showDatePicker(context);
|
|
},
|
|
),
|
|
_buildDivider(),
|
|
_buildSettingsItem(
|
|
icon: Icons.dark_mode,
|
|
title: AppStrings.nightMode,
|
|
trailing: Switch(
|
|
value: _isNightMode,
|
|
activeThumbColor: AppColors.buttonColor,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_isNightMode = value;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
_buildDivider(),
|
|
_buildSettingsItem(
|
|
icon: Icons.language,
|
|
title: AppStrings.language,
|
|
trailing: Text(
|
|
_selectedLanguage,
|
|
style: TextStyle(
|
|
color: Colors.white.withValues(alpha: 0.7),
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
onTap: () {
|
|
_showLanguageSelector(context);
|
|
},
|
|
),
|
|
_buildDivider(),
|
|
_buildSettingsItem(
|
|
icon: Icons.accessibility,
|
|
title: AppStrings.accessibility,
|
|
onTap: () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(AppStrings.accessibility),
|
|
backgroundColor: AppColors.buttonColor,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
_buildDivider(),
|
|
_buildSettingsItem(
|
|
icon: Icons.notifications,
|
|
title: AppStrings.notifications,
|
|
trailing: Switch(
|
|
value: _notificationsEnabled,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_notificationsEnabled = value;
|
|
});
|
|
},
|
|
activeThumbColor: AppColors.buttonColor,
|
|
),
|
|
),
|
|
_buildDivider(),
|
|
_buildSettingsItem(
|
|
icon: Icons.privacy_tip,
|
|
title: AppStrings.privacySecurity,
|
|
onTap: () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(AppStrings.privacySecurity),
|
|
backgroundColor: AppColors.buttonColor,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
_buildDivider(),
|
|
_buildSettingsItem(
|
|
icon: Icons.description,
|
|
title: AppStrings.termsOfUse,
|
|
onTap: () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(AppStrings.termsOfUse),
|
|
backgroundColor: AppColors.buttonColor,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
_buildDivider(),
|
|
_buildSettingsItem(
|
|
icon: Icons.info,
|
|
title: AppStrings.about,
|
|
onTap: () {
|
|
_showAboutDialog(context);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// Logout Button
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton(
|
|
onPressed: () {
|
|
_showLogoutDialog(context);
|
|
},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.red,
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
child: Text(
|
|
AppStrings.logout,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSettingsItem({
|
|
required IconData icon,
|
|
required String title,
|
|
Widget? trailing,
|
|
VoidCallback? onTap,
|
|
}) {
|
|
return ListTile(
|
|
leading: Icon(icon, color: AppColors.buttonColor, size: 24),
|
|
title: Text(
|
|
title,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
trailing: trailing,
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
|
|
Widget _buildDivider() {
|
|
return Divider(
|
|
color: AppColors.buttonColor.withValues(alpha: 0.2),
|
|
height: 1,
|
|
indent: 16,
|
|
endIndent: 16,
|
|
);
|
|
}
|
|
|
|
void _showDatePicker(BuildContext context) {
|
|
showDatePicker(
|
|
context: context,
|
|
initialDate: DateTime.now(),
|
|
firstDate: DateTime(2020),
|
|
lastDate: DateTime(2025),
|
|
).then((date) {
|
|
if (date != null && mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('${AppStrings.dateSelected}: ${date.toString().split(' ')[0]}'),
|
|
backgroundColor: AppColors.buttonColor,
|
|
),
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
void _showLanguageSelector(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppColors.backgroundGrey,
|
|
title: Text(
|
|
AppStrings.selectLanguage,
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
_buildLanguageOption('Português'),
|
|
_buildLanguageOption('English'),
|
|
_buildLanguageOption('Español'),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text(
|
|
AppStrings.btnCancel,
|
|
style: const TextStyle(color: AppColors.buttonColor),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildLanguageOption(String language) {
|
|
return ListTile(
|
|
title: Text(language, style: const TextStyle(color: Colors.white)),
|
|
trailing: Radio<String>(
|
|
value: language,
|
|
groupValue: _selectedLanguage,
|
|
onChanged: (value) {
|
|
if (value != null) {
|
|
setState(() {
|
|
_selectedLanguage = value;
|
|
AppStrings.setLanguage(value);
|
|
});
|
|
Navigator.pop(context);
|
|
// Force rebuild of current screen to apply changes
|
|
setState(() {});
|
|
}
|
|
},
|
|
fillColor: WidgetStateProperty.all(AppColors.buttonColor),
|
|
),
|
|
onTap: () {
|
|
setState(() {
|
|
_selectedLanguage = language;
|
|
AppStrings.setLanguage(language);
|
|
});
|
|
Navigator.pop(context);
|
|
setState(() {});
|
|
},
|
|
);
|
|
}
|
|
|
|
void _showAboutDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppColors.backgroundGrey,
|
|
title: Text(AppStrings.about, style: const TextStyle(color: Colors.white)),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
AppStrings.appTitle,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text('${AppStrings.version}: 1.0.0', style: const TextStyle(color: Colors.white70)),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
AppStrings.appDescription,
|
|
style: const TextStyle(color: Colors.white70),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text(
|
|
AppStrings.btnOk,
|
|
style: const TextStyle(color: AppColors.buttonColor),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showLogoutDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppColors.backgroundGrey,
|
|
title: Text(
|
|
AppStrings.confirmLogout,
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
content: Text(
|
|
AppStrings.confirmLogoutMessage,
|
|
style: const TextStyle(color: Colors.white70),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text(
|
|
AppStrings.btnCancel,
|
|
style: const TextStyle(color: AppColors.buttonColor),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
Navigator.pushReplacementNamed(context, '/');
|
|
},
|
|
child: Text(AppStrings.logout, style: const TextStyle(color: Colors.red)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|