2026-05-03 12:44:51 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2026-05-03 13:03:50 +02:00
|
|
|
import 'package:flux/core/blocs/session/session_cubit.dart';
|
|
|
|
|
import 'package:flux/features/master_data/staff/blocs/staff_cubit.dart';
|
2026-05-03 12:44:51 +02:00
|
|
|
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
|
|
|
|
import 'package:flux/features/operations/models/operation_model.dart';
|
2026-05-03 13:03:50 +02:00
|
|
|
import 'package:get_it/get_it.dart';
|
2026-05-03 12:44:51 +02:00
|
|
|
// IMPORTA IL TUO CUBIT DELLO STAFF
|
|
|
|
|
// import 'package:flux/features/staff/blocs/staff_cubit.dart';
|
|
|
|
|
|
|
|
|
|
class StaffSection extends StatelessWidget {
|
|
|
|
|
final OperationModel? currentOp;
|
|
|
|
|
|
|
|
|
|
const StaffSection({super.key, required this.currentOp});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final theme = Theme.of(context);
|
2026-05-03 13:03:50 +02:00
|
|
|
final selectedStaffId =
|
|
|
|
|
currentOp?.staffId ??
|
|
|
|
|
GetIt.I.get<SessionCubit>().state.currentStaffMember?.id;
|
2026-05-03 12:44:51 +02:00
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 12.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
'Operatore',
|
|
|
|
|
style: theme.textTheme.titleLarge?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2026-05-03 13:03:50 +02:00
|
|
|
BlocBuilder<StaffCubit, StaffState>(
|
|
|
|
|
builder: (context, state) {
|
2026-05-03 12:44:51 +02:00
|
|
|
// Dati finti per farti vedere la UI, piallali quando attacchi il BlocBuilder!
|
2026-05-03 13:03:50 +02:00
|
|
|
final staffMembers = state.storeStaff;
|
|
|
|
|
final currentLoggedStaffMember = GetIt.I
|
|
|
|
|
.get<SessionCubit>()
|
|
|
|
|
.state
|
|
|
|
|
.currentStaffMember;
|
2026-05-03 12:44:51 +02:00
|
|
|
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
|
child: Row(
|
|
|
|
|
children: staffMembers.map((staff) {
|
2026-05-03 13:03:50 +02:00
|
|
|
final isSelected = staff.id == selectedStaffId;
|
2026-05-03 12:44:51 +02:00
|
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
// Aggiorniamo la form con un solo tap!
|
|
|
|
|
context.read<OperationsCubit>().updateOperationFields(
|
2026-05-03 13:03:50 +02:00
|
|
|
staffId: staff.id,
|
|
|
|
|
staffDisplayName: staff.name,
|
2026-05-03 12:44:51 +02:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: AnimatedContainer(
|
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
|
margin: const EdgeInsets.only(right: 12.0),
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 16.0,
|
|
|
|
|
vertical: 10.0,
|
|
|
|
|
),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: isSelected
|
|
|
|
|
? theme.colorScheme.primary
|
|
|
|
|
: theme.colorScheme.surface,
|
|
|
|
|
borderRadius: BorderRadius.circular(30),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: isSelected
|
|
|
|
|
? theme.colorScheme.primary
|
|
|
|
|
: theme.dividerColor,
|
|
|
|
|
width: 1.5,
|
|
|
|
|
),
|
|
|
|
|
boxShadow: isSelected
|
|
|
|
|
? [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: theme.colorScheme.primary.withValues(
|
|
|
|
|
alpha: 0.3,
|
|
|
|
|
),
|
|
|
|
|
blurRadius: 8,
|
|
|
|
|
offset: const Offset(0, 2),
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
CircleAvatar(
|
|
|
|
|
radius: 12,
|
|
|
|
|
backgroundColor: isSelected
|
|
|
|
|
? Colors.white
|
|
|
|
|
: theme.colorScheme.primaryContainer,
|
|
|
|
|
child: Text(
|
2026-05-03 13:03:50 +02:00
|
|
|
staff.name.substring(0, 1).toUpperCase(),
|
2026-05-03 12:44:51 +02:00
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: isSelected
|
|
|
|
|
? theme.colorScheme.primary
|
|
|
|
|
: theme.colorScheme.onPrimaryContainer,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Text(
|
2026-05-03 13:03:50 +02:00
|
|
|
staff == currentLoggedStaffMember
|
|
|
|
|
? 'Tu (${staff.name})'
|
|
|
|
|
: staff.name,
|
2026-05-03 12:44:51 +02:00
|
|
|
style: TextStyle(
|
|
|
|
|
fontWeight: isSelected
|
|
|
|
|
? FontWeight.bold
|
|
|
|
|
: FontWeight.w500,
|
|
|
|
|
color: isSelected
|
|
|
|
|
? Colors.white
|
|
|
|
|
: theme.colorScheme.onSurface,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|