Compare commits

...
4 Commits
Author SHA1 Message Date
brontomark 6ad0aa3e23 v
Build and Release FLUX (Multi-Platform) / build-android (push) Failing after 38s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 2m1s
Build and Release FLUX (Multi-Platform) / build-linux (push) Failing after 1m17s
Build and Release FLUX (Multi-Platform) / build-windows (push) Failing after 4m59s
Build and Release FLUX (Multi-Platform) / build-macos (push) Has been cancelled
2026-09-19 16:33:50 +02:00
brontomark 11c5352555 ritmo singolo addetto
Build and Release FLUX (Multi-Platform) / build-android (push) Successful in 2m40s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 1m53s
Build and Release FLUX (Multi-Platform) / build-macos (push) Successful in 3m8s
Build and Release FLUX (Multi-Platform) / build-windows (push) Failing after 4m4s
Build and Release FLUX (Multi-Platform) / build-linux (push) Failing after 1m16s
2026-09-19 14:05:29 +02:00
brontomark a0bdb9a535 fix titolo hero target widget su mobile
Build and Release FLUX (Multi-Platform) / build-android (push) Successful in 2m49s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 1m58s
Build and Release FLUX (Multi-Platform) / build-macos (push) Successful in 2m46s
Build and Release FLUX (Multi-Platform) / build-windows (push) Failing after 4m5s
Build and Release FLUX (Multi-Platform) / build-linux (push) Failing after 1m17s
2026-09-19 13:49:14 +02:00
brontomark 37d69e3ddc aggiunta navigazione al file viewer
Build and Release FLUX (Multi-Platform) / build-android (push) Successful in 3m26s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 2m41s
Build and Release FLUX (Multi-Platform) / build-macos (push) Successful in 3m3s
Build and Release FLUX (Multi-Platform) / build-windows (push) Failing after 6m14s
Build and Release FLUX (Multi-Platform) / build-linux (push) Failing after 1m16s
2026-09-19 13:34:54 +02:00
11 changed files with 795 additions and 378 deletions

No files matched your search

