2026-04-06 10:55:56 +02:00
|
|
|
// lib/ui/auth/auth_screen.dart
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2026-04-07 11:30:22 +02:00
|
|
|
import 'package:flux/features/auth/bloc/auth_bloc.dart';
|
|
|
|
|
import 'package:flux/core/theme/theme.dart';
|
|
|
|
|
import 'package:flux/core/widgets/flux_text_field.dart';
|
2026-04-06 10:55:56 +02:00
|
|
|
|
|
|
|
|
class AuthScreen extends StatefulWidget {
|
|
|
|
|
const AuthScreen({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<AuthScreen> createState() => _AuthScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AuthScreenState extends State<AuthScreen> {
|
|
|
|
|
final _emailController = TextEditingController();
|
|
|
|
|
final _passwordController = TextEditingController();
|
|
|
|
|
final _storeController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return BlocConsumer<AuthBloc, AuthState>(
|
|
|
|
|
listener: (context, state) {
|
|
|
|
|
if (state.status == AuthStatus.failure) {
|
|
|
|
|
// Mostra l'errore che arriva da Supabase (es. "Invalid login credentials")
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(content: Text(state.error!), backgroundColor: Colors.red),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
2026-04-07 11:30:22 +02:00
|
|
|
FluxTextField(
|
2026-04-06 10:55:56 +02:00
|
|
|
label: 'Email',
|
|
|
|
|
icon: Icons.email,
|
|
|
|
|
controller: _emailController,
|
|
|
|
|
),
|
2026-04-07 11:30:22 +02:00
|
|
|
FluxTextField(
|
2026-04-06 10:55:56 +02:00
|
|
|
label: 'Password',
|
|
|
|
|
icon: Icons.lock,
|
|
|
|
|
isPassword: true,
|
|
|
|
|
controller: _passwordController,
|
|
|
|
|
),
|
|
|
|
|
if (!state.isLoginMode)
|
2026-04-07 11:30:22 +02:00
|
|
|
FluxTextField(
|
2026-04-06 10:55:56 +02:00
|
|
|
label: 'Codice Negozio',
|
|
|
|
|
icon: Icons.store,
|
|
|
|
|
controller: _storeController,
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: state.status == AuthStatus.loading
|
|
|
|
|
? null
|
|
|
|
|
: () {
|
|
|
|
|
context.read<AuthBloc>().add(
|
|
|
|
|
LoginRequested(
|
|
|
|
|
email: _emailController.text.trim(),
|
|
|
|
|
password: _passwordController.text.trim(),
|
|
|
|
|
storeCode: _storeController.text.trim(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: state.status == AuthStatus.loading
|
|
|
|
|
? const CircularProgressIndicator()
|
|
|
|
|
: Text(state.isLoginMode ? 'ACCEDI' : 'REGISTRATI'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_emailController.dispose();
|
|
|
|
|
_passwordController.dispose();
|
|
|
|
|
_storeController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _FluxLogo extends StatelessWidget {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.all_inclusive,
|
|
|
|
|
size: 80,
|
|
|
|
|
color: context.accent,
|
|
|
|
|
), // Simbolo Flux/Infinito
|
|
|
|
|
Text(
|
|
|
|
|
'FLUX',
|
|
|
|
|
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.w900,
|
|
|
|
|
letterSpacing: 8,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|