Settings finalizadas

This commit is contained in:
2026-03-18 20:03:32 +00:00
parent 6322e8d798
commit 1794208143
7 changed files with 399 additions and 401 deletions

View File

@@ -11,9 +11,13 @@ class SettingsScreen extends StatefulWidget {
}
class _SettingsScreenState extends State<SettingsScreen> {
bool _isNightMode = true;
bool _notificationsEnabled = true;
String _selectedLanguage = 'Português';
late String _selectedLanguage;
@override
void initState() {
super.initState();
_selectedLanguage = AppStrings.currentLanguageName;
}
@override
Widget build(BuildContext context) {
@@ -93,12 +97,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
IconButton(
icon: const Icon(Icons.edit, color: AppColors.buttonColor),
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppStrings.editProfile),
backgroundColor: AppColors.buttonColor,
),
);
_showEditProfileDialog(context, userName, userEmail);
},
),
],
@@ -115,28 +114,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
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,
@@ -152,59 +129,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
},
),
_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,
@@ -278,39 +202,42 @@ class _SettingsScreenState extends State<SettingsScreen> {
);
}
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 _showEditProfileDialog(BuildContext context, String currentName, String currentEmail) {
final nameController = TextEditingController(text: currentName);
final emailController = TextEditingController(text: currentEmail);
void _showLanguageSelector(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: AppColors.backgroundGrey,
title: Text(
AppStrings.selectLanguage,
AppStrings.editProfile,
style: const TextStyle(color: Colors.white),
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildLanguageOption('Português'),
_buildLanguageOption('English'),
_buildLanguageOption('Español'),
TextField(
controller: nameController,
style: const TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: AppStrings.labelName,
labelStyle: const TextStyle(color: Colors.white70),
enabledBorder: const UnderlineInputBorder(borderSide: BorderSide(color: Colors.white24)),
focusedBorder: const UnderlineInputBorder(borderSide: BorderSide(color: AppColors.buttonColor)),
),
),
const SizedBox(height: 16),
TextField(
controller: emailController,
style: const TextStyle(color: Colors.white),
decoration: InputDecoration(
labelText: AppStrings.labelEmail,
labelStyle: const TextStyle(color: Colors.white70),
enabledBorder: const UnderlineInputBorder(borderSide: BorderSide(color: Colors.white24)),
focusedBorder: const UnderlineInputBorder(borderSide: BorderSide(color: AppColors.buttonColor)),
),
),
],
),
actions: [
@@ -318,15 +245,74 @@ class _SettingsScreenState extends State<SettingsScreen> {
onPressed: () => Navigator.pop(context),
child: Text(
AppStrings.btnCancel,
style: const TextStyle(color: AppColors.buttonColor),
style: const TextStyle(color: Colors.white54),
),
),
ElevatedButton(
onPressed: () async {
try {
await SupabaseService.updateProfile(
name: nameController.text.trim(),
email: emailController.text.trim(),
);
if (context.mounted) {
Navigator.pop(context);
setState(() {});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Perfil atualizado!'), backgroundColor: Colors.green),
);
}
} catch (e) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString()), backgroundColor: Colors.red),
);
}
}
},
style: ElevatedButton.styleFrom(backgroundColor: AppColors.buttonColor),
child: Text(AppStrings.btnDefine),
),
],
),
);
}
Widget _buildLanguageOption(String language) {
void _showLanguageSelector(BuildContext context) {
showDialog(
context: context,
builder: (context) => StatefulBuilder(
builder: (context, setDialogState) {
return AlertDialog(
backgroundColor: AppColors.backgroundGrey,
title: Text(
AppStrings.selectLanguage,
style: const TextStyle(color: Colors.white),
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildLanguageOption(context, setDialogState, 'Português'),
_buildLanguageOption(context, setDialogState, 'English'),
_buildLanguageOption(context, setDialogState, 'Español'),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
AppStrings.btnCancel,
style: const TextStyle(color: AppColors.buttonColor),
),
),
],
);
}
),
);
}
Widget _buildLanguageOption(BuildContext context, StateSetter setDialogState, String language) {
return ListTile(
title: Text(language, style: const TextStyle(color: Colors.white)),
trailing: Radio<String>(
@@ -334,28 +320,26 @@ class _SettingsScreenState extends State<SettingsScreen> {
groupValue: _selectedLanguage,
onChanged: (value) {
if (value != null) {
setState(() {
_selectedLanguage = value;
AppStrings.setLanguage(value);
});
_updateLanguage(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);
});
_updateLanguage(language);
Navigator.pop(context);
setState(() {});
},
);
}
void _updateLanguage(String language) {
setState(() {
_selectedLanguage = language;
AppStrings.setLanguage(language);
});
}
void _showAboutDialog(BuildContext context) {
showDialog(
context: context,