fix-general (#6)

Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/6
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-20 21:37:39 +02:00
committed by brontomark
parent c3d4f3fac7
commit c5b5b76bd6
4 changed files with 89 additions and 57 deletions

View File

@@ -2,6 +2,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flux/core/enums/enums.dart'; import 'package:flux/core/enums/enums.dart';
import 'package:flux/features/company/models/company_model.dart'; import 'package:flux/features/company/models/company_model.dart';
import 'package:flux/features/master_data/store/data/store_repository.dart';
import 'package:flux/features/master_data/store/models/store_model.dart'; import 'package:flux/features/master_data/store/models/store_model.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@@ -13,6 +14,7 @@ part 'session_state.dart';
class SessionBloc extends Bloc<SessionEvent, SessionState> { class SessionBloc extends Bloc<SessionEvent, SessionState> {
final SupabaseClient _supabase = GetIt.I.get<SupabaseClient>(); final SupabaseClient _supabase = GetIt.I.get<SupabaseClient>();
final StoreRepository _storeRepository = GetIt.I.get<StoreRepository>();
StreamSubscription<AuthState>? _authSubscription; StreamSubscription<AuthState>? _authSubscription;
SessionBloc() : super(const SessionState(status: SessionStatus.unknown)) { SessionBloc() : super(const SessionState(status: SessionStatus.unknown)) {
@@ -56,10 +58,7 @@ class SessionBloc extends Bloc<SessionEvent, SessionState> {
CompanyModel company = CompanyModel.fromJson(companyJson); CompanyModel company = CompanyModel.fromJson(companyJson);
// 2. Controlla i negozi // 2. Controlla i negozi
final stores = await _supabase final stores = await _storeRepository.fetchAllCompanyStores(company.id);
.from('store')
.select()
.eq('company_id', companyJson['id']);
if (stores.isEmpty) { if (stores.isEmpty) {
emit( emit(
@@ -71,27 +70,24 @@ class SessionBloc extends Bloc<SessionEvent, SessionState> {
); );
return; return;
} }
final availableStores = stores.map((s) => StoreModel.fromMap(s)).toList();
// 3. Tutto ok, gestiamo le SharedPreferences per il negozio // 3. Tutto ok, gestiamo le SharedPreferences per il negozio
final prefs = GetIt.I.get<SharedPreferences>(); final prefs = GetIt.I.get<SharedPreferences>();
String? lastStoreId = prefs.getString(PrefKeys.lastStore.value); String? lastStoreId = prefs.getString(PrefKeys.lastStore.value);
// Se non c'è nelle SharedPreferences, prendi il primo della lista // Se non c'è nelle SharedPreferences, prendi il primo della lista
if (lastStoreId == null || !stores.any((s) => s['id'] == lastStoreId)) { if (lastStoreId == null || !stores.any((s) => s.id == lastStoreId)) {
lastStoreId = stores.first['id']; lastStoreId = stores.first.id;
await prefs.setString('last_store_id', lastStoreId!); await prefs.setString('last_store_id', lastStoreId!);
} }
final selectedStore = StoreModel.fromMap( final selectedStore = stores.firstWhere((s) => s.id == lastStoreId);
stores.firstWhere((s) => s['id'] == lastStoreId),
);
emit( emit(
SessionState( SessionState(
status: SessionStatus.ready, status: SessionStatus.ready,
userId: event.userId, userId: event.userId,
company: company, company: company,
selectedStore: selectedStore, selectedStore: selectedStore,
availableStores: availableStores, availableStores: stores,
), ),
); );
}); });

View File

@@ -2,7 +2,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flux/core/theme/theme.dart'; import 'package:flux/core/theme/theme.dart';
class FluxTextField extends StatelessWidget { class FluxTextField extends StatefulWidget {
final String label; final String label;
final IconData icon; final IconData icon;
final bool isPassword; final bool isPassword;
@@ -30,20 +30,38 @@ class FluxTextField extends StatelessWidget {
this.maxLength, this.maxLength,
}); });
@override
State<FluxTextField> createState() => _FluxTextFieldState();
}
class _FluxTextFieldState extends State<FluxTextField> {
late bool _obscureText;
@override
void initState() {
super.initState();
_obscureText = widget.isPassword;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return TextField( return TextField(
controller: controller, controller: widget.controller,
obscureText: isPassword, obscureText: _obscureText,
keyboardType: keyboardType, enableSuggestions: !widget.isPassword,
autofocus: autoFocus, autocorrect: !widget.isPassword,
minLines: minLines, keyboardType: widget.keyboardType,
autofocus: widget.autoFocus,
minLines: widget.minLines,
// Se minLines è impostato, maxLines deve essere almeno uguale o null (espandibile) // Se minLines è impostato, maxLines deve essere almeno uguale o null (espandibile)
maxLines: minLines != null ? null : maxLines, maxLines: widget.minLines != null ? null : widget.maxLines,
style: TextStyle(color: context.primaryText), style: TextStyle(color: context.primaryText),
decoration: InputDecoration( decoration: InputDecoration(
prefixIcon: Icon(icon, color: context.accent.withValues(alpha: 0.6)), prefixIcon: Icon(
labelText: label, widget.icon,
color: context.accent.withValues(alpha: 0.6),
),
labelText: widget.label,
labelStyle: TextStyle(color: context.secondaryText, fontSize: 14), labelStyle: TextStyle(color: context.secondaryText, fontSize: 14),
filled: true, filled: true,
fillColor: context.surface.withValues(alpha: 0.5), fillColor: context.surface.withValues(alpha: 0.5),
@@ -61,10 +79,25 @@ class FluxTextField extends StatelessWidget {
horizontal: 16, horizontal: 16,
vertical: 16, vertical: 16,
), ),
suffixIcon: widget.isPassword
? IconButton(
icon: Icon(
// Cambiamo icona in base allo stato
_obscureText ? Icons.visibility_off : Icons.visibility,
color: Colors.grey,
), ),
onSubmitted: onSubmitted, onPressed: () {
onChanged: onChanged, // Quando l'utente clicca, invertiamo lo stato e ridisegniamo
maxLength: maxLength, setState(() {
_obscureText = !_obscureText;
});
},
)
: null, // Se non è una password, niente icona
),
onSubmitted: widget.onSubmitted,
onChanged: widget.onChanged,
maxLength: widget.maxLength,
); );
} }
} }

