Troca de desing

This commit is contained in:
Carlos Correia
2026-05-18 15:04:07 +01:00
parent 9b4c2f7e04
commit 9999011cfd
9 changed files with 3000 additions and 2138 deletions

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import '../Screens/home_screen.dart';
import '../theme/app_theme.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
@@ -9,364 +10,15 @@ class LoginScreen extends StatefulWidget {
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
bool isLoginSelected = true;
class _LoginScreenState extends State<LoginScreen>
with SingleTickerProviderStateMixin {
bool _isLogin = true;
bool _isLoading = false;
final TextEditingController _usernameController = TextEditingController();
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
bool _obscurePassword = true;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFFFE5CC), // Light orange background
appBar: AppBar(
backgroundColor: const Color(0xFF0066CC), // Blue app bar
elevation: 0,
toolbarHeight: 0, // Remove default app bar height
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 40),
// Logo
Image.asset(
'assets/logoDayMaker.png',
width: 220,
height: 220,
fit: BoxFit.contain,
),
const SizedBox(height: 24),
// App title and subtitle
const Text(
'DayMaker',
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: Color(0xFF0066CC),
),
),
const SizedBox(height: 8),
const Text(
'Organize sua rotina com inteligência',
style: TextStyle(fontSize: 16, color: Color(0xFF666666)),
textAlign: TextAlign.center,
),
const SizedBox(height: 40),
// Toggle buttons for Login/Create Account
Row(
children: [
Expanded(
child: GestureDetector(
onTap: () => setState(() => isLoginSelected = true),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: isLoginSelected
? const Color(0xFF0066CC)
: Colors.transparent,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20),
bottomLeft: Radius.circular(20),
),
border: Border.all(
color: const Color(0xFF0066CC),
width: 2,
),
),
child: Text(
'Entrar',
textAlign: TextAlign.center,
style: TextStyle(
color: isLoginSelected
? Colors.white
: const Color(0xFF0066CC),
fontWeight: FontWeight.w600,
fontSize: 16,
),
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () => setState(() => isLoginSelected = false),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: !isLoginSelected
? const Color(0xFF0066CC)
: Colors.transparent,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20),
bottomRight: Radius.circular(20),
),
border: Border.all(
color: const Color(0xFF0066CC),
width: 2,
),
),
child: Text(
'Criar Conta',
textAlign: TextAlign.center,
style: TextStyle(
color: !isLoginSelected
? Colors.white
: const Color(0xFF0066CC),
fontWeight: FontWeight.w600,
fontSize: 16,
),
),
),
),
),
],
),
const SizedBox(height: 32),
// Email field
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24),
border: Border.all(color: const Color(0xFFE0E0E0)),
),
child: TextField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.email, color: Color(0xFF666666)),
hintText: 'Digite seu email',
hintStyle: TextStyle(color: Color(0xFF999999)),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
),
),
),
const SizedBox(height: 16),
// Username field (only shown when Criar Conta is selected)
if (!isLoginSelected)
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24),
border: Border.all(color: const Color(0xFFE0E0E0)),
),
child: TextField(
controller: _usernameController,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.person, color: Color(0xFF666666)),
hintText: 'Digite seu nome',
hintStyle: TextStyle(color: Color(0xFF999999)),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
),
),
),
if (!isLoginSelected) const SizedBox(height: 16),
// Password field
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24),
border: Border.all(color: const Color(0xFFE0E0E0)),
),
child: TextField(
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.lock, color: Color(0xFF666666)),
hintText: 'Digite sua senha',
hintStyle: TextStyle(color: Color(0xFF999999)),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
),
),
),
const SizedBox(height: 32),
// Login/Create Account button
SizedBox(
width: double.infinity,
height: 56,
child: ElevatedButton(
onPressed: _isLoading
? null
: () async {
if (isLoginSelected) {
await _handleLogin();
} else {
await _handleSignUp();
}
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0066CC),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(42),
),
elevation: 0,
),
child: _isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white,
),
),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
isLoginSelected ? 'Entrar' : 'Criar Conta',
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
const SizedBox(width: 8),
const Icon(
Icons.arrow_forward,
color: Colors.white,
size: 20,
),
],
),
),
),
const Spacer(),
// Version text
const Text(
'Versão 1.0.0',
style: TextStyle(color: Color(0xFF666666), fontSize: 14),
),
const SizedBox(height: 16),
],
),
),
),
);
}
Future<void> _handleLogin() async {
final email = _emailController.text.trim();
final password = _passwordController.text.trim();
if (email.isEmpty || password.isEmpty) {
_showErrorSnackBar('Por favor, preencha todos os campos');
return;
}
setState(() => _isLoading = true);
try {
final response = await Supabase.instance.client.auth.signInWithPassword(
email: email,
password: password,
);
if (response.user != null) {
if (mounted) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => const HomeScreen()),
);
}
}
} on AuthException catch (e) {
_showErrorSnackBar('Erro de login: ${e.message}');
} catch (e) {
_showErrorSnackBar('Erro ao fazer login: $e');
} finally {
if (mounted) {
setState(() => _isLoading = false);
}
}
}
Future<void> _handleSignUp() async {
final email = _emailController.text.trim();
final username = _usernameController.text.trim();
final password = _passwordController.text.trim();
if (email.isEmpty || username.isEmpty || password.isEmpty) {
_showErrorSnackBar('Por favor, preencha todos os campos');
return;
}
setState(() => _isLoading = true);
try {
final response = await Supabase.instance.client.auth.signUp(
email: email,
password: password,
data: {'username': username},
);
if (response.user != null) {
// Save user data to users table
await Supabase.instance.client.from('users').insert({
'id': response.user!.id,
'nome': username,
'email': email,
});
_showSuccessSnackBar('Conta criada com sucesso!');
setState(() => isLoginSelected = true);
}
} on AuthException catch (e) {
_showErrorSnackBar('Erro ao criar conta: ${e.message}');
} catch (e) {
_showErrorSnackBar('Erro ao criar conta: $e');
} finally {
if (mounted) {
setState(() => _isLoading = false);
}
}
}
void _showErrorSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message), backgroundColor: Colors.red),
);
}
void _showSuccessSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message), backgroundColor: Colors.green),
);
}
final _usernameController = TextEditingController();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
@override
void dispose() {
@@ -375,4 +27,277 @@ class _LoginScreenState extends State<LoginScreen> {
_passwordController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.background,
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height -
MediaQuery.of(context).padding.top -
MediaQuery.of(context).padding.bottom,
),
child: IntrinsicHeight(
child: Column(
children: [
const SizedBox(height: 40),
_buildBrandHeader(),
const SizedBox(height: 32),
_buildModeToggle(),
const SizedBox(height: 28),
_buildForm(),
const SizedBox(height: 24),
_buildSubmitButton(),
const Spacer(),
Padding(
padding: const EdgeInsets.only(top: 24, bottom: 8),
child: Text(
'Versão 1.0.0',
style: AppText.caption,
),
),
],
),
),
),
),
),
);
}
Widget _buildBrandHeader() {
return Column(
children: [
Container(
width: 84,
height: 84,
decoration: BoxDecoration(
gradient: AppColors.brandGradient,
borderRadius: BorderRadius.circular(24),
boxShadow: AppShadows.brand,
),
child: const Icon(
Icons.auto_awesome_rounded,
color: Colors.white,
size: 42,
),
),
const SizedBox(height: 18),
const Text('DayMaker', style: AppText.h1),
const SizedBox(height: 6),
Text(
'Organize a sua rotina com inteligência',
style: AppText.bodySecondary,
textAlign: TextAlign.center,
),
],
);
}
Widget _buildModeToggle() {
return Container(
decoration: BoxDecoration(
color: AppColors.surfaceAlt,
borderRadius: BorderRadius.circular(AppRadius.pill),
),
padding: const EdgeInsets.all(4),
child: Row(
children: [
_toggleButton('Entrar', _isLogin, () {
setState(() => _isLogin = true);
}),
_toggleButton('Criar Conta', !_isLogin, () {
setState(() => _isLogin = false);
}),
],
),
);
}
Widget _toggleButton(String label, bool selected, VoidCallback onTap) {
return Expanded(
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
decoration: BoxDecoration(
color: selected ? AppColors.surface : Colors.transparent,
borderRadius: BorderRadius.circular(AppRadius.pill),
boxShadow: selected ? AppShadows.soft : null,
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(AppRadius.pill),
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Center(
child: Text(
label,
style: TextStyle(
fontWeight: FontWeight.w600,
color: selected
? AppColors.primary
: AppColors.textSecondary,
),
),
),
),
),
),
),
);
}
Widget _buildForm() {
return Column(
children: [
_inputField(
controller: _emailController,
icon: Icons.email_outlined,
hint: 'Insira o seu email',
keyboard: TextInputType.emailAddress,
),
AnimatedSize(
duration: const Duration(milliseconds: 250),
curve: Curves.easeOut,
child: !_isLogin
? Padding(
padding: const EdgeInsets.only(top: 12),
child: _inputField(
controller: _usernameController,
icon: Icons.person_outline,
hint: 'Insira o seu nome',
),
)
: const SizedBox.shrink(),
),
const SizedBox(height: 12),
_inputField(
controller: _passwordController,
icon: Icons.lock_outline_rounded,
hint: 'Insira a sua palavra-passe',
obscure: _obscurePassword,
trailing: IconButton(
onPressed: () =>
setState(() => _obscurePassword = !_obscurePassword),
icon: Icon(
_obscurePassword
? Icons.visibility_off_outlined
: Icons.visibility_outlined,
color: AppColors.textSecondary,
),
),
),
],
);
}
Widget _inputField({
required TextEditingController controller,
required IconData icon,
required String hint,
TextInputType? keyboard,
bool obscure = false,
Widget? trailing,
}) {
return Container(
decoration: AppDecorations.outlined(),
child: TextField(
controller: controller,
keyboardType: keyboard,
obscureText: obscure,
style: AppText.body,
decoration: InputDecoration(
prefixIcon: Icon(icon, color: AppColors.textSecondary),
suffixIcon: trailing,
hintText: hint,
hintStyle: TextStyle(color: AppColors.textTertiary),
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 16,
),
),
),
);
}
Widget _buildSubmitButton() {
return AppButton(
label: _isLogin ? 'Entrar' : 'Criar Conta',
icon: Icons.arrow_forward_rounded,
loading: _isLoading,
onPressed: () => _isLogin ? _handleLogin() : _handleSignUp(),
);
}
Future<void> _handleLogin() async {
final email = _emailController.text.trim();
final password = _passwordController.text.trim();
if (email.isEmpty || password.isEmpty) {
AppSnack.error(context, 'Por favor, preencha todos os campos');
return;
}
setState(() => _isLoading = true);
try {
final response =
await Supabase.instance.client.auth.signInWithPassword(
email: email,
password: password,
);
if (response.user != null && mounted) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => const HomeScreen()),
);
}
} on AuthException catch (e) {
if (mounted) AppSnack.error(context, 'Erro de login: ${e.message}');
} catch (e) {
if (mounted) AppSnack.error(context, 'Erro: $e');
} finally {
if (mounted) setState(() => _isLoading = false);
}
}
Future<void> _handleSignUp() async {
final email = _emailController.text.trim();
final username = _usernameController.text.trim();
final password = _passwordController.text.trim();
if (email.isEmpty || username.isEmpty || password.isEmpty) {
AppSnack.error(context, 'Por favor, preencha todos os campos');
return;
}
setState(() => _isLoading = true);
try {
final response = await Supabase.instance.client.auth.signUp(
email: email,
password: password,
data: {'username': username},
);
if (response.user != null) {
await Supabase.instance.client.from('users').insert({
'id': response.user!.id,
'nome': username,
'email': email,
});
if (mounted) {
AppSnack.success(context, 'Conta criada com sucesso!');
setState(() => _isLogin = true);
}
}
} on AuthException catch (e) {
if (mounted) {
AppSnack.error(context, 'Erro ao criar conta: ${e.message}');
}
} catch (e) {
if (mounted) AppSnack.error(context, 'Erro: $e');
} finally {
if (mounted) setState(() => _isLoading = false);
}
}
}