risolti diversi crash e aggiunta presa bollette
Build and Release FLUX (Multi-Platform) / build-linux (push) Failing after 3s
Build and Release FLUX (Multi-Platform) / build-windows (push) Canceled after 0s
Build and Release FLUX (Multi-Platform) / build-macos (push) Canceled after 0s
Build and Release FLUX (Multi-Platform) / build-web (push) Canceled after 1m1s
Build and Release FLUX (Multi-Platform) / build-linux (push) Failing after 3s
Build and Release FLUX (Multi-Platform) / build-windows (push) Canceled after 0s
Build and Release FLUX (Multi-Platform) / build-macos (push) Canceled after 0s
Build and Release FLUX (Multi-Platform) / build-web (push) Canceled after 1m1s
This commit is contained in:
1 parent
19fc90b830
commit
4d791d2213
23 files changed
+960
-177
No files matched your search
@@ -28,14 +28,19 @@ class SessionCubit extends Cubit<SessionState> {
|
||||
: super(const SessionState(status: SessionStatus.initial)) {
|
||||
initializeSession();
|
||||
// Possiamo metterci in ascolto dei cambiamenti di Auth (Login/Logout)
|
||||
_supabase.auth.onAuthStateChange.listen((data) {
|
||||
final AuthChangeEvent event = data.event;
|
||||
if (event == AuthChangeEvent.signedIn) {
|
||||
initializeSession();
|
||||
} else if (event == AuthChangeEvent.signedOut) {
|
||||
emit(const SessionState(status: SessionStatus.unauthenticated));
|
||||
}
|
||||
});
|
||||
_supabase.auth.onAuthStateChange.listen(
|
||||
(data) {
|
||||
final AuthChangeEvent event = data.event;
|
||||
if (event == AuthChangeEvent.signedIn) {
|
||||
initializeSession();
|
||||
} else if (event == AuthChangeEvent.signedOut) {
|
||||
emit(const SessionState(status: SessionStatus.unauthenticated));
|
||||
}
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
debugPrint('Auth state change error: $error');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> initializeSession() async {
|
||||
|
||||
@@ -264,7 +264,9 @@ class _AppMenuState extends State<AppMenu> {
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: isSelected ? theme.colorScheme.primary : null,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -277,11 +279,19 @@ class _AppMenuState extends State<AppMenu> {
|
||||
alpha: 0.4,
|
||||
),
|
||||
selected: isSelected,
|
||||
leading: Icon(icon, color: isSelected ? theme.colorScheme.primary : null),
|
||||
leading: Icon(
|
||||
icon,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.clip,
|
||||
@@ -328,7 +338,7 @@ class _AppMenuState extends State<AppMenu> {
|
||||
: FontWeight.normal,
|
||||
color: widget.currentPath == item.pathToCheck
|
||||
? theme.colorScheme.primary
|
||||
: null,
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -345,7 +355,9 @@ class _AppMenuState extends State<AppMenu> {
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: isSelected ? theme.colorScheme.primary : null,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -359,12 +371,17 @@ class _AppMenuState extends State<AppMenu> {
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
leading: Icon(
|
||||
icon,
|
||||
color: isSelected ? theme.colorScheme.primary : null,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
color: isSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.clip,
|
||||
@@ -390,7 +407,7 @@ class _AppMenuState extends State<AppMenu> {
|
||||
: FontWeight.normal,
|
||||
color: isSubSelected
|
||||
? theme.colorScheme.primary
|
||||
: theme.textTheme.bodyMedium?.color,
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.clip,
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'package:flux/features/customers/models/customer_model.dart';
|
||||
import 'package:flux/features/customers/ui/customer_detail_screen.dart';
|
||||
import 'package:flux/features/customers/ui/customer_form_screen.dart';
|
||||
import 'package:flux/features/customers/ui/customers_list_screen.dart';
|
||||
import 'package:flux/features/home/dashboard_expiring_contracts/bloc/dashboard_expiring_contracts_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_note_list/blocs/dashboard_note_list_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_store_operation_list/bloc/dashboard_store_operation_list_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_store_ticket_list/blocs/dashboard_store_ticket_list_cubit.dart';
|
||||
@@ -197,6 +198,12 @@ class AppRouter {
|
||||
staffId: sessionCubit.state.currentStaffMember?.id,
|
||||
),
|
||||
),
|
||||
BlocProvider<DashboardExpiringContractsCubit>(
|
||||
create: (context) => DashboardExpiringContractsCubit(
|
||||
companyId: sessionCubit.state.company?.id,
|
||||
storeId: sessionCubit.state.currentStore?.id,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: const HomeScreen(),
|
||||
);
|
||||
|
||||
+36
-12
@@ -104,11 +104,25 @@ ThemeData fluxDarkTheme = ThemeData(
|
||||
),
|
||||
),
|
||||
|
||||
drawerTheme: const DrawerThemeData(
|
||||
backgroundColor: FluxColors.darkSurface,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
),
|
||||
|
||||
expansionTileTheme: const ExpansionTileThemeData(
|
||||
iconColor: FluxColors.accentTurquoise,
|
||||
collapsedIconColor: FluxColors.darkTextSecondary,
|
||||
textColor: FluxColors.darkTextPrimary,
|
||||
collapsedTextColor: FluxColors.darkTextPrimary,
|
||||
),
|
||||
|
||||
listTileTheme: ListTileThemeData(
|
||||
// Definiamo la forma arrotondata (fondamentale per l'effetto moderno)
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
// Colore dell'icona (Turchese Flux)
|
||||
iconColor: FluxColors.accentTurquoise,
|
||||
selectedColor: FluxColors.primaryBlue,
|
||||
selectedTileColor: FluxColors.primaryBlue.withValues(alpha: 0.15),
|
||||
// Colore del testo
|
||||
titleTextStyle: GoogleFonts.poppins(
|
||||
color: FluxColors.darkTextPrimary,
|
||||
@@ -121,9 +135,6 @@ ThemeData fluxDarkTheme = ThemeData(
|
||||
),
|
||||
// Per far apparire la "manina" su Web/Desktop
|
||||
mouseCursor: WidgetStateProperty.all(SystemMouseCursors.click),
|
||||
|
||||
// NOTA: Se overlayColor non esiste, Flutter userà i colori
|
||||
// di default del tema (splashColor e hoverColor) definiti nel ThemeData generale.
|
||||
),
|
||||
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
@@ -189,26 +200,37 @@ ThemeData fluxLightTheme = ThemeData(
|
||||
),
|
||||
),
|
||||
|
||||
drawerTheme: const DrawerThemeData(
|
||||
backgroundColor: FluxColors.lightSurface,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
),
|
||||
|
||||
expansionTileTheme: const ExpansionTileThemeData(
|
||||
iconColor: FluxColors.accentTurquoise,
|
||||
collapsedIconColor: FluxColors.lightTextSecondary,
|
||||
textColor: FluxColors.lightTextPrimary,
|
||||
collapsedTextColor: FluxColors.lightTextPrimary,
|
||||
),
|
||||
|
||||
listTileTheme: ListTileThemeData(
|
||||
// Definiamo la forma arrotondata (fondamentale per l'effetto moderno)
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
// Colore dell'icona (Turchese Flux)
|
||||
iconColor: FluxColors.accentTurquoise,
|
||||
// Colore del testo
|
||||
selectedColor: FluxColors.primaryBlue,
|
||||
selectedTileColor: FluxColors.primaryBlue.withValues(alpha: 0.1),
|
||||
// Colore del testo per il tema chiaro
|
||||
titleTextStyle: GoogleFonts.poppins(
|
||||
color: FluxColors.darkTextPrimary,
|
||||
color: FluxColors.lightTextPrimary,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
subtitleTextStyle: GoogleFonts.poppins(
|
||||
color: FluxColors.darkTextSecondary,
|
||||
color: FluxColors.lightTextSecondary,
|
||||
fontSize: 13,
|
||||
),
|
||||
// Per far apparire la "manina" su Web/Desktop
|
||||
mouseCursor: WidgetStateProperty.all(SystemMouseCursors.click),
|
||||
|
||||
// NOTA: Se overlayColor non esiste, Flutter userà i colori
|
||||
// di default del tema (splashColor e hoverColor) definiti nel ThemeData generale.
|
||||
),
|
||||
|
||||
// Il pulsante principale rimane Blu Elettrico, molto visibile
|
||||
@@ -260,12 +282,14 @@ extension FluxThemeContext on BuildContext {
|
||||
// --- Testi (La parte mancante) ---
|
||||
// Mappiamo primaryText sul colore del titolo e secondaryText su quello del corpo
|
||||
Color get primaryText =>
|
||||
Theme.of(this).textTheme.titleLarge?.color ?? Colors.white;
|
||||
Theme.of(this).textTheme.titleLarge?.color ??
|
||||
Theme.of(this).colorScheme.onSurface;
|
||||
Color get secondaryText =>
|
||||
Theme.of(this).textTheme.bodyMedium?.color ?? Colors.grey;
|
||||
Theme.of(this).textTheme.bodyMedium?.color ??
|
||||
Theme.of(this).colorScheme.onSurfaceVariant;
|
||||
|
||||
// Opzionale: un colore ancora più tenue per suggerimenti o icone disabilitate
|
||||
Color get hintText =>
|
||||
Theme.of(this).textTheme.bodySmall?.color ??
|
||||
Colors.grey.withValues(alpha: 0.5);
|
||||
Theme.of(this).colorScheme.onSurface.withValues(alpha: 0.5);
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/features/home/dashboard_expiring_contracts/bloc/dashboard_expiring_contracts_state.dart';
|
||||
import 'package:flux/features/operations/data/operations_repository.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
class DashboardExpiringContractsCubit
|
||||
extends Cubit<DashboardExpiringContractsState> {
|
||||
final OperationsRepository _repository =
|
||||
GetIt.I.get<OperationsRepository>();
|
||||
final String? companyId;
|
||||
final String? storeId;
|
||||
StreamSubscription<void>? _operationsSubscription;
|
||||
Timer? _pollingTimer;
|
||||
|
||||
DashboardExpiringContractsCubit({
|
||||
required this.companyId,
|
||||
required this.storeId,
|
||||
}) : super(const DashboardExpiringContractsState());
|
||||
|
||||
void startListening() {
|
||||
emit(state.copyWith(status: DashboardExpiringContractsStatus.loading));
|
||||
stopListening();
|
||||
|
||||
_loadExpiringSilently();
|
||||
|
||||
_operationsSubscription = _repository.onOperationsChanged.listen((_) {
|
||||
_loadExpiringSilently();
|
||||
});
|
||||
|
||||
_pollingTimer = Timer.periodic(const Duration(seconds: 30), (_) {
|
||||
_loadExpiringSilently();
|
||||
});
|
||||
}
|
||||
|
||||
void stopListening() {
|
||||
_operationsSubscription?.cancel();
|
||||
_operationsSubscription = null;
|
||||
_pollingTimer?.cancel();
|
||||
_pollingTimer = null;
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
_loadExpiringSilently();
|
||||
}
|
||||
|
||||
void _loadExpiringSilently() async {
|
||||
try {
|
||||
if (companyId == null || companyId!.isEmpty) return;
|
||||
final expiringOps = await _repository.fetchExpiringOperations(
|
||||
companyId: companyId!,
|
||||
storeId: storeId,
|
||||
limit: 20,
|
||||
);
|
||||
if (isClosed) return;
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: DashboardExpiringContractsStatus.success,
|
||||
operations: expiringOps,
|
||||
error: null,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (isClosed) return;
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: DashboardExpiringContractsStatus.failure,
|
||||
error: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
stopListening();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
|
||||
enum DashboardExpiringContractsStatus { initial, loading, success, failure }
|
||||
|
||||
class DashboardExpiringContractsState extends Equatable {
|
||||
final DashboardExpiringContractsStatus status;
|
||||
final List<OperationModel> operations;
|
||||
final String? error;
|
||||
|
||||
const DashboardExpiringContractsState({
|
||||
this.status = DashboardExpiringContractsStatus.initial,
|
||||
this.operations = const [],
|
||||
this.error,
|
||||
});
|
||||
|
||||
DashboardExpiringContractsState copyWith({
|
||||
DashboardExpiringContractsStatus? status,
|
||||
List<OperationModel>? operations,
|
||||
String? error,
|
||||
}) {
|
||||
return DashboardExpiringContractsState(
|
||||
status: status ?? this.status,
|
||||
operations: operations ?? this.operations,
|
||||
error: error,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, operations, error];
|
||||
}
|
||||
+292
@@ -0,0 +1,292 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/routes/routes.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
import 'package:flux/features/home/dashboard_expiring_contracts/bloc/dashboard_expiring_contracts_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_expiring_contracts/bloc/dashboard_expiring_contracts_state.dart';
|
||||
import 'package:flux/features/operations/data/operations_repository.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class DashboardExpiringContractsCard extends StatelessWidget {
|
||||
const DashboardExpiringContractsCard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _ExpiringContractsCardContent();
|
||||
}
|
||||
}
|
||||
|
||||
class _ExpiringContractsCardContent extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
const color = Colors.orange;
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: BorderSide(color: theme.dividerColor.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () => context.pushNamed(Routes.operations),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// --- HEADER DELLA CARD ---
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.event_repeat_outlined,
|
||||
color: color,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context.l10n.homeExpiringContracts,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: context.primaryText,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// --- LISTA OPERAZIONI IN SCADENZA ---
|
||||
Expanded(
|
||||
child: BlocBuilder<DashboardExpiringContractsCubit,
|
||||
DashboardExpiringContractsState>(
|
||||
builder: (context, state) {
|
||||
if (state.status ==
|
||||
DashboardExpiringContractsStatus.loading ||
|
||||
state.status ==
|
||||
DashboardExpiringContractsStatus.initial) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.status ==
|
||||
DashboardExpiringContractsStatus.failure) {
|
||||
return Center(
|
||||
child: Text(
|
||||
"Errore di caricamento",
|
||||
style: TextStyle(color: theme.colorScheme.error),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.operations.isEmpty) {
|
||||
return Center(
|
||||
child: Text(
|
||||
"Nessun contratto in scadenza.",
|
||||
style: TextStyle(
|
||||
color: context.secondaryText,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.separated(
|
||||
itemCount: state.operations.length,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
height: 1,
|
||||
color: theme.dividerColor.withValues(alpha: 0.3),
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final operation = state.operations[index];
|
||||
final earliestExp =
|
||||
OperationsRepository.getEarliestExpiration(operation);
|
||||
final phone = operation.customer?.phoneNumber;
|
||||
|
||||
return InkWell(
|
||||
onTap: () => context.pushNamed(
|
||||
Routes.operationForm,
|
||||
extra: (createdBy: null, operation: operation),
|
||||
pathParameters: {'id': operation.id!},
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Nome Cliente & note
|
||||
Expanded(
|
||||
flex: 5,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
operation.customer?.name ??
|
||||
'Cliente sconosciuto',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.primaryText,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (operation.attachments.isNotEmpty) ...[
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.attach_file,
|
||||
size: 14,
|
||||
color: context.secondaryText,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
if (phone != null && phone.isNotEmpty)
|
||||
Text(
|
||||
phone,
|
||||
style: TextStyle(
|
||||
color: context.secondaryText,
|
||||
fontSize: 11,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// Badge Tipo / Subtipo
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: _buildBadges(operation),
|
||||
),
|
||||
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// Data Scadenza Badge
|
||||
_buildExpiryBadge(context, earliestExp),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBadges(OperationModel op) {
|
||||
final labels = op.details
|
||||
.map((d) {
|
||||
final tLabel = d.type?.shortLabel ?? d.type?.value ?? '';
|
||||
final sub = d.subType?.trim() ?? '';
|
||||
if (sub.isNotEmpty) return '$tLabel: $sub';
|
||||
return tLabel;
|
||||
})
|
||||
.where((l) => l.isNotEmpty)
|
||||
.toList();
|
||||
|
||||
if (labels.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: labels
|
||||
.map(
|
||||
(label) => Container(
|
||||
margin: const EdgeInsets.only(right: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.amber.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(
|
||||
color: Colors.amber.withValues(alpha: 0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
color: Colors.amber,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildExpiryBadge(BuildContext context, DateTime? expiry) {
|
||||
if (expiry == null) return const SizedBox.shrink();
|
||||
|
||||
final now = DateTime.now();
|
||||
final differenceDays = expiry.difference(now).inDays;
|
||||
final isExpired = expiry.isBefore(now);
|
||||
|
||||
Color badgeColor = Colors.orange;
|
||||
String text = "${expiry.day}/${expiry.month}/${expiry.year}";
|
||||
|
||||
if (isExpired) {
|
||||
badgeColor = Colors.red;
|
||||
text = "Scaduto ($text)";
|
||||
} else if (differenceDays <= 30) {
|
||||
badgeColor = Colors.redAccent;
|
||||
text = "Tra $differenceDays gg";
|
||||
} else if (differenceDays <= 60) {
|
||||
badgeColor = Colors.orange;
|
||||
text = "Tra ~${(differenceDays / 30).round()} mesi";
|
||||
} else {
|
||||
badgeColor = Colors.blue;
|
||||
text = "${expiry.day}/${expiry.month}/${expiry.year}";
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: badgeColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: badgeColor.withValues(alpha: 0.4)),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: badgeColor,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -35,10 +35,15 @@ class DashboardNoteListCubit extends Cubit<DashboardNoteListState> {
|
||||
try {
|
||||
_subscription = _repository
|
||||
.notesStream(companyId: companyId!, currentStaffId: staffId!)
|
||||
.listen((_) {
|
||||
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
|
||||
_loadNotesSilently();
|
||||
});
|
||||
.listen(
|
||||
(_) {
|
||||
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
|
||||
_loadNotesSilently();
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
debugPrint('Dashboard notes stream error: $error');
|
||||
},
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
debugPrint(e.toString());
|
||||
}
|
||||
|
||||
+8
-3
@@ -58,9 +58,14 @@ class DashboardStoreTicketListCubit
|
||||
if (storeId != null && storeId!.isNotEmpty) {
|
||||
_realtimeSubscription = _repository
|
||||
.getLatestStoreTicketsStream(storeId: storeId!, limit: 10)
|
||||
.listen((_) {
|
||||
_loadTicketsSilently();
|
||||
});
|
||||
.listen(
|
||||
(_) {
|
||||
_loadTicketsSilently();
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
debugPrint('Realtime store tickets stream error: $error');
|
||||
},
|
||||
);
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
debugPrint(e.toString());
|
||||
|
||||
@@ -4,15 +4,25 @@ import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/routes/routes.dart';
|
||||
import 'package:flux/features/home/dashboard_target_progress/blocs/dashboard_target_progress_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_target_progress/blocs/dashboard_target_progress_state.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/targets/models/target_progress_model.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class DashboardTargetHeroCard extends StatelessWidget {
|
||||
class DashboardTargetHeroCard extends StatefulWidget {
|
||||
const DashboardTargetHeroCard({super.key});
|
||||
|
||||
@override
|
||||
State<DashboardTargetHeroCard> createState() =>
|
||||
_DashboardTargetHeroCardState();
|
||||
}
|
||||
|
||||
class _DashboardTargetHeroCardState extends State<DashboardTargetHeroCard> {
|
||||
bool _showAllCategories = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DashboardTargetProgressCubit, DashboardTargetProgressState>(
|
||||
return BlocBuilder<DashboardTargetProgressCubit,
|
||||
DashboardTargetProgressState>(
|
||||
builder: (context, state) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
@@ -149,17 +159,33 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
final target = state.target!;
|
||||
final staffMember =
|
||||
context.watch<SessionCubit>().state.currentStaffMember;
|
||||
final currentStore =
|
||||
context.watch<SessionCubit>().state.currentStore;
|
||||
final staffName = staffMember?.name ?? 'Ospite';
|
||||
final staffId = staffMember?.id;
|
||||
|
||||
final staffProgress = state.getEffectiveStaffProgress(
|
||||
staffId: staffId,
|
||||
staffName: staffName,
|
||||
);
|
||||
final displayCategories = staffProgress.categories.values
|
||||
final isManager = staffMember?.systemRole == SystemRole.manager ||
|
||||
staffMember?.systemRole == SystemRole.admin;
|
||||
|
||||
final activeProgress = isManager
|
||||
? progress
|
||||
: state.getEffectiveStaffProgress(
|
||||
staffId: staffId,
|
||||
staffName: staffName,
|
||||
);
|
||||
|
||||
final displayCategories = activeProgress.categories.values
|
||||
.where((c) => c.hasTarget)
|
||||
.toList();
|
||||
|
||||
final inLineCategories =
|
||||
displayCategories.where((c) => !c.isBehind).toList();
|
||||
final behindCategories =
|
||||
displayCategories.where((c) => c.isBehind).toList();
|
||||
|
||||
final categoriesToDisplay =
|
||||
_showAllCategories ? displayCategories : behindCategories;
|
||||
|
||||
final remainingDays = progress.remainingWorkingDays;
|
||||
|
||||
return LayoutBuilder(
|
||||
@@ -236,7 +262,7 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
Text(
|
||||
'IL TUO RITMO PER OGGI',
|
||||
isManager ? 'RITMO NEGOZIO PER OGGI' : 'IL TUO RITMO PER OGGI',
|
||||
style: TextStyle(
|
||||
fontSize: isCompact ? 10.5 : 11,
|
||||
fontWeight: FontWeight.w800,
|
||||
@@ -271,9 +297,11 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
staffMember != null
|
||||
? 'Cosa portare a casa oggi, $staffName'
|
||||
: 'Obiettivi personali per oggi',
|
||||
isManager
|
||||
? 'Obiettivi di ${currentStore?.name ?? "Negozio"} per oggi'
|
||||
: (staffMember != null
|
||||
? 'Cosa portare a casa oggi, $staffName'
|
||||
: 'Obiettivi personali per oggi'),
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: isCompact ? 15 : 17,
|
||||
@@ -328,31 +356,63 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: displayCategories.length,
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent:
|
||||
constraints.maxWidth > 700 ? 260 : 200,
|
||||
mainAxisExtent: 168,
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final category = displayCategories[index];
|
||||
final storeCategory = progress.categories[category.key];
|
||||
return _buildCategoryDailyPacingCard(
|
||||
theme,
|
||||
category,
|
||||
storeCategory: storeCategory,
|
||||
);
|
||||
},
|
||||
else ...[
|
||||
// Banner sintetico per gli elementi in linea
|
||||
if (inLineCategories.isNotEmpty)
|
||||
_buildInLineSummaryBanner(
|
||||
theme,
|
||||
inLineCategories: inLineCategories,
|
||||
totalCategoriesCount: displayCategories.length,
|
||||
hasBehindCategories: behindCategories.isNotEmpty,
|
||||
isManager: isManager,
|
||||
),
|
||||
),
|
||||
|
||||
if (categoriesToDisplay.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: categoriesToDisplay.length,
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent:
|
||||
constraints.maxWidth > 700 ? 260 : 200,
|
||||
mainAxisExtent: 168,
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final category = categoriesToDisplay[index];
|
||||
final storeCategory =
|
||||
progress.categories[category.key];
|
||||
return _buildCategoryDailyPacingCard(
|
||||
theme,
|
||||
category,
|
||||
storeCategory: storeCategory,
|
||||
isManager: isManager,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
else if (behindCategories.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 8,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Tutti gli obiettivi sono in linea col ritmo! 🎉',
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: 14),
|
||||
|
||||
@@ -468,6 +528,7 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
ThemeData theme,
|
||||
CategoryProgress category, {
|
||||
CategoryProgress? storeCategory,
|
||||
bool isManager = false,
|
||||
}) {
|
||||
final pacingTheme = PacingTheme.of(category.status);
|
||||
final isAchieved = category.isAchieved;
|
||||
@@ -571,7 +632,9 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
)
|
||||
else
|
||||
Text(
|
||||
'Obiettivo personale centrato!',
|
||||
isManager
|
||||
? 'Obiettivo negozio centrato!'
|
||||
: 'Obiettivo personale centrato!',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -632,12 +695,14 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// Footer: Avanzamento personale e ritmo
|
||||
// Footer: Avanzamento e ritmo
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'I tuoi: ${category.actualPieces} / ${category.targetS1}',
|
||||
isManager
|
||||
? 'Negozio: ${category.actualPieces} / ${category.targetS1}'
|
||||
: 'I tuoi: ${category.actualPieces} / ${category.targetS1}',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -666,7 +731,7 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
color: pacingTheme.primary,
|
||||
),
|
||||
),
|
||||
if (storeCategory != null && storeCategory.targetS1 > 0) ...[
|
||||
if (!isManager && storeCategory != null && storeCategory.targetS1 > 0) ...[
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -695,6 +760,117 @@ class DashboardTargetHeroCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInLineSummaryBanner(
|
||||
ThemeData theme, {
|
||||
required List<CategoryProgress> inLineCategories,
|
||||
required int totalCategoriesCount,
|
||||
required bool hasBehindCategories,
|
||||
bool isManager = false,
|
||||
}) {
|
||||
final isDark = theme.brightness == Brightness.dark;
|
||||
final bannerBg = isDark
|
||||
? const Color(0xFF064E3B).withValues(alpha: 0.35)
|
||||
: const Color(0xFFF0FDF4);
|
||||
final bannerBorder = isDark
|
||||
? const Color(0xFF047857).withValues(alpha: 0.5)
|
||||
: const Color(0xFFBBF7D0);
|
||||
final bannerIconColor =
|
||||
isDark ? const Color(0xFF34D399) : const Color(0xFF16A34A);
|
||||
final bannerTextColor =
|
||||
isDark ? const Color(0xFF6EE7B7) : const Color(0xFF15803D);
|
||||
final bannerSubtextColor =
|
||||
isDark ? const Color(0xFFA7F3D0) : const Color(0xFF166534);
|
||||
|
||||
final subjectText = isManager ? 'Il negozio è in linea' : 'Sei in linea';
|
||||
|
||||
final titleText = !hasBehindCategories
|
||||
? '$subjectText con tutti i ${inLineCategories.length} obiettivi! 🎉'
|
||||
: '$subjectText con ${inLineCategories.length} ${inLineCategories.length == 1 ? 'obiettivo' : 'obiettivi'} su $totalCategoriesCount';
|
||||
|
||||
final categoryNames = inLineCategories.map((c) => c.label).join(' • ');
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: bannerBg,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: bannerBorder, width: 1),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.check_circle_rounded,
|
||||
color: bannerIconColor,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
titleText,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: bannerTextColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
categoryNames,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: bannerSubtextColor,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_showAllCategories = !_showAllCategories;
|
||||
});
|
||||
},
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_showAllCategories
|
||||
? 'Nascondi'
|
||||
: 'Mostra tutti (${inLineCategories.length})',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: bannerTextColor,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
_showAllCategories
|
||||
? Icons.keyboard_arrow_up
|
||||
: Icons.keyboard_arrow_down,
|
||||
size: 16,
|
||||
color: bannerTextColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMiniBadge({
|
||||
required String label,
|
||||
required Color color,
|
||||
|
||||
@@ -29,12 +29,15 @@ class DashboardTaskListCubit extends Cubit<DashboardTaskListState> {
|
||||
|
||||
// Inizio ascolto campanello
|
||||
try {
|
||||
_tasksSubscription = _repository.watchCompanyTasks(companyId!).listen((
|
||||
_,
|
||||
) {
|
||||
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
|
||||
_loadTasksSilently();
|
||||
});
|
||||
_tasksSubscription = _repository.watchCompanyTasks(companyId!).listen(
|
||||
(_) {
|
||||
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
|
||||
_loadTasksSilently();
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
debugPrint('Dashboard tasks stream error: $error');
|
||||
},
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
debugPrint(e.toString());
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:flux/core/routes/routes.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
import 'package:flux/core/widgets/staff_selector_modal.dart';
|
||||
import 'package:flux/features/home/dashboard_expiring_contracts/bloc/dashboard_expiring_contracts_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_expiring_contracts/ui/dashboard_expiring_contracts_card.dart';
|
||||
import 'package:flux/features/home/dashboard_note_list/blocs/dashboard_note_list_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_store_operation_list/bloc/dashboard_store_operation_list_cubit.dart';
|
||||
import 'package:flux/features/home/dashboard_store_ticket_list/blocs/dashboard_store_ticket_list_cubit.dart';
|
||||
@@ -76,6 +78,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
context.read<DashboardStoreTicketListCubit>().stopListening();
|
||||
context.read<DashboardNoteListCubit>().stopListening();
|
||||
context.read<DashboardTargetProgressCubit>().stopListening();
|
||||
context.read<DashboardExpiringContractsCubit>().stopListening();
|
||||
}
|
||||
|
||||
void _startListeners() {
|
||||
@@ -90,6 +93,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
context.read<DashboardStoreTicketListCubit>().startListening();
|
||||
context.read<DashboardNoteListCubit>().startListening();
|
||||
context.read<DashboardTargetProgressCubit>().startListening();
|
||||
context.read<DashboardExpiringContractsCubit>().startListening();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -168,12 +172,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
delegate: SliverChildListDelegate([
|
||||
DashboardStoreOperationListCard(),
|
||||
DashboardStoreTicketListCard(),
|
||||
_buildDashboardWidget(
|
||||
title: context.l10n.homeExpiringContracts,
|
||||
icon: Icons.assignment_late_outlined,
|
||||
color: Colors.orange,
|
||||
context: context,
|
||||
),
|
||||
DashboardExpiringContractsCard(),
|
||||
DashboardNoteListCard(),
|
||||
DashboardTaskListCard(),
|
||||
]),
|
||||
@@ -339,82 +338,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDashboardWidget({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
required IconData icon,
|
||||
required Color color,
|
||||
VoidCallback? onTap,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(color: theme.dividerColor.withValues(alpha: 0.5)),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: context.primaryText,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.more_vert,
|
||||
size: 20,
|
||||
color: context.secondaryText,
|
||||
),
|
||||
onPressed: () {},
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Text(
|
||||
context.l10n.commonComingSoon,
|
||||
style: TextStyle(
|
||||
color: context.secondaryText.withValues(alpha: 0.7),
|
||||
fontStyle: FontStyle.italic,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showStoreSelector(BuildContext context, ThemeData theme) {
|
||||
showModalBottomSheet(
|
||||
|
||||
@@ -37,10 +37,15 @@ class NotesCubit extends Cubit<NotesState> {
|
||||
try {
|
||||
_subscription = _repository
|
||||
.notesStream(companyId: companyId!, currentStaffId: staffId!)
|
||||
.listen((_) {
|
||||
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
|
||||
_loadNotesSilently();
|
||||
});
|
||||
.listen(
|
||||
(_) {
|
||||
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
|
||||
_loadNotesSilently();
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
debugPrint('Notes stream error: $error');
|
||||
},
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
debugPrint(e.toString());
|
||||
}
|
||||
|
||||
@@ -251,4 +251,67 @@ class OperationsRepository {
|
||||
throw Exception('Errore nel salvataggio dell\'operazione: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<OperationModel>> fetchExpiringOperations({
|
||||
required String companyId,
|
||||
String? storeId,
|
||||
int limit = 20,
|
||||
}) async {
|
||||
try {
|
||||
var query = _supabase
|
||||
.from(Tables.operations)
|
||||
.select('''
|
||||
*,
|
||||
${Tables.customers}(*),
|
||||
${Tables.stores}(*),
|
||||
${Tables.staffMembers}(*),
|
||||
${Tables.attachments}(*),
|
||||
${Tables.operationDetails}!inner(
|
||||
*,
|
||||
${Tables.providers}(*),
|
||||
${Tables.models}(*)
|
||||
)
|
||||
''')
|
||||
.eq('company_id', companyId)
|
||||
.not('${Tables.operationDetails}.expiration_date', 'is', null);
|
||||
|
||||
if (storeId != null && storeId.isNotEmpty) {
|
||||
query = query.or('store_id.eq.$storeId,store_id.is.null');
|
||||
}
|
||||
|
||||
final response = await query
|
||||
.order('created_at', ascending: false)
|
||||
.limit(limit);
|
||||
|
||||
final List<OperationModel> operations = (response as List)
|
||||
.map((map) => OperationModel.fromMap(map as Map<String, dynamic>))
|
||||
.toList();
|
||||
|
||||
operations.sort((a, b) {
|
||||
final aExp = getEarliestExpiration(a);
|
||||
final bExp = getEarliestExpiration(b);
|
||||
if (aExp == null && bExp == null) return 0;
|
||||
if (aExp == null) return 1;
|
||||
if (bExp == null) return -1;
|
||||
return aExp.compareTo(bExp);
|
||||
});
|
||||
|
||||
return operations;
|
||||
} catch (e) {
|
||||
debugPrint('Errore nel recupero contratti/operazioni in scadenza: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
static DateTime? getEarliestExpiration(OperationModel op) {
|
||||
DateTime? earliest;
|
||||
for (final d in op.details) {
|
||||
if (d.expirationDate != null) {
|
||||
if (earliest == null || d.expirationDate!.isBefore(earliest)) {
|
||||
earliest = d.expirationDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
return earliest;
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,13 @@ enum OperationType {
|
||||
icon: Icons.business_center_outlined,
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
ricontatto(
|
||||
value: 'Ricontatto',
|
||||
label: 'Ricontatto / Scadenza',
|
||||
shortLabel: 'Ricontatto',
|
||||
icon: Icons.event_repeat_outlined,
|
||||
color: Colors.amber,
|
||||
),
|
||||
altro(
|
||||
value: 'Altro',
|
||||
label: 'Altro Servizio',
|
||||
@@ -139,3 +146,14 @@ class EnergySubtypes {
|
||||
|
||||
static const List<String> all = [luce, gas, dual];
|
||||
}
|
||||
|
||||
/// Sottotipi standard per Ricontatti / Bollette in scadenza
|
||||
class RicontattoSubtypes {
|
||||
static const String luce = 'Luce';
|
||||
static const String gas = 'Gas';
|
||||
static const String dual = 'Luce e Gas';
|
||||
static const String telefonia = 'Telefonia';
|
||||
static const String altro = 'Altro';
|
||||
|
||||
static const List<String> all = [luce, gas, dual, telefonia, altro];
|
||||
}
|
||||
@@ -707,6 +707,52 @@ class _OperationDetailFormSheetState
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// Scenario Ricontatto / Bolletta in scadenza
|
||||
if (currentType == OperationType.ricontatto) ...[
|
||||
const Text(
|
||||
'Tipo di Fornitura / Servizio da Ricontattare',
|
||||
style: TextStyle(fontWeight: FontWeight.w600, fontSize: 13),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8.0,
|
||||
runSpacing: 8.0,
|
||||
children: RicontattoSubtypes.all.map((sub) {
|
||||
final isSelected = detail.subType?.toLowerCase() == sub.toLowerCase();
|
||||
return ChoiceChip(
|
||||
avatar: sub == RicontattoSubtypes.luce
|
||||
? const Icon(Icons.bolt_outlined, size: 16)
|
||||
: (sub == RicontattoSubtypes.gas
|
||||
? const Icon(Icons.local_fire_department_outlined, size: 16)
|
||||
: (sub == RicontattoSubtypes.telefonia
|
||||
? const Icon(Icons.phone_outlined, size: 16)
|
||||
: null)),
|
||||
label: Text(sub),
|
||||
selected: isSelected,
|
||||
onSelected: (selected) {
|
||||
final newVal = selected ? sub : null;
|
||||
_subtypeController.text = newVal ?? '';
|
||||
context.read<OperationDetailsFormCubit>().updateFields(subType: newVal);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _descriptionController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Gestore Attuale / Note Offerta',
|
||||
hintText: 'Es. Enel Luce 0.15€/kWh, scadenza vincolo tra 10 mesi...',
|
||||
),
|
||||
onChanged: (val) {
|
||||
context
|
||||
.read<OperationDetailsFormCubit>()
|
||||
.updateFields(description: val);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// Scenario Altro (Testo libero)
|
||||
if (currentType == OperationType.altro) ...[
|
||||
TextFormField(
|
||||
@@ -728,6 +774,7 @@ class _OperationDetailFormSheetState
|
||||
OperationType.energy,
|
||||
OperationType.fin,
|
||||
OperationType.entertainment,
|
||||
OperationType.ricontatto,
|
||||
OperationType.altro,
|
||||
].contains(currentType)) ...[
|
||||
_buildDurationQuickPicks(context),
|
||||
|
||||
@@ -279,6 +279,8 @@ class TargetFormCubit extends Cubit<TargetFormState> {
|
||||
energiaTim2: calc(m.energiaTim2),
|
||||
energiaAltri1: calc(m.energiaAltri1),
|
||||
energiaAltri2: calc(m.energiaAltri2),
|
||||
ricontatti1: calc(m.ricontatti1),
|
||||
ricontatti2: calc(m.ricontatti2),
|
||||
);
|
||||
|
||||
return it.copyWith(metrics: distributedMetrics);
|
||||
|
||||
@@ -28,6 +28,7 @@ class TargetProgressService {
|
||||
(key: 'telepass', label: 'Telepass'),
|
||||
(key: 'energiaTim', label: 'Energia TIM'),
|
||||
(key: 'energiaAltri', label: 'Energia Non TIM'),
|
||||
(key: 'ricontatti', label: 'Ricontatti / Bollette'),
|
||||
];
|
||||
|
||||
/// Calcola l'avanzamento completo per un target (di negozio e per ciascun addetto)
|
||||
@@ -290,6 +291,8 @@ class TargetProgressService {
|
||||
return 'energiaTim';
|
||||
}
|
||||
return 'energiaAltri';
|
||||
case OperationType.ricontatto:
|
||||
return 'ricontatti';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -324,6 +327,8 @@ class TargetProgressService {
|
||||
return (s1: m.energiaTim1, s2: m.energiaTim2);
|
||||
case 'energiaAltri':
|
||||
return (s1: m.energiaAltri1, s2: m.energiaAltri2);
|
||||
case 'ricontatti':
|
||||
return (s1: m.ricontatti1, s2: m.ricontatti2);
|
||||
default:
|
||||
return (s1: 0, s2: 0);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ class TargetMetrics extends Equatable {
|
||||
final int energiaTim2;
|
||||
final int energiaAltri1;
|
||||
final int energiaAltri2;
|
||||
final int ricontatti1;
|
||||
final int ricontatti2;
|
||||
|
||||
// Getter di compatibilità con codice pregresso
|
||||
int get energiaTim => energiaTim1;
|
||||
@@ -61,6 +63,8 @@ class TargetMetrics extends Equatable {
|
||||
int? energiaAltri1,
|
||||
int? energiaAltri,
|
||||
this.energiaAltri2 = 0,
|
||||
this.ricontatti1 = 0,
|
||||
this.ricontatti2 = 0,
|
||||
}) : energiaTim1 = energiaTim1 ?? energiaTim ?? 0,
|
||||
energiaAltri1 = energiaAltri1 ?? energiaAltri ?? 0;
|
||||
|
||||
@@ -92,6 +96,8 @@ class TargetMetrics extends Equatable {
|
||||
energiaTim2,
|
||||
energiaAltri1,
|
||||
energiaAltri2,
|
||||
ricontatti1,
|
||||
ricontatti2,
|
||||
];
|
||||
|
||||
TargetMetrics copyWith({
|
||||
@@ -123,6 +129,8 @@ class TargetMetrics extends Equatable {
|
||||
int? energiaAltri1,
|
||||
int? energiaAltri,
|
||||
int? energiaAltri2,
|
||||
int? ricontatti1,
|
||||
int? ricontatti2,
|
||||
}) {
|
||||
return TargetMetrics(
|
||||
mnp1: mnp1 ?? this.mnp1,
|
||||
@@ -151,6 +159,8 @@ class TargetMetrics extends Equatable {
|
||||
energiaTim2: energiaTim2 ?? this.energiaTim2,
|
||||
energiaAltri1: energiaAltri1 ?? energiaAltri ?? this.energiaAltri1,
|
||||
energiaAltri2: energiaAltri2 ?? this.energiaAltri2,
|
||||
ricontatti1: ricontatti1 ?? this.ricontatti1,
|
||||
ricontatti2: ricontatti2 ?? this.ricontatti2,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -196,6 +206,10 @@ class TargetMetrics extends Equatable {
|
||||
energiaAltri2: (map['energia_altri_2'] as num?)?.toInt() ??
|
||||
(map['Energia_altri_2'] as num?)?.toInt() ??
|
||||
0,
|
||||
ricontatti1: (map['ricontatti_1'] as num?)?.toInt() ??
|
||||
(map['ricontatti'] as num?)?.toInt() ??
|
||||
0,
|
||||
ricontatti2: (map['ricontatti_2'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -229,10 +243,13 @@ class TargetMetrics extends Equatable {
|
||||
'energia_altri_1': energiaAltri1,
|
||||
'energia_altri_2': energiaAltri2,
|
||||
'energia_altri': energiaAltri1,
|
||||
'ricontatti_1': ricontatti1,
|
||||
'ricontatti_2': ricontatti2,
|
||||
'ricontatti': ricontatti1,
|
||||
};
|
||||
}
|
||||
|
||||
/// Somma totale di tutti i target del Livello 1 (inclusa energia)
|
||||
/// Somma totale di tutti i target del Livello 1 (inclusa energia e ricontatti)
|
||||
int get totalLevel1 =>
|
||||
mnp1 +
|
||||
unica1 +
|
||||
@@ -246,9 +263,10 @@ class TargetMetrics extends Equatable {
|
||||
al1 +
|
||||
telepass1 +
|
||||
energiaTim1 +
|
||||
energiaAltri1;
|
||||
energiaAltri1 +
|
||||
ricontatti1;
|
||||
|
||||
/// Somma totale di tutti i target del Livello 2 (inclusa energia)
|
||||
/// Somma totale di tutti i target del Livello 2 (inclusa energia e ricontatti)
|
||||
int get totalLevel2 =>
|
||||
mnp2 +
|
||||
unica2 +
|
||||
@@ -262,7 +280,8 @@ class TargetMetrics extends Equatable {
|
||||
al2 +
|
||||
telepass2 +
|
||||
energiaTim2 +
|
||||
energiaAltri2;
|
||||
energiaAltri2 +
|
||||
ricontatti2;
|
||||
|
||||
/// Numero di categorie con almeno una soglia impostata (> 0)
|
||||
int get activeMetricsCount {
|
||||
@@ -280,6 +299,7 @@ class TargetMetrics extends Equatable {
|
||||
if (telepass1 > 0 || telepass2 > 0) count++;
|
||||
if (energiaTim1 > 0 || energiaTim2 > 0) count++;
|
||||
if (energiaAltri1 > 0 || energiaAltri2 > 0) count++;
|
||||
if (ricontatti1 > 0 || ricontatti2 > 0) count++;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
@@ -578,6 +578,24 @@ class _TargetFormScreenState extends State<TargetFormScreen>
|
||||
metrics.copyWith(energiaAltri2: v),
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
_buildMetricInputRow(
|
||||
theme: theme,
|
||||
icon: Icons.event_repeat_outlined,
|
||||
color: Colors.amber,
|
||||
label: 'Ricontatti / Bollette',
|
||||
val1: metrics.ricontatti1,
|
||||
val2: metrics.ricontatti2,
|
||||
showLevel2: true,
|
||||
onChanged1:
|
||||
(v) => cubit.updateStoreMetrics(
|
||||
metrics.copyWith(ricontatti1: v),
|
||||
),
|
||||
onChanged2:
|
||||
(v) => cubit.updateStoreMetrics(
|
||||
metrics.copyWith(ricontatti2: v),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -952,6 +970,21 @@ class _TargetFormScreenState extends State<TargetFormScreen>
|
||||
it.metrics.copyWith(energiaAltri2: v),
|
||||
),
|
||||
),
|
||||
_buildStaffMetricRow(
|
||||
theme: theme,
|
||||
label: 'Ricontatti / Bollette',
|
||||
val1: it.metrics.ricontatti1,
|
||||
val2: it.metrics.ricontatti2,
|
||||
showLevel2: true,
|
||||
onChanged1: (v) => cubit.updateIndividualMetrics(
|
||||
it.staffId,
|
||||
it.metrics.copyWith(ricontatti1: v),
|
||||
),
|
||||
onChanged2: (v) => cubit.updateIndividualMetrics(
|
||||
it.staffId,
|
||||
it.metrics.copyWith(ricontatti2: v),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/features/tasks/data/task_repository.dart';
|
||||
@@ -27,12 +28,15 @@ class TaskListCubit extends Cubit<TaskListState> {
|
||||
_loadTasksSilently();
|
||||
|
||||
// Ci mettiamo in ascolto del campanello del Repository
|
||||
_taskSubscription = _repository.watchCompanyTasks(currentCompanyId).listen((
|
||||
_,
|
||||
) {
|
||||
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
|
||||
_loadTasksSilently();
|
||||
});
|
||||
_taskSubscription = _repository.watchCompanyTasks(currentCompanyId).listen(
|
||||
(_) {
|
||||
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
|
||||
_loadTasksSilently();
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
debugPrint('Task list stream error: $error');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> loadTasks() async {
|
||||
|
||||
+20
-3
@@ -37,6 +37,18 @@ import 'package:flux/core/utils/auto_update_service.dart';
|
||||
String? initialRecoveryFragment;
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Scudo di Sicurezza Globale: Previene crash dell'app per eccezioni asincrone di rete/WebSocket non gestite
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
FlutterError.presentError(details);
|
||||
debugPrint('FlutterError caught: ${details.exception}');
|
||||
};
|
||||
|
||||
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
|
||||
debugPrint('PlatformDispatcher error caught: $error');
|
||||
return true; // Contrassegna l'errore come gestito ed evita il crash dell'app
|
||||
};
|
||||
|
||||
await dotenv.load(fileName: ".env");
|
||||
await init();
|
||||
final initialUri = Uri.base;
|
||||
@@ -288,9 +300,14 @@ class _GlobalUpdateCheckerState extends State<GlobalUpdateChecker>
|
||||
_versionSubscription = GetIt.I<SupabaseClient>()
|
||||
.from('app_config')
|
||||
.stream(primaryKey: ['id'])
|
||||
.listen((_) {
|
||||
_checkVersion();
|
||||
});
|
||||
.listen(
|
||||
(_) {
|
||||
_checkVersion();
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
debugPrint('Realtime version check stream error: $error');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _stopRealtimeVersionCheck() {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
name: flux
|
||||
description: "Gestione attività negozio di telefonia"
|
||||
publish_to: 'none'
|
||||
version: 2.0.12+68
|
||||
version: 2.0.13+69
|
||||
|
||||
environment:
|
||||
sdk: ^3.11.3
|
||||
|
||||
Reference in new issue
Block a user