View File

@@ -15,6 +15,7 @@ class AuthScreen extends StatefulWidget {
class _AuthScreenState extends State<AuthScreen> { class _AuthScreenState extends State<AuthScreen> {
final _emailController = TextEditingController(); final _emailController = TextEditingController();
final _passwordController = TextEditingController(); final _passwordController = TextEditingController();
final _isPassword = true;
@override @override
void dispose() { void dispose() {

View File

@@ -14,7 +14,7 @@ class MasterDataHubContent extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
padding: const EdgeInsets.all(24.0), padding: const EdgeInsets.all(23.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -34,10 +34,15 @@ class MasterDataHubContent extends StatelessWidget {
const SizedBox(height: 32), const SizedBox(height: 32),
Expanded( Expanded(
child: GridView.count( child: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: MediaQuery.of(context).size.width > 600 ? 3 : 2, crossAxisCount: MediaQuery.of(context).size.width > 600 ? 3 : 2,
mainAxisSpacing: 16, mainAxisSpacing: 14,
crossAxisSpacing: 16, crossAxisSpacing: 14,
// LA MAGIA: Fissiamo l'altezza della card a 200 pixel
// indipendentemente da quanto sia stretta la colonna!
mainAxisExtent: 200,
),
children: [ children: [
_buildHubCard( _buildHubCard(
context, context,
@@ -45,9 +50,7 @@ class MasterDataHubContent extends StatelessWidget {
subtitle: 'Anagrafica di Marche e Modelli', subtitle: 'Anagrafica di Marche e Modelli',
icon: Icons.inventory_2_outlined, icon: Icons.inventory_2_outlined,
color: Colors.blue, color: Colors.blue,
onTap: () => onOpenPage( onTap: () => onOpenPage(const ProductsScreen()),
const ProductsScreen(),
), // Apre ProductsScreen, // Indice per ProductsScreen
), ),
_buildHubCard( _buildHubCard(
context, context,
@@ -55,9 +58,7 @@ class MasterDataHubContent extends StatelessWidget {
subtitle: 'Anagrafica dei clienti del tuo business', subtitle: 'Anagrafica dei clienti del tuo business',
icon: Icons.people_outlined, icon: Icons.people_outlined,
color: Colors.orange, color: Colors.orange,
onTap: () => onOpenPage( onTap: () => onOpenPage(const CustomersContent()),
const CustomersContent(),
), // Indice per CustomersContent
), ),
_buildHubCard( _buildHubCard(
context, context,
@@ -77,8 +78,9 @@ class MasterDataHubContent extends StatelessWidget {
), ),
_buildHubCard( _buildHubCard(
context, context,
title: 'Gestione Provider', title:
subtitle: 'Anagrafica mandati e servizi abilitati', 'Provider', // Accorciato per non andare a capo male su mobile
subtitle: 'Anagrafica mandati e servizi',
icon: Icons.handshake_rounded, icon: Icons.handshake_rounded,
color: Colors.indigo, color: Colors.indigo,
onTap: () { onTap: () {
@@ -110,43 +112,43 @@ Widget _buildHubCard(
return Card( return Card(
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
elevation: 2, elevation: 2,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
borderRadius: BorderRadius.circular(16),
), // Un pelo più arrotondato
child: InkWell( child: InkWell(
onTap: onTap, onTap: onTap,
child: Padding( child: Padding(
padding: const EdgeInsets.all( // Ridotto da 22 a 16 per dare più respiro orizzontale su mobile
24.0, padding: const EdgeInsets.all(16.0),
), // Aumentiamo il padding per dare respiro
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, // CENTRA VERTICALMENTE mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: crossAxisAlignment: CrossAxisAlignment.center,
CrossAxisAlignment.center, // CENTRA ORIZZONTALMENTE
children: [ children: [
// Icona con un leggero sfondo circolare opaco per farla risaltare
Container( Container(
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),
decoration: BoxDecoration( decoration: BoxDecoration(
color: color.withValues(alpha: 0.1), // <--- API moderna color: color.withValues(alpha: 0.1),
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
child: Icon(icon, size: 48, color: color), child: Icon(icon, size: 40, color: color),
), ),
const SizedBox(height: 16), const SizedBox(height: 12), // Leggermente ridotto
Text( Text(
title, title,
textAlign: TextAlign.center, // Centra il testo textAlign: TextAlign.center,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
maxLines: 1,
overflow: TextOverflow.ellipsis,
), ),
const SizedBox(height: 8), const SizedBox(height: 4), // Leggermente ridotto
Text( Expanded(
// Impedisce matematicamente l'overflow verticale
child: Text(
subtitle, subtitle,
textAlign: TextAlign.center, // Centra il sottotitolo textAlign: TextAlign.center,
style: TextStyle(fontSize: 13, color: Colors.grey.shade500), style: TextStyle(fontSize: 13, color: Colors.grey.shade500),
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
),
], ],
), ),
), ),