Files
PlayMaker/lib/widgets/register_widgets.dart
2026-01-07 10:40:48 +00:00

172 lines
5.4 KiB
Dart

import 'package:flutter/material.dart';
import '../Controllers/register_controller.dart';
class RegisterHeader extends StatelessWidget {
const RegisterHeader({super.key});
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
// Mesma lógica de tamanhos do Login
final logoSize = screenWidth > 600 ? 150.0 : 100.0;
final titleFontSize = screenWidth > 600 ? 48.0 : 36.0;
final subtitleFontSize = screenWidth > 600 ? 22.0 : 18.0;
return Column(
children: [
Icon(
Icons.person_add_outlined,
size: logoSize,
color: const Color(0xFFE74C3C)
),
const SizedBox(height: 10),
Text(
'Nova Conta',
style: TextStyle(
fontSize: titleFontSize,
fontWeight: FontWeight.bold,
color: Colors.grey[900],
),
),
const SizedBox(height: 5),
Text(
'Cria o teu perfil no BasketTrack',
style: TextStyle(
fontSize: subtitleFontSize,
color: Colors.grey[600],
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
),
],
);
}
}
class RegisterFormFields extends StatefulWidget {
final RegisterController controller;
const RegisterFormFields({super.key, required this.controller});
@override
State<RegisterFormFields> createState() => _RegisterFormFieldsState();
}
class _RegisterFormFieldsState extends State<RegisterFormFields> {
bool _obscurePassword = true;
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
// Padding vertical idêntico ao login
final verticalPadding = screenWidth > 600 ? 22.0 : 16.0;
return Column(
children: [
TextField(
controller: widget.controller.emailController,
decoration: InputDecoration(
labelText: 'E-mail',
prefixIcon: const Icon(Icons.email_outlined),
// O erro agora vem diretamente do controller
errorText: widget.controller.emailError,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
contentPadding: EdgeInsets.symmetric(vertical: verticalPadding, horizontal: 16),
),
keyboardType: TextInputType.emailAddress,
),
const SizedBox(height: 20),
// Campo Password
TextField(
controller: widget.controller.passwordController,
obscureText: _obscurePassword,
decoration: InputDecoration(
labelText: 'Palavra-passe',
prefixIcon: const Icon(Icons.lock_outlined),
errorText: widget.controller.passwordError,
suffixIcon: IconButton(
icon: Icon(_obscurePassword ? Icons.visibility_outlined : Icons.visibility_off_outlined),
onPressed: () => setState(() => _obscurePassword = !_obscurePassword),
),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
contentPadding: EdgeInsets.symmetric(vertical: verticalPadding, horizontal: 16),
),
),
const SizedBox(height: 20),
// Campo Confirmar Password
TextField(
controller: widget.controller.confirmPasswordController,
obscureText: _obscurePassword,
decoration: InputDecoration(
labelText: 'Confirmar Palavra-passe',
prefixIcon: const Icon(Icons.lock_clock_outlined),
errorText: widget.controller.confirmPasswordError,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
contentPadding: EdgeInsets.symmetric(vertical: verticalPadding, horizontal: 16),
),
),
],
);
}
}
class RegisterButton extends StatelessWidget {
final RegisterController controller;
final VoidCallback onRegisterSuccess;
const RegisterButton({
super.key,
required this.controller,
required this.onRegisterSuccess,
});
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
// Mesmos tamanhos exatos do LoginButton
final buttonHeight = screenWidth > 600 ? 70.0 : 58.0;
final fontSize = screenWidth > 600 ? 22.0 : 18.0;
return SizedBox(
width: double.infinity,
height: buttonHeight,
child: ElevatedButton(
onPressed: controller.isLoading ? null : () async {
final success = await controller.signUp();
if (success) {
onRegisterSuccess();
}
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFE74C3C),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
elevation: 3,
),
child: controller.isLoading
? const SizedBox(
width: 28,
height: 28,
child: CircularProgressIndicator(
strokeWidth: 3,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Text(
'Criar Conta',
style: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.w700,
),
),
),
);
}
}