156 lines
5.5 KiB
Dart
156 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
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';
|
|
|
|
class AuthScreen extends StatefulWidget {
|
|
const AuthScreen({super.key});
|
|
|
|
@override
|
|
State<AuthScreen> createState() => _AuthScreenState();
|
|
}
|
|
|
|
class _AuthScreenState extends State<AuthScreen> {
|
|
final _emailController = TextEditingController();
|
|
final _passwordController = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_emailController.dispose();
|
|
_passwordController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: BlocConsumer<AuthBloc, AuthState>(
|
|
listener: (context, state) {
|
|
if (state.status == AuthStatus.failure) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(state.error ?? 'Errore di autenticazione'),
|
|
backgroundColor: Colors.redAccent,
|
|
),
|
|
);
|
|
}
|
|
},
|
|
builder: (context, state) {
|
|
final isLoading = state.status == AuthStatus.loading;
|
|
|
|
return SafeArea(
|
|
child: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
// --- LOGO FLUX ---
|
|
FluxLogoAuto(height: 80),
|
|
const SizedBox(height: 60),
|
|
|
|
// --- TITOLO DINAMICO ---
|
|
Text(
|
|
state.isLoginMode ? 'BENTORNATO' : 'CREA ACCOUNT',
|
|
style: TextStyle(
|
|
color: context.primaryText,
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.w900,
|
|
letterSpacing: 1.5,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
state.isLoginMode
|
|
? 'Accedi per gestire il tuo business'
|
|
: 'Inizia oggi a digitalizzare il tuo negozio',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(color: context.secondaryText),
|
|
),
|
|
const SizedBox(height: 40),
|
|
|
|
// --- CAMPI INPUT ---
|
|
FluxTextField(
|
|
label: 'Email Aziendale',
|
|
icon: Icons.email_outlined,
|
|
controller: _emailController,
|
|
keyboardType: TextInputType.emailAddress,
|
|
),
|
|
const SizedBox(height: 20),
|
|
FluxTextField(
|
|
label: 'Password',
|
|
icon: Icons.lock_outline,
|
|
isPassword: true,
|
|
controller: _passwordController,
|
|
onSubmitted: (_) => _submit(),
|
|
),
|
|
|
|
const SizedBox(height: 40),
|
|
|
|
// --- BOTTONE PRINCIPALE ---
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 56,
|
|
child: ElevatedButton(
|
|
onPressed: isLoading ? null : () => _submit(),
|
|
child: isLoading
|
|
? const SizedBox(
|
|
height: 24,
|
|
width: 24,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
color: Colors.white,
|
|
),
|
|
)
|
|
: Text(state.isLoginMode ? 'ACCEDI' : 'REGISTRATI'),
|
|
),
|
|
),
|
|
|
|
// --- SWITCH LOGIN/SIGNUP ---
|
|
const SizedBox(height: 24),
|
|
TextButton(
|
|
onPressed: isLoading
|
|
? null
|
|
: () {
|
|
context.read<AuthBloc>().add(ToggleAuthMode());
|
|
},
|
|
child: RichText(
|
|
text: TextSpan(
|
|
text: state.isLoginMode
|
|
? "Non hai un account? "
|
|
: "Hai già un account? ",
|
|
style: TextStyle(color: context.secondaryText),
|
|
children: [
|
|
TextSpan(
|
|
text: state.isLoginMode ? "Registrati" : "Accedi",
|
|
style: TextStyle(
|
|
color: context.accent,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
void _submit() {
|
|
context.read<AuthBloc>().add(
|
|
LoginRequested(
|
|
email: _emailController.text.trim(),
|
|
password: _passwordController.text.trim(),
|
|
),
|
|
);
|
|
}
|
|
}
|