This commit is contained in:
brontomark committed 2026-10-05 13:42:11 +02:00
1 parent 4f0fe7bab5
commit 19fc90b830
9 files changed
+168 -80

No files matched your search

@@ -27,13 +27,26 @@ class SharedModelSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final hasModel = modelId != null && modelId!.isNotEmpty;
final currentModelId = modelId;
final currentModelName = modelName;
final hasModelId = currentModelId != null && currentModelId.isNotEmpty;
final hasModelName = currentModelName != null && currentModelName.isNotEmpty;
final hasModel = hasModelId || hasModelName;
final String subtitleText;
if (hasModelName) {
subtitleText = currentModelName;
} else if (hasModelId) {
subtitleText = 'Modello selezionato';
} else {
subtitleText = 'Nessun modello selezionato';
}
return ListTile(
tileColor: backgroundColor,
title: Text(label),
subtitle: Text(
hasModel ? modelName! : 'Nessun modello selezionato',
subtitleText,
style: TextStyle(
color: hasModel ? null : Colors.grey,
fontWeight: hasModel ? FontWeight.bold : FontWeight.normal,
@@ -124,8 +137,12 @@ class SharedModelSection extends StatelessWidget {
);
if (newModel != null) {
// CHIAMIAMO LA CALLBACK!
onModelSelected(newModel.id, newModel.nameWithBrand);
final selectedId = newModel.id ?? '';
final selectedName =
newModel.nameWithBrand.isNotEmpty
? newModel.nameWithBrand
: newModel.name;
onModelSelected(selectedId, selectedName);
if (context.mounted) Navigator.pop(modalContext);
}
},
@@ -149,11 +166,12 @@ class SharedModelSection extends StatelessWidget {
),
),
onTap: () {
// CHIAMIAMO LA CALLBACK!
onModelSelected(
deviceModel.id!,
deviceModel.nameWithBrand,
);
final selectedId = deviceModel.id ?? '';
final selectedName =
deviceModel.nameWithBrand.isNotEmpty
? deviceModel.nameWithBrand
: deviceModel.name;
onModelSelected(selectedId, selectedName);
Navigator.pop(modalContext);
},
);
@@ -14,7 +14,9 @@ class DashboardStoreTicketListCubit
final TicketRepository _repository = GetIt.I.get<TicketRepository>();
final String? companyId;
final String? storeId;
StreamSubscription<void>? _subscription;
StreamSubscription<void>? _realtimeSubscription;
StreamSubscription<void>? _localSubscription;
Timer? _pollingTimer;
DashboardStoreTicketListCubit({
required this.companyId,
@@ -26,8 +28,16 @@ class DashboardStoreTicketListCubit
);
void stopListening() {
_subscription?.cancel();
_subscription = null;
_realtimeSubscription?.cancel();
_realtimeSubscription = null;
_localSubscription?.cancel();
_localSubscription = null;
_pollingTimer?.cancel();
_pollingTimer = null;
}
void refresh() {
_loadTicketsSilently();
}
void startListening() {
@@ -38,17 +48,28 @@ class DashboardStoreTicketListCubit
// Primo caricamento
_loadTicketsSilently();
// Inizio ascolto campanello
// 1. Ascolto notifiche locali di mutazione in memoria (reattività istantanea)
_localSubscription = _repository.onTicketsChanged.listen((_) {
_loadTicketsSilently();
});
// 2. Ascolto campanello Supabase Realtime (se attivo in DB)
try {
_subscription = _repository
.getLatestStoreTicketsStream(storeId: storeId!, limit: 10)
.listen((_) {
// Quando il campanello suona (qualcosa è cambiato a DB), ricarichiamo!
_loadTicketsSilently();
});
if (storeId != null && storeId!.isNotEmpty) {
_realtimeSubscription = _repository
.getLatestStoreTicketsStream(storeId: storeId!, limit: 10)
.listen((_) {
_loadTicketsSilently();
});
}
} on Exception catch (e) {
debugPrint(e.toString());
}
// 3. Polling di sicurezza ogni 30 secondi
_pollingTimer = Timer.periodic(const Duration(seconds: 30), (_) {
_loadTicketsSilently();
});
}
Future<void> _loadTicketsSilently() async {
@@ -8,6 +8,7 @@ import 'package:flux/features/operations/blocs/operation_details_form_cubit.dart
import 'package:flux/features/operations/blocs/operation_details_list_cubit.dart';
import 'package:flux/features/operations/models/operation_detail_model.dart';
import 'package:flux/features/operations/models/operation_type.dart';
import 'package:flux/features/master_data/products/models/model_model.dart';
class OperationDetailsSection extends StatelessWidget {
const OperationDetailsSection({super.key});
@@ -648,7 +649,15 @@ class _OperationDetailFormSheetState
onModelSelected: (id, name) {
context
.read<OperationDetailsFormCubit>()
.updateFields(modelId: id);
.updateFields(
modelId: id,
model: ModelModel(
id: id,
name: name,
nameWithBrand: name,
brandId: '',
),
);
},
),
const SizedBox(height: 16),
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flux/features/tickets/models/ticket_model.dart';
@@ -13,8 +14,19 @@ class TicketListCubit extends Cubit<TicketListState> {
.get<TrackingRepository>();
static const int _limit = 20; // Paginazione a blocchi di 20
StreamSubscription<void>? _ticketsSubscription;
TicketListCubit() : super(const TicketListState()) {
loadTickets(refresh: true);
_ticketsSubscription = _repository.onTicketsChanged.listen((_) {
loadTickets(refresh: true);
});
}
@override
Future<void> close() {
_ticketsSubscription?.cancel();
return super.close();
}
int _fetchId = 0;
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flux/core/blocs/session/session_cubit.dart';
import 'package:flux/core/enums_and_consts/consts.dart';
@@ -16,6 +17,17 @@ class TicketRepository {
static const String _tableName = Tables.tickets;
final StreamController<void> _ticketsChangedController =
StreamController<void>.broadcast();
Stream<void> get onTicketsChanged => _ticketsChangedController.stream;
void notifyTicketsChanged() {
if (!_ticketsChangedController.isClosed) {
_ticketsChangedController.add(null);
}
}
// --- RECUPERO PAGINATO CON FILTRI E JOIN DEI TICKET DI UNO STORE ---
Future<List<TicketModel>> fetchStoreTickets({
required int offset,
@@ -280,6 +292,7 @@ class TicketRepository {
.select()
.single();
notifyTicketsChanged();
return TicketModel.fromMap(response);
} catch (e) {
throw Exception('Errore nella creazione del ticket: $e');
@@ -300,6 +313,7 @@ class TicketRepository {
.select()
.single();
notifyTicketsChanged();
return TicketModel.fromMap(response);
} catch (e) {
throw Exception('Errore nell\'aggiornamento del ticket: $e');
@@ -313,6 +327,7 @@ class TicketRepository {
.from(_tableName)
.update({'ticket_status': TicketStatus.closed.value})
.inFilter('id', ticketIds);
notifyTicketsChanged();
} catch (e) {
throw Exception('Errore nella chiusura dei ticket: $e');
}
@@ -322,6 +337,7 @@ class TicketRepository {
Future<void> deleteTicket(String ticketId) async {
try {
await _supabase.from(_tableName).delete().eq('id', ticketId);
notifyTicketsChanged();
} catch (e) {
throw Exception('Errore nell\'eliminazione del ticket: $e');
}
+22 -18
View File
@@ -349,27 +349,31 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
}
void _deleteTicket(TicketModel ticket, {Color color = Colors.red}) {
final ticketFormCubit = context.read<TicketFormCubit>();
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Conferma Cancellazione'),
content: Text(
'Sei sicuro di voler cancellare il ticket "${ticket.referenceId}"? Questa azione è irreversibile.',
builder: (dialogContext) => BlocProvider.value(
value: ticketFormCubit,
child: AlertDialog(
title: const Text('Conferma Cancellazione'),
content: Text(
'Sei sicuro di voler cancellare il ticket "${ticket.referenceId}"? Questa azione è irreversibile.',
),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(),
child: const Text('Annulla'),
),
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: color),
onPressed: () {
ticketFormCubit.deleteTicket();
Navigator.of(dialogContext).pop(); // Chiude il dialog
},
child: const Text('Cancella Ticket'),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Annulla'),
),
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: color),
onPressed: () {
context.read<TicketFormCubit>().deleteTicket();
Navigator.of(context).pop(); // Chiude il dialog
},
child: const Text('Cancella Ticket'),
),
],
),
);
}
+1 -1
View File
@@ -1,4 +1,4 @@
platform :osx, '10.15'
platform :osx, '12.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
+46 -38
View File
@@ -5,33 +5,33 @@ PODS:
- FlutterMacOS
- file_selector_macos (0.0.1):
- FlutterMacOS
- Firebase/CoreOnly (12.15.0):
- FirebaseCore (~> 12.15.0)
- Firebase/Messaging (12.15.0):
- Firebase/CoreOnly (12.19.0):
- FirebaseCore (~> 12.19.0)
- Firebase/Messaging (12.19.0):
- Firebase/CoreOnly
- FirebaseMessaging (~> 12.15.0)
- firebase_core (4.11.0):
- Firebase/CoreOnly (~> 12.15.0)
- FirebaseMessaging (~> 12.19.0)
- firebase_core (4.15.0):
- Firebase/CoreOnly (~> 12.19.0)
- FlutterMacOS
- firebase_messaging (16.4.1):
- Firebase/CoreOnly (~> 12.15.0)
- Firebase/Messaging (~> 12.15.0)
- firebase_messaging (16.7.0):
- Firebase/CoreOnly (~> 12.19.0)
- Firebase/Messaging (~> 12.19.0)
- firebase_core
- FlutterMacOS
- FirebaseCore (12.15.0):
- FirebaseCoreInternal (~> 12.15.0)
- FirebaseCore (12.19.0):
- FirebaseCoreInternal (~> 12.19.0)
- GoogleUtilities/Environment (~> 8.1)
- GoogleUtilities/Logger (~> 8.1)
- FirebaseCoreInternal (12.15.0):
- FirebaseCoreInternal (12.19.0):
- "GoogleUtilities/NSData+zlib (~> 8.1)"
- FirebaseInstallations (12.15.0):
- FirebaseCore (~> 12.15.0)
- FirebaseInstallations (12.19.0):
- FirebaseCore (~> 12.19.0)
- GoogleUtilities/Environment (~> 8.1)
- GoogleUtilities/UserDefaults (~> 8.1)
- PromisesObjC (~> 2.4)
- FirebaseMessaging (12.15.0):
- FirebaseCore (~> 12.15.0)
- FirebaseInstallations (~> 12.15.0)
- FirebaseMessaging (12.19.0):
- FirebaseCore (~> 12.19.0)
- FirebaseInstallations (~> 12.19.0)
- GoogleDataTransport (~> 10.1)
- GoogleUtilities/AppDelegateSwizzler (~> 8.1)
- GoogleUtilities/Environment (~> 8.1)
@@ -42,28 +42,28 @@ PODS:
- GoogleDataTransport (10.1.1):
- nanopb (~> 3.30910.0)
- PromisesObjC (~> 2.4)
- GoogleUtilities/AppDelegateSwizzler (8.1.2):
- GoogleUtilities/AppDelegateSwizzler (8.1.4):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Privacy
- GoogleUtilities/Environment (8.1.2):
- GoogleUtilities/Environment (8.1.4):
- GoogleUtilities/Privacy
- GoogleUtilities/Logger (8.1.2):
- GoogleUtilities/Logger (8.1.4):
- GoogleUtilities/Environment
- GoogleUtilities/Privacy
- GoogleUtilities/Network (8.1.2):
- GoogleUtilities/Network (8.1.4):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Privacy
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (8.1.2)":
- "GoogleUtilities/NSData+zlib (8.1.4)":
- GoogleUtilities/Privacy
- GoogleUtilities/Privacy (8.1.2)
- GoogleUtilities/Reachability (8.1.2):
- GoogleUtilities/Privacy (8.1.4)
- GoogleUtilities/Reachability (8.1.4):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GoogleUtilities/UserDefaults (8.1.2):
- GoogleUtilities/UserDefaults (8.1.4):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- nanopb (3.30910.0):
@@ -73,7 +73,11 @@ PODS:
- nanopb/encode (3.30910.0)
- package_info_plus (0.0.1):
- FlutterMacOS
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- pdfx (1.0.0):
- Flutter
- FlutterMacOS
- printing (1.0.0):
- FlutterMacOS
@@ -92,7 +96,8 @@ DEPENDENCIES:
- firebase_messaging (from `Flutter/ephemeral/.symlinks/plugins/firebase_messaging/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
- pdfx (from `Flutter/ephemeral/.symlinks/plugins/pdfx/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- pdfx (from `Flutter/ephemeral/.symlinks/plugins/pdfx/darwin`)
- printing (from `Flutter/ephemeral/.symlinks/plugins/printing/macos`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
@@ -124,8 +129,10 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral
package_info_plus:
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
path_provider_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
pdfx:
:path: Flutter/ephemeral/.symlinks/plugins/pdfx/macos
:path: Flutter/ephemeral/.symlinks/plugins/pdfx/darwin
printing:
:path: Flutter/ephemeral/.symlinks/plugins/printing/macos
shared_preferences_foundation:
@@ -137,24 +144,25 @@ SPEC CHECKSUMS:
app_links: 05a6ec2341985eb05e9f97dc63f5837c39895c3f
file_picker: 7584aae6fa07a041af2b36a2655122d42f578c1a
file_selector_macos: 9e9e068e90ebee155097d00e89ae91edb2374db7
Firebase: a8539b633d474fbeb654c7043f9c1649e274045b
firebase_core: 4922bf7ac16c97fb67008a1a00842059b345b0d9
firebase_messaging: 6c506190a7499e67e644957961f86efe1ac1c3e3
FirebaseCore: 2e86a4ea1684d4381707069e4a6d89ac808e901e
FirebaseCoreInternal: 6ab6a02c94446c026d2cf35cf5383842ebaa4992
FirebaseInstallations: eb29ccbf64eaedf86fd5b2ccc7fabde567660b52
FirebaseMessaging: 40017d7bc8457ee295b0f41d480a80fdabc9994e
FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1
Firebase: 7ca191e43724142f79fae653547b3382c45413cc
firebase_core: 43e1937898a25c5d76bc3ac4e58539465c9f219d
firebase_messaging: cf6920ca401d6870c1095a15cec1d4b9ca92b89f
FirebaseCore: c990214798d7c568ad436a15ba7da25c7a278c9a
FirebaseCoreInternal: 656b1c2fd5a1c5976183dc54b73deda78fb26ee3
FirebaseInstallations: f70a49eed611f5602f373e40974b3b01556ac217
FirebaseMessaging: c15f48126adbe8b4d3238a5e1fa24bab3ad3e472
FlutterMacOS: c232990155153907050900a2e175c7773903ba4e
GoogleDataTransport: a24e58982ab3ba2f64d79613e027fe7f57e88539
GoogleUtilities: 766ace00c6b10d8148408f329d10c4f051931850
GoogleUtilities: db34c1c11c6f2eccb6fab2340cb8ceb1451299dc
nanopb: fad817b59e0457d11a5dfbde799381cd727c1275
package_info_plus: f0052d280d17aa382b932f399edf32507174e870
pdfx: 1e79f57f7a6ce2f4a4c30f21fa54d3dc82441b51
path_provider_foundation: bb55f6dbba17d0dccd6737fe6f7f34fbd0376880
pdfx: 824a9108791a81e400da7d1a903ab73668365072
printing: 7916ffaaede65713863e621de9a4742d9fa723b9
PromisesObjC: 752c3227f599e3467650e47ea36f433eeb10c273
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
url_launcher_macos: f87a979182d112f911de6820aefddaf56ee9fbfd
PODFILE CHECKSUM: 180da7a1dbc1d932db021ebc8007656e7c46dd99
PODFILE CHECKSUM: 1920c73e89a474dd2aac51211a579ac3e392c7fa
COCOAPODS: 1.17.0
+3 -3
View File
@@ -589,7 +589,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
@@ -671,7 +671,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
@@ -721,7 +721,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;