auth
This commit is contained in:
176
lib/ui/auth/auth_screen.dart
Normal file
176
lib/ui/auth/auth_screen.dart
Normal file
@@ -0,0 +1,176 @@
|
||||
// lib/ui/auth/auth_screen.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/blocs/auth/auth_bloc.dart';
|
||||
import 'package:flux/theme/theme.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();
|
||||
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: [
|
||||
_AuthTextField(
|
||||
label: 'Email',
|
||||
icon: Icons.email,
|
||||
controller: _emailController,
|
||||
),
|
||||
_AuthTextField(
|
||||
label: 'Password',
|
||||
icon: Icons.lock,
|
||||
isPassword: true,
|
||||
controller: _passwordController,
|
||||
),
|
||||
if (!state.isLoginMode)
|
||||
_AuthTextField(
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AuthTextField extends StatefulWidget {
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final bool isPassword;
|
||||
final TextEditingController? controller; // Aggiunto per recuperare i dati
|
||||
|
||||
const _AuthTextField({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
this.isPassword = false,
|
||||
this.controller,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_AuthTextField> createState() => _AuthTextFieldState();
|
||||
}
|
||||
|
||||
class _AuthTextFieldState extends State<_AuthTextField> {
|
||||
bool _obscureText = true; // Stato interno per la visibilità
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(
|
||||
controller: widget.controller,
|
||||
obscureText: widget.isPassword ? _obscureText : false,
|
||||
style: TextStyle(color: context.primaryText),
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: Icon(
|
||||
widget.icon,
|
||||
color: context.accent.withValues(alpha: 0.6),
|
||||
),
|
||||
labelText: widget.label,
|
||||
labelStyle: TextStyle(color: context.secondaryText, fontSize: 14),
|
||||
filled: true,
|
||||
fillColor: context.surface.withValues(alpha: 0.5),
|
||||
|
||||
// --- LOGICA OCCHIO PASSWORD ---
|
||||
suffixIcon: widget.isPassword
|
||||
? IconButton(
|
||||
icon: Icon(
|
||||
_obscureText
|
||||
? Icons.visibility_off_outlined
|
||||
: Icons.visibility_outlined,
|
||||
color: context.secondaryText,
|
||||
size: 20,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscureText = !_obscureText;
|
||||
});
|
||||
},
|
||||
)
|
||||
: null,
|
||||
|
||||
// --- BORDI STILE FLUX ---
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: context.secondaryText.withValues(alpha: 0.1),
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: context.accent, width: 1.5),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user