rework-onboarding (#7)

Onboarding completato, ora super rapido e top

Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/7
Co-authored-by: Mark M2 Macbook <marco@catelli.it>
Co-committed-by: Mark M2 Macbook <marco@catelli.it>
This commit is contained in:
2026-04-22 11:06:02 +02:00
committed by brontomark
parent c5b5b76bd6
commit 90bd5ecacf
47 changed files with 1742 additions and 516 deletions

View File

@@ -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 ---
@@ -83,9 +106,10 @@ class _AuthScreenState extends State<AuthScreen> {
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 +119,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 +129,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 +143,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 +171,4 @@ class _AuthScreenState extends State<AuthScreen> {
),
);
}
void _submit() {
context.read<AuthBloc>().add(
LoginRequested(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
),
);
}
}