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

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../constants/app_colors.dart';
import '../constants/app_strings.dart';
import '../services/supabase_service.dart';
@@ -16,10 +17,10 @@ class LogadoScreen extends StatefulWidget {
class _LogadoScreenState extends State<LogadoScreen> {
// Estado dinâmico do utilizador
double _dailyGoal = 0.0; // 0.0 significa que ainda não foi definida
double _dailyGoal = 0.0;
double _currentDistance = 0.0;
double _bestDistance = 12.4; // Exemplo de recorde
double _bestSpeed = 16.8; // Exemplo de recorde
double _bestDistance = 12.4;
double _bestSpeed = 16.8;
int _steps = 0;
int _totalTimeMinutes = 0;
@@ -32,15 +33,38 @@ class _LogadoScreenState extends State<LogadoScreen> {
}
Future<void> _loadUserData() async {
// No futuro, aqui buscaríamos os dados reais do Supabase ou Local Storage
final prefs = await SharedPreferences.getInstance();
final lastGoalDate = prefs.getString('last_goal_date');
final today = DateTime.now().toIso8601String().split('T')[0];
setState(() {
// Simulação de dados carregados
_currentDistance = 0.0; // Começa o dia a zero
// Reset meta se o dia mudou
if (lastGoalDate != today) {
_dailyGoal = 0.0;
prefs.remove('daily_goal');
} else {
_dailyGoal = prefs.getDouble('daily_goal') ?? 0.0;
}
// No futuro, estes viriam do Supabase ou histórico local
_currentDistance = 0.0;
_steps = 0;
_totalTimeMinutes = 0;
});
}
Future<void> _saveGoal(double goal) async {
final prefs = await SharedPreferences.getInstance();
final today = DateTime.now().toIso8601String().split('T')[0];
await prefs.setDouble('daily_goal', goal);
await prefs.setString('last_goal_date', today);
setState(() {
_dailyGoal = goal;
});
}
void _showGoalDialog() {
showDialog(
context: context,
@@ -54,9 +78,7 @@ class _LogadoScreenState extends State<LogadoScreen> {
...[5, 10, 15, 20].map((km) => ListTile(
title: Text("$km ${AppStrings.kmUnit}", style: const TextStyle(color: Colors.white)),
onTap: () {
setState(() {
_dailyGoal = km.toDouble();
});
_saveGoal(km.toDouble());
Navigator.pop(context);
},
)),
@@ -107,9 +129,7 @@ class _LogadoScreenState extends State<LogadoScreen> {
onPressed: () {
final value = double.tryParse(controller.text);
if (value != null && value > 0) {
setState(() {
_dailyGoal = value;
});
_saveGoal(value);
Navigator.pop(context);
}
},
@@ -126,194 +146,187 @@ class _LogadoScreenState extends State<LogadoScreen> {
@override
Widget build(BuildContext context) {
final user = SupabaseService.currentUser;
final userName = user?.userMetadata?['name'] ?? user?.email?.split('@')[0] ?? AppStrings.userPlaceholder;
return ValueListenableBuilder<AppLanguage>(
valueListenable: AppStrings.languageNotifier,
builder: (context, language, child) {
final user = SupabaseService.currentUser;
final userName = user?.userMetadata?['name'] ?? user?.email?.split('@')[0] ?? AppStrings.userPlaceholder;
return Scaffold(
backgroundColor: AppColors.background,
body: Stack(
children: [
// Background Gradient
Positioned.fill(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFF2D2D31), AppColors.background],
),
),
),
),
SafeArea(
child: Column(
children: [
// Header Bar
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppStrings.welcome.toUpperCase(),
style: const TextStyle(
color: Colors.white38,
fontSize: 10,
fontWeight: FontWeight.w900,
letterSpacing: 2,
),
),
Text(
userName,
style: const TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.w900,
letterSpacing: -0.5,
),
),
],
),
Row(
children: [
_buildIconButton(
Icons.bluetooth_audio_rounded,
() => Navigator.push(context, MaterialPageRoute(builder: (context) => const BluetoothConnectionScreen())),
),
const SizedBox(width: 12),
_buildIconButton(
Icons.settings_rounded,
() => Navigator.push(context, MaterialPageRoute(builder: (context) => const SettingsScreen())),
),
],
),
],
),
),
Expanded(
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 20),
// Main Tracking Card (Meta Diária)
_buildMainTrackingCard(),
const SizedBox(height: 30),
// Personal Bests Section
Text(
AppStrings.personalRecords,
style: const TextStyle(
color: Colors.white38,
fontSize: 11,
fontWeight: FontWeight.w900,
letterSpacing: 1.5,
),
),
const SizedBox(height: 15),
Row(
children: [
Expanded(
child: _buildRecordCard(
AppStrings.bestDistance,
_bestDistance.toStringAsFixed(1),
AppStrings.kmUnit,
Icons.auto_graph_rounded,
AppColors.coral,
),
),
const SizedBox(width: 15),
Expanded(
child: _buildRecordCard(
AppStrings.bestSpeed,
_bestSpeed.toStringAsFixed(1),
AppStrings.kmhUnit,
Icons.speed_rounded,
Colors.cyanAccent,
),
),
],
),
const SizedBox(height: 25),
// Steps Section (Atividade Geral)
Text(
AppStrings.generalActivity,
style: const TextStyle(
color: Colors.white38,
fontSize: 11,
fontWeight: FontWeight.w900,
letterSpacing: 1.5,
),
),
const SizedBox(height: 15),
_buildWideRecordCard(
AppStrings.steps,
_steps.toString(),
AppStrings.stepsToday,
Icons.directions_walk_rounded,
AppColors.success,
),
const SizedBox(height: 120), // Espaço para o botão inferior
],
return Scaffold(
backgroundColor: AppColors.background,
body: Stack(
children: [
Positioned.fill(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFF2D2D31), AppColors.background],
),
),
),
],
),
),
// Bottom Action Button
Positioned(
bottom: 30,
left: 50,
right: 50,
child: Container(
height: 70,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: AppColors.coral.withValues(alpha: 0.3),
blurRadius: 25,
spreadRadius: -5,
)
],
),
child: ElevatedButton(
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (context) => const GoogleMapScreen())),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.coral,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
elevation: 0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
SafeArea(
child: Column(
children: [
const Icon(Icons.play_arrow_rounded, size: 30),
const SizedBox(width: 10),
Text(
AppStrings.startTraining,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w900, letterSpacing: 1.5),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppStrings.welcome.toUpperCase(),
style: const TextStyle(
color: Colors.white38,
fontSize: 10,
fontWeight: FontWeight.w900,
letterSpacing: 2,
),
),
Text(
userName,
style: const TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.w900,
letterSpacing: -0.5,
),
),
],
),
Row(
children: [
_buildIconButton(
Icons.bluetooth_audio_rounded,
() => Navigator.push(context, MaterialPageRoute(builder: (context) => const BluetoothConnectionScreen())),
),
const SizedBox(width: 12),
_buildIconButton(
Icons.settings_rounded,
() => Navigator.push(context, MaterialPageRoute(builder: (context) => const SettingsScreen())),
),
],
),
],
),
),
Expanded(
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 20),
_buildMainTrackingCard(),
const SizedBox(height: 30),
Text(
AppStrings.personalRecords,
style: const TextStyle(
color: Colors.white38,
fontSize: 11,
fontWeight: FontWeight.w900,
letterSpacing: 1.5,
),
),
const SizedBox(height: 15),
Row(
children: [
Expanded(
child: _buildRecordCard(
AppStrings.bestDistance,
_bestDistance.toStringAsFixed(1),
AppStrings.kmUnit,
Icons.auto_graph_rounded,
AppColors.coral,
),
),
const SizedBox(width: 15),
Expanded(
child: _buildRecordCard(
AppStrings.bestSpeed,
_bestSpeed.toStringAsFixed(1),
AppStrings.kmhUnit,
Icons.speed_rounded,
Colors.cyanAccent,
),
),
],
),
const SizedBox(height: 25),
Text(
AppStrings.generalActivity,
style: const TextStyle(
color: Colors.white38,
fontSize: 11,
fontWeight: FontWeight.w900,
letterSpacing: 1.5,
),
),
const SizedBox(height: 15),
_buildWideRecordCard(
AppStrings.steps,
_steps.toString(),
AppStrings.stepsToday,
Icons.directions_walk_rounded,
AppColors.success,
),
const SizedBox(height: 120),
],
),
),
),
],
),
),
),
Positioned(
bottom: 30,
left: 50,
right: 50,
child: Container(
height: 70,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: AppColors.coral.withValues(alpha: 0.3),
blurRadius: 25,
spreadRadius: -5,
)
],
),
child: ElevatedButton(
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (context) => const GoogleMapScreen())),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.coral,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
elevation: 0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.play_arrow_rounded, size: 30),
const SizedBox(width: 10),
Text(
AppStrings.startTraining,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w900, letterSpacing: 1.5),
),
],
),
),
),
),
],
),
],
),
);
},
);
}
@@ -352,9 +365,25 @@ class _LogadoScreenState extends State<LogadoScreen> {
style: const TextStyle(color: Colors.white54, fontWeight: FontWeight.bold, letterSpacing: 1),
),
if (_dailyGoal > 0)
Text(
"${(_progress * 100).toInt()}%",
style: const TextStyle(color: AppColors.coral, fontWeight: FontWeight.w900),
GestureDetector(
onTap: _showGoalDialog,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: AppColors.coral.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
Text(
"${(_progress * 100).toInt()}%",
style: const TextStyle(color: AppColors.coral, fontWeight: FontWeight.w900),
),
const SizedBox(width: 5),
const Icon(Icons.edit_rounded, color: AppColors.coral, size: 14),
],
),
),
),
],
),

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,