refactor power
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/data/enums.dart';
|
||||
import 'package:flux/core/enums/enums.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'dart:async';
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/data/enums.dart';
|
||||
import 'package:flux/core/enums/enums.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// lib/ui/auth/auth_screen.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
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';
|
||||
import 'package:flux/features/auth/bloc/auth_bloc.dart';
|
||||
|
||||
class AuthScreen extends StatefulWidget {
|
||||
const AuthScreen({super.key});
|
||||
@@ -15,86 +14,166 @@ class AuthScreen extends StatefulWidget {
|
||||
class _AuthScreenState extends State<AuthScreen> {
|
||||
final _emailController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _storeController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<AuthBloc, AuthState>(
|
||||
return Scaffold(
|
||||
body: 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),
|
||||
SnackBar(
|
||||
content: Text(state.error ?? 'Errore di autenticazione'),
|
||||
backgroundColor: Colors.redAccent,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
final isLoading = state.status == AuthStatus.loading;
|
||||
|
||||
return SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
FluxTextField(
|
||||
label: 'Email',
|
||||
icon: Icons.email,
|
||||
controller: _emailController,
|
||||
// --- LOGO FLUX ---
|
||||
_buildLogo(context),
|
||||
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,
|
||||
icon: Icons.lock_outline,
|
||||
isPassword: true,
|
||||
controller: _passwordController,
|
||||
),
|
||||
if (!state.isLoginMode)
|
||||
FluxTextField(
|
||||
label: 'Codice Negozio',
|
||||
icon: Icons.store,
|
||||
controller: _storeController,
|
||||
),
|
||||
|
||||
ElevatedButton(
|
||||
onPressed: state.status == AuthStatus.loading
|
||||
const SizedBox(height: 40),
|
||||
|
||||
// --- BOTTONE PRINCIPALE ---
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 56,
|
||||
child: ElevatedButton(
|
||||
onPressed: isLoading
|
||||
? 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()
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
_passwordController.dispose();
|
||||
_storeController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class _FluxLogo extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget _buildLogo(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.all_inclusive,
|
||||
size: 80,
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: context.accent.withValues(alpha: 0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.all_inclusive_rounded, // Simbolo dell'infinito/Flux
|
||||
size: 60,
|
||||
color: context.accent,
|
||||
), // Simbolo Flux/Infinito
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'FLUX',
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
style: TextStyle(
|
||||
color: context.primaryText,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 8,
|
||||
letterSpacing: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/blocs/company/company_bloc.dart';
|
||||
import 'package:flux/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/features/company/bloc/company_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/widgets/flux_text_field.dart';
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/theme/bloc/theme_bloc.dart';
|
||||
import 'package:flux/features/auth/bloc/auth_bloc.dart';
|
||||
import 'package:flux/features/auth/ui/auth_screen.dart';
|
||||
import 'package:flux/features/company/ui/create_company_screen.dart';
|
||||
import 'package:flux/features/store/ui/create_store_screen.dart';
|
||||
@@ -29,10 +30,13 @@ void main() async {
|
||||
runApp(
|
||||
MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(create: (context) => ThemeBloc()..add(LoadThemeEvent())),
|
||||
BlocProvider<ThemeBloc>(
|
||||
create: (context) => ThemeBloc()..add(LoadThemeEvent()),
|
||||
),
|
||||
BlocProvider<SessionBloc>(
|
||||
create: (context) => SessionBloc()..add(AppStarted()),
|
||||
),
|
||||
BlocProvider<AuthBloc>(create: (context) => AuthBloc()),
|
||||
],
|
||||
child: const FluxApp(),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/data/enums.dart';
|
||||
import 'package:flux/core/enums/enums.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/theme/bloc/theme_bloc.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user