aiuto
This commit is contained in:
@@ -3,7 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/widgets/flux_logo.dart';
|
||||
import 'package:flux/core/widgets/flux_text_field.dart';
|
||||
import 'package:flux/features/auth/bloc/auth_bloc.dart';
|
||||
import 'package:flux/features/auth/bloc/auth_cubit.dart';
|
||||
|
||||
class AuthScreen extends StatefulWidget {
|
||||
const AuthScreen({super.key});
|
||||
@@ -15,7 +15,6 @@ class AuthScreen extends StatefulWidget {
|
||||
class _AuthScreenState extends State<AuthScreen> {
|
||||
final _emailController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _isPassword = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -24,19 +23,43 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
// Chiudiamo la tastiera per fare pulizia a schermo
|
||||
FocusScope.of(context).unfocus();
|
||||
|
||||
context.read<AuthCubit>().submitAuth(
|
||||
_emailController.text.trim(),
|
||||
_passwordController.text.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: BlocConsumer<AuthBloc, AuthState>(
|
||||
body: BlocConsumer<AuthCubit, AuthState>(
|
||||
// Ottimizzazione: Ridisegniamo la UI solo quando cambia lo status o la modalità
|
||||
listenWhen: (previous, current) =>
|
||||
previous.errorMessage != current.errorMessage ||
|
||||
previous.infoMessage != current.infoMessage,
|
||||
listener: (context, state) {
|
||||
if (state.status == AuthStatus.failure) {
|
||||
// Mostriamo l'errore se c'è
|
||||
if (state.errorMessage != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.error ?? 'Errore di autenticazione'),
|
||||
content: Text(state.errorMessage!),
|
||||
backgroundColor: Colors.redAccent,
|
||||
),
|
||||
);
|
||||
}
|
||||
// Mostriamo il messaggio info (es. Conferma Email)
|
||||
if (state.infoMessage != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.infoMessage!),
|
||||
backgroundColor: Colors.blueAccent, // O context.accent
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
final isLoading = state.status == AuthStatus.loading;
|
||||
@@ -49,7 +72,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// --- LOGO FLUX ---
|
||||
FluxLogoAuto(height: 80),
|
||||
const FluxLogoAuto(height: 80),
|
||||
const SizedBox(height: 60),
|
||||
|
||||
// --- TITOLO DINAMICO ---
|
||||
@@ -77,15 +100,15 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
label: 'Email Aziendale',
|
||||
icon: Icons.email_outlined,
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
// TODO: Aggiungi nel tuo FluxTextField la gestione del keyboardType se non c'è già!
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
FluxTextField(
|
||||
label: 'Password',
|
||||
icon: Icons.lock_outline,
|
||||
isPassword: true,
|
||||
isPassword: true, // Magia del FluxTextField!
|
||||
controller: _passwordController,
|
||||
onSubmitted: (_) => _submit(),
|
||||
// onSubmitted: (_) => _submit(), // Se lo supporti nel tuo widget custom
|
||||
),
|
||||
|
||||
const SizedBox(height: 40),
|
||||
@@ -95,7 +118,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
width: double.infinity,
|
||||
height: 56,
|
||||
child: ElevatedButton(
|
||||
onPressed: isLoading ? null : () => _submit(),
|
||||
onPressed: isLoading ? null : _submit,
|
||||
child: isLoading
|
||||
? const SizedBox(
|
||||
height: 24,
|
||||
@@ -105,7 +128,12 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: Text(state.isLoginMode ? 'ACCEDI' : 'REGISTRATI'),
|
||||
: Text(
|
||||
state.isLoginMode ? 'ACCEDI' : 'REGISTRATI',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -114,9 +142,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
TextButton(
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () {
|
||||
context.read<AuthBloc>().add(ToggleAuthMode());
|
||||
},
|
||||
: () => context.read<AuthCubit>().toggleMode(),
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
text: state.isLoginMode
|
||||
@@ -144,13 +170,4 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
context.read<AuthBloc>().add(
|
||||
LoginRequested(
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text.trim(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user