This commit is contained in:
2026-04-13 19:27:23 +02:00
parent f710183f61
commit f33b63c0c6
3 changed files with 36 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ 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';
import 'package:flux/features/staff/blocs/staff_cubit.dart';
import 'package:flux/features/staff/models/staff_member_model.dart';
import 'package:flux/features/store/bloc/store_bloc.dart';
import 'package:flux/features/store/models/store_model.dart';
@@ -29,15 +30,16 @@ class _StoresScreenState extends State<StoresScreen> {
appBar: AppBar(title: const Text("I Tuoi Negozi")),
body: BlocBuilder<StoreBloc, StoreState>(
builder: (context, state) {
if (state.status == StoreStatus.loading)
if (state.status == StoreStatus.loading) {
return const Center(child: CircularProgressIndicator());
}
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: state.stores.length,
itemBuilder: (context, index) {
final store = state.stores[index];
return _buildStoreCard(store);
return _buildStoreCard(store, state.staffByStore);
},
);
},
@@ -50,7 +52,10 @@ class _StoresScreenState extends State<StoresScreen> {
);
}
Widget _buildStoreCard(StoreModel store) {
Widget _buildStoreCard(
StoreModel store,
Map<StoreModel, List<StaffMemberModel>> map,
) {
return Card(
margin: const EdgeInsets.only(bottom: 16),
shape: RoundedRectangleBorder(
@@ -89,16 +94,10 @@ class _StoresScreenState extends State<StoresScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Mostra quanti dipendenti ci sono (usando lo StaffCubit)
BlocBuilder<StaffCubit, StaffState>(
builder: (context, staffState) {
final staffCount =
staffState.staffByStore[store.id]?.length ?? 0;
return ActionChip(
avatar: const Icon(Icons.people, size: 16),
label: Text("$staffCount Dipendenti"),
onPressed: () => _manageStoreStaff(store),
);
},
ActionChip(
avatar: const Icon(Icons.people, size: 16),
label: Text("${map[store]?.length ?? 0} Dipendenti"),
onPressed: () => _manageStoreStaff(store),
),
TextButton.icon(
onPressed: () => _openStoreForm(context, store: store),