+4
View File
@@ -11,6 +11,10 @@ analyzer:
- "ios/**"
- "macos/**"
- ".dart_tool/**"
- android/**
- web/**
- windows/**
- linux/**
linter:
rules:
@@ -283,22 +283,35 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
}
// --- APERTURA VIEWER ---
void _openFile(AttachmentModel file) {
void _openFile(
AttachmentModel file, {
List<AttachmentModel>? files,
int? initialIndex,
}) {
// 1. Catturiamo il BLoC dalla pagina corrente prima di navigare
final operationFilesBloc = context.read<AttachmentsBloc>();
final allFilesList = files ?? operationFilesBloc.state.allFiles;
final index = initialIndex ??
(allFilesList.isNotEmpty ? allFilesList.indexOf(file) : 0);
Navigator.push(
context,
MaterialPageRoute(
builder: (viewerContext) => BlocProvider.value(
value: operationFilesBloc,
child: AttachmentViewerScreen(
attachment: file,
onRename: (newName) {
attachments: allFilesList.isNotEmpty ? allFilesList : [file],
initialIndex: index >= 0 ? index : 0,
onRenameAttachment: (targetFile, newName) {
// Spara l'evento al BLoC e lui farà il resto!
operationFilesBloc.add(RenameAttachmentEvent(file, newName));
operationFilesBloc.add(
RenameAttachmentEvent(targetFile, newName),
);
},
onDelete: () {
operationFilesBloc.add(DeleteSpecificAttachmentEvent(file));
onDeleteAttachment: (targetFile) {
operationFilesBloc.add(
DeleteSpecificAttachmentEvent(targetFile),
);
},
),
),
@@ -890,7 +903,11 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
children: [
// CARD DEL FILE
InkWell(
onTap: () => _openFile(file),
onTap: () => _openFile(
file,
files: allFiles,
initialIndex: index,
),
onLongPress: () {
// Selezione rapida con long press!
context.read<AttachmentsBloc>().add(
@@ -1,110 +1,191 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flux/core/utils/functions.dart';
import 'package:flux/features/attachments/models/attachment_model.dart';
import 'package:pdfx/pdfx.dart';
import 'package:internet_file/internet_file.dart';
class AttachmentViewerScreen extends StatefulWidget {
final AttachmentModel attachment;
final AttachmentModel? attachment;
final List<AttachmentModel>? attachments;
final int initialIndex;
final Function(String newName)? onRename;
final Function(AttachmentModel attachment, String newName)? onRenameAttachment;
final VoidCallback? onDelete;
final Function(AttachmentModel attachment)? onDeleteAttachment;
const AttachmentViewerScreen({
super.key,
required this.attachment,
this.attachment,
this.attachments,
this.initialIndex = 0,
this.onRename,
this.onRenameAttachment,
this.onDelete,
});
this.onDeleteAttachment,
}) : assert(
attachment != null || (attachments != null && attachments.length > 0),
'Devi fornire un allegato o una lista di allegati non vuota.',
);
@override
State<AttachmentViewerScreen> createState() => _AttachmentViewerScreenState();
}
class _AttachmentViewerScreenState extends State<AttachmentViewerScreen> {
late List<AttachmentModel> _items;
late int _currentIndex;
final FocusNode _focusNode = FocusNode();
PdfControllerPinch? _pdfController;
bool _isLoading = true;
String? _errorMessage;
Uint8List? _fileBytes;
late String _fileName;
int _loadToken = 0;
bool get isPdf => widget.attachment.extension.toLowerCase() == 'pdf';
AttachmentModel get _currentAttachment => _items[_currentIndex];
bool get isPdf =>
_currentAttachment.extension.toLowerCase().replaceAll('.', '') == 'pdf';
bool get hasMultipleFiles => _items.length > 1;
bool get canGoPrevious => _currentIndex > 0;
bool get canGoNext => _currentIndex < _items.length - 1;
@override
void initState() {
super.initState();
_fileName = widget.attachment.name;
_loadFile();
}
Future<void> _loadFile() async {
try {
// 1. Capiamo da dove prendere i dati
if (widget.attachment.localBytes != null) {
_fileBytes = widget.attachment.localBytes;
} else if (widget.attachment.storagePath != null &&
widget.attachment.storagePath!.isNotEmpty) {
final signedUrl = await getSignedUrl(widget.attachment.storagePath!);
_fileBytes = await InternetFile.get(signedUrl);
} else {
throw Exception("Nessun documento trovato o byte mancanti.");
}
// 2. Se è PDF, inizializziamo il controller
if (isPdf && _fileBytes != null) {
_pdfController = PdfControllerPinch(
document: PdfDocument.openData(_fileBytes!),
);
}
if (mounted) setState(() => _isLoading = false);
} catch (e) {
if (mounted) {
setState(() {
_isLoading = false;
_errorMessage = e.toString();
});
}
if (widget.attachments != null && widget.attachments!.isNotEmpty) {
_items = List<AttachmentModel>.from(widget.attachments!);
_currentIndex = widget.initialIndex.clamp(0, _items.length - 1);
} else if (widget.attachment != null) {
_items = [widget.attachment!];
_currentIndex = 0;
} else {
_items = [];
_currentIndex = 0;
}
_loadFile();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
_focusNode.requestFocus();
}
});
}
@override
void dispose() {
_focusNode.dispose();
_pdfController?.dispose();
super.dispose();
}
void _goToPrevious() {
if (!canGoPrevious) return;
_changeFile(_currentIndex - 1);
}
void _goToNext() {
if (!canGoNext) return;
_changeFile(_currentIndex + 1);
}
void _changeFile(int newIndex) {
if (newIndex < 0 || newIndex >= _items.length) return;
_pdfController?.dispose();
_pdfController = null;
setState(() {
_currentIndex = newIndex;
_isLoading = true;
_errorMessage = null;
_fileBytes = null;
});
_loadFile();
}
KeyEventResult _handleKeyEvent(FocusNode node, KeyEvent event) {
if (event is KeyDownEvent) {
if (event.logicalKey == LogicalKeyboardKey.arrowLeft) {
if (canGoPrevious) {
_goToPrevious();
return KeyEventResult.handled;
}
} else if (event.logicalKey == LogicalKeyboardKey.arrowRight) {
if (canGoNext) {
_goToNext();
return KeyEventResult.handled;
}
}
}
return KeyEventResult.ignored;
}
Future<void> _loadFile() async {
final token = ++_loadToken;
final item = _currentAttachment;
try {
Uint8List? bytes;
if (item.localBytes != null) {
bytes = item.localBytes;
} else if (item.storagePath != null &&
item.storagePath!.isNotEmpty) {
final signedUrl = await getSignedUrl(item.storagePath!);
bytes = await InternetFile.get(signedUrl);
} else {
throw Exception("Nessun documento trovato o byte mancanti.");
}
if (token != _loadToken || !mounted) return;
PdfControllerPinch? controller;
if (isPdf && bytes != null) {
controller = PdfControllerPinch(
document: PdfDocument.openData(bytes),
);
}
setState(() {
_fileBytes = bytes;
_pdfController = controller;
_isLoading = false;
});
} catch (e) {
if (token != _loadToken || !mounted) return;
setState(() {
_isLoading = false;
_errorMessage = e.toString();
});
}
}
void _showRenameDialog() {
final ctrl = TextEditingController(text: _fileName);
final current = _currentAttachment;
final ctrl = TextEditingController(text: current.name);
ctrl.selection = TextSelection(
baseOffset: 0,
extentOffset: ctrl.text.length,
);
final focusNode = FocusNode();
final dialogFocusNode = FocusNode();
showDialog(
context: context,
builder: (context) {
WidgetsBinding.instance.addPostFrameCallback(
(_) => focusNode.requestFocus(),
(_) => dialogFocusNode.requestFocus(),
);
return AlertDialog(
title: const Text('Rinomina File'),
content: TextField(
controller: ctrl,
focusNode: focusNode,
focusNode: dialogFocusNode,
decoration: InputDecoration(
labelText: 'Nuovo nome',
suffixText: '.${widget.attachment.extension}',
suffixText: '.${current.extension}',
),
onSubmitted: (val) {
Navigator.pop(context);
if (val.trim().isNotEmpty && widget.onRename != null) {
setState(() {
_fileName = val.trim();
});
widget.onRename!(val.trim());
}
_applyRename(val);
},
),
actions: [
@@ -115,73 +196,141 @@ class _AttachmentViewerScreenState extends State<AttachmentViewerScreen> {
ElevatedButton(
onPressed: () {
Navigator.pop(context);
if (ctrl.text.trim().isNotEmpty && widget.onRename != null) {
setState(() {
_fileName = ctrl.text.trim();
});
widget.onRename!(ctrl.text.trim());
}
_applyRename(ctrl.text);
},
child: const Text('Salva'),
),
],
);
},
).then((_) {
if (mounted) {
_focusNode.requestFocus();
}
});
}
void _applyRename(String val) {
final trimmed = val.trim();
if (trimmed.isEmpty) return;
final current = _currentAttachment;
final updated = current.copyWith(name: trimmed);
setState(() {
_items[_currentIndex] = updated;
});
widget.onRenameAttachment?.call(current, trimmed);
widget.onRename?.call(trimmed);
}
void _confirmDelete() {
final current = _currentAttachment;
showDialog(
context: context,
builder: (c) => AlertDialog(
title: const Text('Eliminare file?'),
content: const Text(
'Sei sicuro di voler eliminare questo allegato?',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(c),
child: const Text('Annulla'),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
),
onPressed: () {
Navigator.pop(c); // Chiude dialog
widget.onDeleteAttachment?.call(current);
widget.onDelete?.call();
Navigator.pop(context); // Chiude il viewer
},
child: const Text('Elimina'),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black87, // Sfondo scuro per i viewer è il top
appBar: AppBar(
backgroundColor: Colors.black,
foregroundColor: Colors.white,
title: Text(_fileName, style: const TextStyle(fontSize: 16)),
actions: [
if (widget.onRename != null)
IconButton(
icon: const Icon(Icons.edit),
tooltip: 'Rinomina',
onPressed: _showRenameDialog,
return Focus(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: _handleKeyEvent,
child: Scaffold(
backgroundColor: Colors.black87,
appBar: AppBar(
backgroundColor: Colors.black,
foregroundColor: Colors.white,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
_currentAttachment.name,
style: const TextStyle(fontSize: 16),
overflow: TextOverflow.ellipsis,
),
if (hasMultipleFiles)
Text(
'${_currentIndex + 1} di ${_items.length}',
style: const TextStyle(fontSize: 12, color: Colors.white70),
),
],
),
actions: [
if (widget.onRename != null || widget.onRenameAttachment != null)
IconButton(
icon: const Icon(Icons.edit),
tooltip: 'Rinomina',
onPressed: _showRenameDialog,
),
if (widget.onDelete != null || widget.onDeleteAttachment != null)
IconButton(
icon: const Icon(Icons.delete, color: Colors.redAccent),
tooltip: 'Elimina',
onPressed: _confirmDelete,
),
],
),
body: Stack(
children: [
Positioned.fill(
child: _buildBody(),
),
if (widget.onDelete != null)
IconButton(
icon: const Icon(Icons.delete, color: Colors.redAccent),
tooltip: 'Elimina',
onPressed: () {
// Chiediamo conferma
showDialog(
context: context,
builder: (c) => AlertDialog(
title: const Text('Eliminare file?'),
content: const Text(
'Sei sicuro di voler eliminare questo allegato?',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(c),
child: const Text('Annulla'),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
),
onPressed: () {
Navigator.pop(c); // Chiude dialog
widget.onDelete!(); // Lancia eliminazione
Navigator.pop(context); // Chiude il viewer
},
child: const Text('Elimina'),
),
],
// Freccia Precedente
if (hasMultipleFiles && canGoPrevious)
Positioned(
left: 16,
top: 0,
bottom: 0,
child: Center(
child: _NavigationArrowButton(
icon: Icons.arrow_back_ios_new_rounded,
tooltip: 'File precedente (←)',
onPressed: _goToPrevious,
),
);
},
),
],
),
),
// Freccia Successivo
if (hasMultipleFiles && canGoNext)
Positioned(
right: 16,
top: 0,
bottom: 0,
child: Center(
child: _NavigationArrowButton(
icon: Icons.arrow_forward_ios_rounded,
tooltip: 'File successivo (→)',
onPressed: _goToNext,
),
),
),
],
),
),
body: _buildBody(),
);
}
@@ -218,3 +367,41 @@ class _AttachmentViewerScreenState extends State<AttachmentViewerScreen> {
}
}
}
class _NavigationArrowButton extends StatelessWidget {
final IconData icon;
final String tooltip;
final VoidCallback onPressed;
const _NavigationArrowButton({
required this.icon,
required this.tooltip,
required this.onPressed,
});
@override
Widget build(BuildContext context) {
return Tooltip(
message: tooltip,
child: Material(
color: Colors.black.withValues(alpha: 0.55),
shape: const CircleBorder(),
clipBehavior: Clip.antiAlias,
elevation: 6,
child: InkWell(
onTap: onPressed,
hoverColor: Colors.white.withValues(alpha: 0.2),
splashColor: Colors.white.withValues(alpha: 0.3),
child: Padding(
padding: const EdgeInsets.all(12),
child: Icon(
icon,
color: Colors.white,
size: 28,
),
),
),
),
);
}
}
@@ -41,28 +41,78 @@ class DashboardTargetProgressState extends Equatable {
);
}
/// Avanzamento specifico del membro dello staff correntemente connesso
TargetProgressModel? get currentStaffProgress {
/// Avanzamento specifico del membro dello staff indicato o correntemente connesso
TargetProgressModel? getStaffProgress([String? staffId]) {
final curProgress = progress;
final staffId = currentStaffId;
if (curProgress == null || staffId == null) return null;
return curProgress.staffProgress[staffId];
final id = staffId ?? currentStaffId;
if (curProgress == null || id == null) return null;
return curProgress.staffProgress[id];
}
/// True se lo staff connesso ha almeno un target individuale attivo impostato
bool get hasStaffTargets {
final sp = currentStaffProgress;
/// True se lo staff connesso o specificato ha almeno un target individuale attivo impostato
bool hasStaffTargets([String? staffId]) {
final sp = getStaffProgress(staffId);
if (sp == null) return false;
return sp.categories.values.any((c) => c.hasTarget);
}
/// Lista delle categorie con target attivo per l'addetto connesso
List<CategoryProgress> get activeStaffCategories {
final sp = currentStaffProgress;
/// Lista delle categorie con target attivo per l'addetto indicato o connesso
List<CategoryProgress> activeStaffCategories([String? staffId]) {
final sp = getStaffProgress(staffId);
if (sp == null) return const [];
return sp.categories.values.where((c) => c.hasTarget).toList();
}
/// Restituisce sempre l'avanzamento personalizzato per lo staff
TargetProgressModel getEffectiveStaffProgress({
required String? staffId,
required String? staffName,
}) {
final sp = getStaffProgress(staffId);
if (sp != null) {
return sp;
}
final curProgress = progress;
if (curProgress == null) {
return TargetProgressModel.empty();
}
// Se l'addetto non è mappato nella lista (es. nuovo addetto senza operazioni),
// creiamo una scheda personale con le categorie attive del negozio
final staffCount = target?.individualTargets.length ?? 1;
final divisor = staffCount > 0 ? staffCount : 1;
final userCategories = <String, CategoryProgress>{};
for (final entry in curProgress.categories.entries) {
final storeCat = entry.value;
userCategories[entry.key] = CategoryProgress.calculate(
key: storeCat.key,
label: storeCat.label,
actual: 0,
s1: (storeCat.targetS1 / divisor).round(),
s2: (storeCat.targetS2 / divisor).round(),
elapsedDays: curProgress.elapsedWorkingDays,
remainingDays: curProgress.remainingWorkingDays,
totalDays: curProgress.totalWorkingDays,
);
}
return TargetProgressModel(
targetId: curProgress.targetId,
storeId: curProgress.storeId,
staffId: staffId,
staffName: staffName,
totalWorkingDays: curProgress.totalWorkingDays,
elapsedWorkingDays: curProgress.elapsedWorkingDays,
remainingWorkingDays: curProgress.remainingWorkingDays,
categories: userCategories,
);
}
/// Avanzamento specifico del membro dello staff correntemente connesso
TargetProgressModel? get currentStaffProgress => getStaffProgress();
/// Lista delle categorie con target attivo per il negozio
List<CategoryProgress> get activeStoreCategories {
final curProgress = progress;
@@ -150,286 +150,325 @@ class DashboardTargetHeroCard extends StatelessWidget {
final staffMember =
context.watch<SessionCubit>().state.currentStaffMember;
final staffName = staffMember?.name ?? 'Ospite';
final staffId = staffMember?.id;
final hasStaffTargets = state.hasStaffTargets;
final displayCategories = hasStaffTargets
? state.activeStaffCategories
: state.activeStoreCategories;
final staffProgress = state.getEffectiveStaffProgress(
staffId: staffId,
staffName: staffName,
);
final displayCategories = staffProgress.categories.values
.where((c) => c.hasTarget)
.toList();
final remainingDays = progress.remainingWorkingDays;
return Container(
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: theme.colorScheme.primary.withValues(alpha: 0.25),
width: 1.5,
),
boxShadow: [
BoxShadow(
color: theme.colorScheme.primary.withValues(alpha: 0.06),
blurRadius: 20,
offset: const Offset(0, 6),
return LayoutBuilder(
builder: (context, constraints) {
final isCompact = constraints.maxWidth < 600;
return Container(
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: theme.colorScheme.primary.withValues(alpha: 0.25),
width: 1.5,
),
boxShadow: [
BoxShadow(
color: theme.colorScheme.primary.withValues(alpha: 0.06),
blurRadius: 20,
offset: const Offset(0, 6),
),
],
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// ==========================================
// 1. HEADER DELLA CARD (TITOLO & GIORNI)
// ==========================================
Padding(
padding: const EdgeInsets.fromLTRB(20, 18, 20, 14),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
theme.colorScheme.primary,
theme.colorScheme.primary.withValues(alpha: 0.8),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.colorScheme.primary.withValues(alpha: 0.25),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: const Icon(
Icons.trending_up_rounded,
color: Colors.white,
size: 22,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// ==========================================
// 1. HEADER DELLA CARD (TITOLO & GIORNI)
// ==========================================
Padding(
padding: EdgeInsets.fromLTRB(
isCompact ? 14 : 20,
isCompact ? 14 : 18,
isCompact ? 14 : 20,
isCompact ? 10 : 14,
),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Flexible(
child: Text(
hasStaffTargets
? 'IL TUO RITMO PER OGGI'
: 'RITMO GIORNALIERO NEGOZIO',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w800,
letterSpacing: 0.8,
color: theme.colorScheme.primary,
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(isCompact ? 8 : 10),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
theme.colorScheme.primary,
theme.colorScheme.primary.withValues(alpha: 0.8),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: theme.colorScheme.primary
.withValues(alpha: 0.25),
blurRadius: 8,
offset: const Offset(0, 2),
),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 2,
),
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer
.withValues(alpha: 0.35),
borderRadius: BorderRadius.circular(6),
),
child: Text(
remainingDays > 1
? 'Mancano $remainingDays gg'
: (remainingDays == 1
? 'Ultimo giorno!'
: 'Mese concluso'),
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
],
),
child: Icon(
Icons.trending_up_rounded,
color: Colors.white,
size: isCompact ? 20 : 22,
),
),
SizedBox(width: isCompact ? 10 : 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
runSpacing: 4,
children: [
Text(
'IL TUO RITMO PER OGGI',
style: TextStyle(
fontSize: isCompact ? 10.5 : 11,
fontWeight: FontWeight.w800,
letterSpacing: 0.6,
color: theme.colorScheme.primary,
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 7,
vertical: 2,
),
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer
.withValues(alpha: 0.35),
borderRadius: BorderRadius.circular(6),
),
child: Text(
remainingDays > 1
? 'Mancano $remainingDays gg'
: (remainingDays == 1
? 'Ultimo giorno!'
: 'Mese concluso'),
style: TextStyle(
fontSize: isCompact ? 10 : 11,
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
),
),
),
],
),
const SizedBox(height: 3),
Text(
staffMember != null
? 'Cosa portare a casa oggi, $staffName'
: 'Obiettivi personali per oggi',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w900,
fontSize: isCompact ? 15 : 17,
),
),
],
),
const SizedBox(height: 3),
Text(
hasStaffTargets
? 'Cosa portare a casa oggi, $staffName'
: 'Obiettivi di ${target.store?.name ?? "Negozio"} per oggi',
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w900,
fontSize: 17,
),
const SizedBox(width: 4),
// Tasto rapido dettaglio
if (isCompact)
IconButton(
onPressed: () => context.pushNamed(
Routes.targetDetail,
extra: target,
),
icon: const Icon(Icons.analytics_outlined),
tooltip: 'Dettagli target',
color: theme.colorScheme.primary,
visualDensity: VisualDensity.compact,
)
else
TextButton.icon(
onPressed: () => context.pushNamed(
Routes.targetDetail,
extra: target,
),
icon: const Icon(Icons.analytics_outlined, size: 18),
label: const Text('Dettagli'),
style: TextButton.styleFrom(
visualDensity: VisualDensity.compact,
foregroundColor: theme.colorScheme.primary,
textStyle: const TextStyle(fontWeight: FontWeight.bold),
),
),
],
),
),
// Tasto rapido dettaglio
TextButton.icon(
onPressed: () => context.pushNamed(
Routes.targetDetail,
extra: target,
),
icon: const Icon(Icons.analytics_outlined, size: 18),
label: const Text('Dettagli'),
style: TextButton.styleFrom(
visualDensity: VisualDensity.compact,
foregroundColor: theme.colorScheme.primary,
textStyle: const TextStyle(fontWeight: FontWeight.bold),
),
),
],
),
),
// ==========================================
// 2. FOCUS METRICHE: MEDIE RICHIESTE PER OGGI
// ==========================================
if (displayCategories.isEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
child: Text(
'Nessun obiettivo attivo configurato per questo mese.',
style: TextStyle(
color: theme.colorScheme.onSurfaceVariant,
fontSize: 13,
],
),
),
)
else
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: LayoutBuilder(
builder: (context, constraints) {
final isWide = constraints.maxWidth > 700;
return GridView.builder(
// ==========================================
// 2. FOCUS METRICHE: MEDIE RICHIESTE PER OGGI
// ==========================================
if (displayCategories.isEmpty)
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
child: Text(
'Nessun obiettivo attivo configurato per questo mese.',
style: TextStyle(
color: theme.colorScheme.onSurfaceVariant,
fontSize: 13,
),
),
)
else
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: displayCategories.length,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: isWide ? 260 : 200,
mainAxisExtent: 154,
maxCrossAxisExtent:
constraints.maxWidth > 700 ? 260 : 200,
mainAxisExtent: 168,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemBuilder: (context, index) {
final category = displayCategories[index];
return _buildCategoryDailyPacingCard(theme, category);
final storeCategory = progress.categories[category.key];
return _buildCategoryDailyPacingCard(
theme,
category,
storeCategory: storeCategory,
);
},
);
},
),
),
),
),
const SizedBox(height: 14),
const SizedBox(height: 14),
// ==========================================
// 3. SEZIONE INFERIORE: RIEPILOGO NEGOZIO
// ==========================================
Container(
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest
.withValues(alpha: 0.35),
borderRadius: const BorderRadius.vertical(
bottom: Radius.circular(19),
),
border: Border(
top: BorderSide(
color: theme.dividerColor.withValues(alpha: 0.2),
),
),
),
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
child: Row(
children: [
Icon(
Icons.storefront_outlined,
size: 18,
color: theme.colorScheme.primary,
),
const SizedBox(width: 8),
Text(
'Negozio:',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w800,
color: theme.colorScheme.primary,
letterSpacing: 0.5,
// ==========================================
// 3. SEZIONE INFERIORE: RIEPILOGO NEGOZIO
// ==========================================
Container(
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest
.withValues(alpha: 0.35),
borderRadius: const BorderRadius.vertical(
bottom: Radius.circular(19),
),
),
const SizedBox(width: 10),
// Badge sintetici del negozio
_buildMiniBadge(
label: '${progress.countAchieved}/${progress.countTotalActive} Presi',
color: const Color(0xFF15803D),
bgColor: const Color(0xFFDCFCE7),
),
const SizedBox(width: 6),
_buildMiniBadge(
label: '${progress.countInLineOnly} In linea',
color: const Color(0xFF0D9488),
bgColor: const Color(0xFFCCFBF1),
),
if (progress.countBehind > 0) ...[
const SizedBox(width: 6),
_buildMiniBadge(
label: '${progress.countBehind} Sotto ritmo',
color: const Color(0xFFDC2626),
bgColor: const Color(0xFFFEE2E2),
),
],
const Spacer(),
InkWell(
onTap: () => context.pushNamed(
Routes.targetDetail,
extra: target,
),
borderRadius: BorderRadius.circular(6),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
border: Border(
top: BorderSide(
color: theme.dividerColor.withValues(alpha: 0.2),
),
child: Row(
mainAxisSize: MainAxisSize.min,
),
),
padding: EdgeInsets.symmetric(
horizontal: isCompact ? 14 : 20,
vertical: 10,
),
child: Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 10,
runSpacing: 8,
children: [
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 6,
runSpacing: 4,
children: [
Text(
'Apri analisi completa',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
),
),
const SizedBox(width: 4),
Icon(
Icons.arrow_forward_rounded,
size: 14,
Icons.storefront_outlined,
size: 17,
color: theme.colorScheme.primary,
),
Text(
'Negozio:',
style: TextStyle(
fontSize: 11.5,
fontWeight: FontWeight.w800,
color: theme.colorScheme.primary,
letterSpacing: 0.5,
),
),
const SizedBox(width: 2),
// Badge sintetici del negozio
_buildMiniBadge(
label:
'${progress.countAchieved}/${progress.countTotalActive} Presi',
color: const Color(0xFF15803D),
bgColor: const Color(0xFFDCFCE7),
),
_buildMiniBadge(
label: '${progress.countInLineOnly} In linea',
color: const Color(0xFF0D9488),
bgColor: const Color(0xFFCCFBF1),
),
if (progress.countBehind > 0)
_buildMiniBadge(
label: '${progress.countBehind} Sotto ritmo',
color: const Color(0xFFDC2626),
bgColor: const Color(0xFFFEE2E2),
),
],
),
),
InkWell(
onTap: () => context.pushNamed(
Routes.targetDetail,
extra: target,
),
borderRadius: BorderRadius.circular(6),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 2,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Apri analisi completa',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
),
),
const SizedBox(width: 4),
Icon(
Icons.arrow_forward_rounded,
size: 14,
color: theme.colorScheme.primary,
),
],
),
),
),
],
),
],
),
),
],
),
],
),
);
},
);
}
Widget _buildCategoryDailyPacingCard(
ThemeData theme,
CategoryProgress category,
) {
CategoryProgress category, {
CategoryProgress? storeCategory,
}) {
final pacingTheme = PacingTheme.of(category.status);
final isAchieved = category.isAchieved;
final hasS2 = category.targetS2 > 0;
@@ -532,7 +571,7 @@ class DashboardTargetHeroCard extends StatelessWidget {
)
else
Text(
'Soglia minima centrata!',
'Obiettivo personale centrato!',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w600,
@@ -581,7 +620,7 @@ class DashboardTargetHeroCard extends StatelessWidget {
)
else
Text(
'per Minimo (${category.targetS1})',
'Target: ${category.targetS1} pz',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w600,
@@ -593,12 +632,12 @@ class DashboardTargetHeroCard extends StatelessWidget {
const Spacer(),
// Footer: Avanzamento e ritmo attuale
// Footer: Avanzamento personale e ritmo
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Fatti: ${category.actualPieces} / ${category.targetS1}',
'I tuoi: ${category.actualPieces} / ${category.targetS1}',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
@@ -627,6 +666,30 @@ class DashboardTargetHeroCard extends StatelessWidget {
color: pacingTheme.primary,
),
),
if (storeCategory != null && storeCategory.targetS1 > 0) ...[
const SizedBox(height: 4),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Negozio: ${storeCategory.actualPieces}/${storeCategory.targetS1}',
style: TextStyle(
fontSize: 9.5,
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.75),
fontWeight: FontWeight.w600,
),
),
Text(
'ritmo: ${storeCategory.actualDailyRate.toStringAsFixed(1)}/gg',
style: TextStyle(
fontSize: 9.5,
color: theme.colorScheme.onSurfaceVariant.withValues(alpha: 0.75),
fontWeight: FontWeight.w600,
),
),
],
),
],
],
),
);
+6
View File
@@ -79,6 +79,12 @@ class _HomeScreenState extends State<HomeScreen> {
}
void _startListeners() {
final sessionState = context.read<SessionCubit>().state;
context.read<DashboardTargetProgressCubit>().updateContext(
newCompanyId: sessionState.company?.id,
newStoreId: sessionState.currentStore?.id,
newStaffId: sessionState.currentStaffMember?.id,
);
context.read<DashboardStoreOperationListCubit>().startListening();
context.read<DashboardTaskListCubit>().startListening();
context.read<DashboardStoreTicketListCubit>().startListening();
@@ -139,14 +139,39 @@ class TargetProgressService {
// 4. Costruzione avanzamento per singoli addetti
final staffProgressMap = <String, TargetProgressModel>{};
for (final it in target.individualTargets) {
final individualTargetsList = target.individualTargets;
final bool hasExplicitIndividualTargets = individualTargetsList.any(
(it) => it.metrics.totalLevel1 > 0 || it.metrics.totalLevel2 > 0,
);
final int staffCount = individualTargetsList.isNotEmpty
? individualTargetsList.length
: (staffCounts.isNotEmpty ? staffCounts.length : 1);
for (final it in individualTargetsList) {
final sId = it.staffId;
final sCounts = staffCounts[sId] ?? {};
final sCategories = <String, CategoryProgress>{};
for (final def in metricDefinitions) {
final actual = sCounts[def.key] ?? 0;
final targets = _extractTargetS1S2(it.metrics, def.key);
({int s1, int s2}) targets;
if (hasExplicitIndividualTargets) {
targets = _extractTargetS1S2(it.metrics, def.key);
} else {
// Se non sono stati assegnati target individuali, dividi equamente il target del negozio
final storeTargets = _extractTargetS1S2(target.metrics, def.key);
targets = (
s1: staffCount > 0
? (storeTargets.s1 / staffCount).round()
: storeTargets.s1,
s2: staffCount > 0
? (storeTargets.s2 / staffCount).round()
: storeTargets.s2,
);
}
sCategories[def.key] = CategoryProgress.calculate(
key: def.key,
@@ -172,6 +197,48 @@ class TargetProgressService {
);
}
// Se ci sono addetti con operazioni che non compaiono in individualTargets, creiamo la loro scheda
for (final sId in staffCounts.keys) {
if (!staffProgressMap.containsKey(sId)) {
final sCounts = staffCounts[sId] ?? {};
final sCategories = <String, CategoryProgress>{};
for (final def in metricDefinitions) {
final actual = sCounts[def.key] ?? 0;
final storeTargets = _extractTargetS1S2(target.metrics, def.key);
final targets = (
s1: staffCount > 0
? (storeTargets.s1 / staffCount).round()
: storeTargets.s1,
s2: staffCount > 0
? (storeTargets.s2 / staffCount).round()
: storeTargets.s2,
);
sCategories[def.key] = CategoryProgress.calculate(
key: def.key,
label: def.label,
actual: actual,
s1: targets.s1,
s2: targets.s2,
elapsedDays: days.elapsed,
remainingDays: days.remaining,
totalDays: days.total,
);
}
staffProgressMap[sId] = TargetProgressModel(
targetId: target.id ?? '',
storeId: target.storeId,
staffId: sId,
totalWorkingDays: days.total,
elapsedWorkingDays: days.elapsed,
remainingWorkingDays: days.remaining,
categories: sCategories,
);
}
}
return TargetProgressModel(
targetId: target.id ?? '',
storeId: target.storeId,
@@ -179,6 +179,15 @@ class TargetProgressModel extends Equatable {
this.staffProgress = const {},
});
factory TargetProgressModel.empty() => const TargetProgressModel(
targetId: '',
totalWorkingDays: 0,
elapsedWorkingDays: 0,
remainingWorkingDays: 0,
categories: {},
staffProgress: {},
);
/// Somma di tutti i pezzi realizzati finora
int get totalActualPieces =>
categories.values.fold(0, (sum, c) => sum + c.actualPieces);
@@ -26,22 +26,32 @@ class TicketListCard extends StatelessWidget {
void _openFile({
required BuildContext context,
required AttachmentModel file,
List<AttachmentModel>? attachments,
int? initialIndex,
}) {
// 1. Catturiamo il BLoC dalla pagina corrente prima di navigare
final operationFilesBloc = context.read<AttachmentsBloc>();
final list = attachments ?? [file];
final index = initialIndex ?? (list.isNotEmpty ? list.indexOf(file) : 0);
Navigator.push(
context,
MaterialPageRoute(
builder: (viewerContext) => BlocProvider.value(
value: operationFilesBloc,
child: AttachmentViewerScreen(
attachment: file,
onRename: (newName) {
attachments: list,
initialIndex: index >= 0 ? index : 0,
onRenameAttachment: (targetFile, newName) {
// Spara l'evento al BLoC e lui farà il resto!
operationFilesBloc.add(RenameAttachmentEvent(file, newName));
operationFilesBloc.add(
RenameAttachmentEvent(targetFile, newName),
);
},
onDelete: () {
operationFilesBloc.add(DeleteSpecificAttachmentEvent(file));
onDeleteAttachment: (targetFile) {
operationFilesBloc.add(
DeleteSpecificAttachmentEvent(targetFile),
);
},
),
),
@@ -155,6 +165,8 @@ class TicketListCard extends StatelessWidget {
_openFile(
context: context,
file: attachments.first,
attachments: attachments,
initialIndex: 0,
);
} else {
// CASO 2: Più allegati. Mostriamo una BottomSheet fulminea per far scegliere all'utente.
@@ -188,6 +200,8 @@ class TicketListCard extends StatelessWidget {
_openFile(
context: context,
file: file,
attachments: attachments,
initialIndex: index,
); // Apre il viewer
},
);
+10 -10
View File
@@ -585,10 +585,10 @@ packages:
dependency: "direct main"
description:
name: intl
sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
sha256: "1ca20c894b1717686a2319b8548763d812bc0aabdac580420a44c5178c57a867"
url: "https://pub.dev"
source: hosted
version: "0.20.2"
version: "0.20.3"
jni:
dependency: transitive
description:
@@ -665,10 +665,10 @@ packages:
dependency: transitive
description:
name: matcher
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
sha256: "31bd099b47c10cd1aeb55146a2d46ce0277630ecef3f7dae54ad7873f36696cd"
url: "https://pub.dev"
source: hosted
version: "0.12.19"
version: "0.12.20"
material_color_utilities:
dependency: transitive
description:
@@ -681,10 +681,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "1741988757a65eb6b36abe716829688cf01910bbf91c34354ff7ec1c3de2b349"
sha256: "307249ce4ff29d58a18e97f6345f539382eb9c9c29ecda628900f31de0443dd9"
url: "https://pub.dev"
source: hosted
version: "1.18.0"
version: "1.19.0"
mime:
dependency: transitive
description:
@@ -1143,10 +1143,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "949a932224383300f01be9221c39180316445ecb8e7547f70a41a35bf421fb9e"
sha256: "2a122cbe059f8b610d3a5415f42e255b6c17b1f21eee1d960f31080237fb4f11"
url: "https://pub.dev"
source: hosted
version: "0.7.11"
version: "0.7.12"
typed_data:
dependency: transitive
description:
@@ -1287,10 +1287,10 @@ packages:
dependency: transitive
description:
name: vector_math
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
sha256: "92b9910f66ed1057fd4da7b040ae7c74cafacf885bdc81be496928d5049b032d"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.4.3"
vm_service:
dependency: transitive
description:
+1 -1
View File
@@ -1,7 +1,7 @@
name: flux
description: "Gestione attività negozio di telefonia"
publish_to: 'none'
version: 2.0.0+56
version: 2.0.4+60
environment:
sdk: ^3.11.3