pulizie completate
This commit is contained in:
@@ -6,12 +6,11 @@ import 'package:flux/core/data/core_repository.dart';
|
|||||||
import 'package:flux/core/layout/app_shell.dart';
|
import 'package:flux/core/layout/app_shell.dart';
|
||||||
import 'package:flux/core/utils/extensions.dart';
|
import 'package:flux/core/utils/extensions.dart';
|
||||||
import 'package:flux/core/widgets/set_password_screen.dart';
|
import 'package:flux/core/widgets/set_password_screen.dart';
|
||||||
|
import 'package:flux/core/widgets/shared_forms/shared_mobile_upload_screen.dart';
|
||||||
import 'package:flux/features/auth/ui/auth_screen.dart';
|
import 'package:flux/features/auth/ui/auth_screen.dart';
|
||||||
import 'package:flux/features/customers/blocs/customer_files_bloc.dart';
|
|
||||||
import 'package:flux/features/customers/blocs/customers_cubit.dart';
|
import 'package:flux/features/customers/blocs/customers_cubit.dart';
|
||||||
import 'package:flux/features/customers/models/customer_model.dart';
|
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_detail_screen.dart';
|
||||||
import 'package:flux/features/customers/ui/customer_mobile_upload_screen.dart';
|
|
||||||
import 'package:flux/features/customers/ui/customers_content.dart';
|
import 'package:flux/features/customers/ui/customers_content.dart';
|
||||||
import 'package:flux/features/home/ui/home_screen.dart';
|
import 'package:flux/features/home/ui/home_screen.dart';
|
||||||
import 'package:flux/features/master_data/master_data_hub_content.dart';
|
import 'package:flux/features/master_data/master_data_hub_content.dart';
|
||||||
@@ -27,7 +26,6 @@ import 'package:flux/features/onboarding/ui/onboarding_screen.dart';
|
|||||||
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||||
import 'package:flux/features/operations/models/operation_model.dart';
|
import 'package:flux/features/operations/models/operation_model.dart';
|
||||||
import 'package:flux/features/operations/ui/operation_form_screen.dart';
|
import 'package:flux/features/operations/ui/operation_form_screen.dart';
|
||||||
import 'package:flux/features/operations/ui/operation_mobile_upload_screen.dart';
|
|
||||||
import 'package:flux/features/operations/ui/operations_screen.dart';
|
import 'package:flux/features/operations/ui/operations_screen.dart';
|
||||||
import 'package:flux/features/tickets/blocs/ticket_list_cubit.dart';
|
import 'package:flux/features/tickets/blocs/ticket_list_cubit.dart';
|
||||||
import 'package:flux/features/tickets/ui/ticket_list_screen.dart';
|
import 'package:flux/features/tickets/ui/ticket_list_screen.dart';
|
||||||
@@ -164,7 +162,10 @@ class AppRouter {
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final customer = state.extra as CustomerModel;
|
final customer = state.extra as CustomerModel;
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CustomerFilesBloc(customer.id!),
|
create: (context) => AttachmentsBloc(
|
||||||
|
parentType: AttachmentParentType.customer,
|
||||||
|
parentId: customer.id,
|
||||||
|
),
|
||||||
child: CustomerDetailScreen(customer: customer),
|
child: CustomerDetailScreen(customer: customer),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -175,10 +176,12 @@ class AppRouter {
|
|||||||
final customerId = state.pathParameters['id']!;
|
final customerId = state.pathParameters['id']!;
|
||||||
final customerName = state.uri.queryParameters['name'] ?? 'Cliente';
|
final customerName = state.uri.queryParameters['name'] ?? 'Cliente';
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CustomerFilesBloc(customerId),
|
create: (context) => AttachmentsBloc(
|
||||||
child: CustomerMobileUploadScreen(
|
parentType: AttachmentParentType.customer,
|
||||||
customerId: customerId,
|
parentId: customerId,
|
||||||
customerName: customerName,
|
),
|
||||||
|
child: SharedMobileUploadScreen(
|
||||||
|
title: 'Aggiungi allegati al cliente $customerName',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -237,9 +240,8 @@ class AppRouter {
|
|||||||
parentId: operationId,
|
parentId: operationId,
|
||||||
parentType: AttachmentParentType.operation,
|
parentType: AttachmentParentType.operation,
|
||||||
),
|
),
|
||||||
child: OperationMobileUploadScreen(
|
child: SharedMobileUploadScreen(
|
||||||
operationId: operationId,
|
title: 'Aggiungi allegati alla pratica $operationName',
|
||||||
operationName: operationName,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,27 +1,21 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
|
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||||
|
|
||||||
class OperationMobileUploadScreen extends StatefulWidget {
|
class SharedMobileUploadScreen extends StatefulWidget {
|
||||||
final String operationId;
|
final String title;
|
||||||
final String operationName;
|
|
||||||
|
|
||||||
const OperationMobileUploadScreen({
|
const SharedMobileUploadScreen({super.key, required this.title});
|
||||||
super.key,
|
|
||||||
required this.operationId,
|
|
||||||
required this.operationName,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<OperationMobileUploadScreen> createState() =>
|
State<SharedMobileUploadScreen> createState() =>
|
||||||
_OperationMobileUploadScreenState();
|
_SharedMobileUploadScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _OperationMobileUploadScreenState
|
class _SharedMobileUploadScreenState extends State<SharedMobileUploadScreen> {
|
||||||
extends State<OperationMobileUploadScreen> {
|
|
||||||
// 1. LA NOSTRA STAGING AREA (Il "Carrello")
|
// 1. LA NOSTRA STAGING AREA (Il "Carrello")
|
||||||
final List<PlatformFile> _stagedFiles = [];
|
final List<PlatformFile> _stagedFiles = [];
|
||||||
|
|
||||||
@@ -56,7 +50,8 @@ class _OperationMobileUploadScreenState
|
|||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("Upload Pratica:\n${widget.operationName}"),
|
title: Text("Upload: ${widget.title}"),
|
||||||
|
// Togliamo la freccia indietro se stiamo caricando per evitare disastri
|
||||||
automaticallyImplyLeading: !_isUploading,
|
automaticallyImplyLeading: !_isUploading,
|
||||||
),
|
),
|
||||||
body: Stack(
|
body: Stack(
|
||||||
@@ -109,8 +104,7 @@ class _OperationMobileUploadScreenState
|
|||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
gridDelegate:
|
gridDelegate:
|
||||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount:
|
crossAxisCount: 3, // 3 colonne stile galleria
|
||||||
3, // 3 colonne come la galleria dell'iPhone
|
|
||||||
crossAxisSpacing: 12,
|
crossAxisSpacing: 12,
|
||||||
mainAxisSpacing: 12,
|
mainAxisSpacing: 12,
|
||||||
),
|
),
|
||||||
@@ -136,10 +130,17 @@ class _OperationMobileUploadScreenState
|
|||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: isImg
|
child: isImg
|
||||||
? Image.file(
|
? (file.bytes != null
|
||||||
File(file.path!),
|
// Se abbiamo i bytes (es. scatto da fotocamera) usiamo quelli (a prova di Web!)
|
||||||
fit: BoxFit.cover,
|
? Image.memory(
|
||||||
)
|
file.bytes!,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
)
|
||||||
|
// Altrimenti andiamo di file fisico
|
||||||
|
: Image.file(
|
||||||
|
File(file.path!),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
))
|
||||||
: const Column(
|
: const Column(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment:
|
||||||
MainAxisAlignment.center,
|
MainAxisAlignment.center,
|
||||||
@@ -227,9 +228,10 @@ class _OperationMobileUploadScreenState
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
// --- OVERLAY DI CARICAMENTO (Impedisce tap multipli) ---
|
// --- OVERLAY DI CARICAMENTO ---
|
||||||
if (_isUploading)
|
if (_isUploading)
|
||||||
Container(
|
Container(
|
||||||
|
// Usa il metodo non deprecato che hai giustamente suggerito!
|
||||||
color: Colors.black.withValues(alpha: 0.5),
|
color: Colors.black.withValues(alpha: 0.5),
|
||||||
child: const Center(
|
child: const Center(
|
||||||
child: Card(
|
child: Card(
|
||||||
@@ -264,7 +266,7 @@ class _OperationMobileUploadScreenState
|
|||||||
imageQuality: 80,
|
imageQuality: 80,
|
||||||
);
|
);
|
||||||
if (photo != null) {
|
if (photo != null) {
|
||||||
final photoBytes = await photo.readAsBytes(); // Sicuro anche per Web!
|
final photoBytes = await photo.readAsBytes();
|
||||||
final photoSize = await photo.length();
|
final photoSize = await photo.length();
|
||||||
|
|
||||||
final platformFile = PlatformFile(
|
final platformFile = PlatformFile(
|
||||||
@@ -274,13 +276,12 @@ class _OperationMobileUploadScreenState
|
|||||||
bytes: photoBytes, // I bytes ci salvano la vita su Supabase!
|
bytes: photoBytes, // I bytes ci salvano la vita su Supabase!
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
_stagedFiles.add(platformFile); // Unifichiamo tutto in un dart:io File
|
_stagedFiles.add(platformFile);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleFilePicker() async {
|
Future<void> _handleFilePicker() async {
|
||||||
// allowMultiple: true permette di pescare 5 foto dalla galleria in un colpo solo!
|
|
||||||
final result = await FilePicker.pickFiles(allowMultiple: true);
|
final result = await FilePicker.pickFiles(allowMultiple: true);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -293,11 +294,9 @@ class _OperationMobileUploadScreenState
|
|||||||
void _submitAllFiles() {
|
void _submitAllFiles() {
|
||||||
setState(() => _isUploading = true);
|
setState(() => _isUploading = true);
|
||||||
|
|
||||||
// Diciamo al BLoC di caricare tutti i file.
|
// Lanciamo l'evento del nostro nuovo AttachmentsBloc Agnostico!
|
||||||
// Usiamo il tuo evento esistente per ogni file (il BLoC li metterà in coda)
|
context.read<AttachmentsBloc>().add(
|
||||||
final bloc = context.read<AttachmentsBloc>();
|
UploadAttachmentsEvent(pickedFiles: _stagedFiles),
|
||||||
bloc.add(UploadAttachmentsEvent(pickedFiles: _stagedFiles));
|
);
|
||||||
|
|
||||||
// N.B: Il Navigator.pop() viene chiamato dal BlocListener in alto quando lo stato diventa "success"!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
165
lib/core/widgets/shared_forms/shared_model_section.dart
Normal file
165
lib/core/widgets/shared_forms/shared_model_section.dart
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flux/features/master_data/products/blocs/product_cubit.dart';
|
||||||
|
import 'package:flux/features/master_data/products/ui/quick_product_dialog.dart';
|
||||||
|
|
||||||
|
class SharedModelSection extends StatelessWidget {
|
||||||
|
final String? modelId;
|
||||||
|
final String? modelName;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
// Usiamo una callback che passa direttamente ID e Nome
|
||||||
|
// così non dobbiamo preoccuparci di importare la classe esatta del modello ovunque
|
||||||
|
final void Function(String id, String name) onModelSelected;
|
||||||
|
|
||||||
|
const SharedModelSection({
|
||||||
|
super.key,
|
||||||
|
required this.modelId,
|
||||||
|
required this.modelName,
|
||||||
|
required this.onModelSelected,
|
||||||
|
this.label = 'Seleziona Modello',
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final hasModel = modelId != null && modelId!.isNotEmpty;
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
title: Text(label),
|
||||||
|
subtitle: Text(
|
||||||
|
hasModel ? modelName! : 'Nessun modello selezionato',
|
||||||
|
style: TextStyle(
|
||||||
|
color: hasModel ? null : Colors.grey,
|
||||||
|
fontWeight: hasModel ? FontWeight.bold : FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
trailing: const Icon(Icons.arrow_drop_down),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
side: BorderSide(color: theme.dividerColor),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
onTap: () => _showModelModal(context),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showModelModal(BuildContext context) {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
isScrollControlled: true,
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||||
|
),
|
||||||
|
builder: (modalContext) {
|
||||||
|
return DraggableScrollableSheet(
|
||||||
|
initialChildSize: 0.6,
|
||||||
|
minChildSize: 0.4,
|
||||||
|
maxChildSize: 0.9,
|
||||||
|
expand: false,
|
||||||
|
builder: (_, scrollController) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Seleziona Modello',
|
||||||
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.close),
|
||||||
|
onPressed: () => Navigator.pop(modalContext),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
child: TextField(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Cerca modello (es. iPhone 15...)',
|
||||||
|
prefixIcon: const Icon(Icons.search),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onChanged: (query) =>
|
||||||
|
context.read<ProductsCubit>().searchModels(query),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: ElevatedButton.icon(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
minimumSize: const Size.fromHeight(48),
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
label: const Text('Aggiungi Modello al Volo'),
|
||||||
|
onPressed: () async {
|
||||||
|
// Leggiamo i brand dal Cubit per passarli alla dialog
|
||||||
|
final existingBrands = context
|
||||||
|
.read<ProductsCubit>()
|
||||||
|
.state
|
||||||
|
.brands;
|
||||||
|
|
||||||
|
final newModel = await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return BlocProvider.value(
|
||||||
|
value: context.read<ProductsCubit>(),
|
||||||
|
child: QuickProductDialog(
|
||||||
|
existingBrands: existingBrands,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (newModel != null) {
|
||||||
|
// CHIAMIAMO LA CALLBACK!
|
||||||
|
onModelSelected(newModel.id, newModel.nameWithBrand);
|
||||||
|
if (context.mounted) Navigator.pop(modalContext);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
Expanded(
|
||||||
|
child: BlocBuilder<ProductsCubit, ProductState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return ListView.builder(
|
||||||
|
controller: scrollController,
|
||||||
|
itemCount: state.models.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final deviceModel = state.models[index];
|
||||||
|
return ListTile(
|
||||||
|
leading: const Icon(Icons.devices),
|
||||||
|
title: Text(
|
||||||
|
deviceModel.nameWithBrand,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
// CHIAMIAMO LA CALLBACK!
|
||||||
|
onModelSelected(
|
||||||
|
deviceModel.id!,
|
||||||
|
deviceModel.nameWithBrand,
|
||||||
|
);
|
||||||
|
Navigator.pop(modalContext);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:flux/features/attachments/models/attachment_model.dart';
|
|
||||||
import 'package:flux/features/customers/data/customer_repository.dart';
|
|
||||||
import 'package:get_it/get_it.dart';
|
|
||||||
|
|
||||||
part 'customer_files_events.dart';
|
|
||||||
part 'customer_files_state.dart';
|
|
||||||
|
|
||||||
class CustomerFilesBloc extends Bloc<CustomerFilesEvent, CustomerFilesState> {
|
|
||||||
final CustomerRepository _repository = GetIt.I<CustomerRepository>();
|
|
||||||
final String customerId;
|
|
||||||
CustomerFilesBloc(this.customerId)
|
|
||||||
: super(const CustomerFilesState(status: CustomerFilesStatus.initial)) {
|
|
||||||
on<LoadCustomerFilesEvent>(_loadCustomerFiles);
|
|
||||||
on<UploadCustomerFileEvent>(_uploadCustomerFile);
|
|
||||||
on<UploadMultipleCustomerFilesEvent>(_uploadMultipleCustomerFiles);
|
|
||||||
on<DeleteCustomerFilesEvent>(_deleteCustomerFiles);
|
|
||||||
on<ToggleCustomerFileSelectionEvent>(_toggleCustomerFileSelection);
|
|
||||||
}
|
|
||||||
void _loadCustomerFiles(
|
|
||||||
LoadCustomerFilesEvent event,
|
|
||||||
Emitter<CustomerFilesState> emit,
|
|
||||||
) async {
|
|
||||||
await emit.forEach<List<AttachmentModel>>(
|
|
||||||
_repository.getCustomerFilesStream(customerId),
|
|
||||||
onData: (customerFiles) => CustomerFilesState(
|
|
||||||
status: CustomerFilesStatus.success,
|
|
||||||
customerFiles: customerFiles,
|
|
||||||
),
|
|
||||||
onError: (error, stackTrace) => CustomerFilesState(
|
|
||||||
status: CustomerFilesStatus.failure,
|
|
||||||
error: error.toString(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _uploadCustomerFile(
|
|
||||||
UploadCustomerFileEvent event,
|
|
||||||
Emitter<CustomerFilesState> emit,
|
|
||||||
) async {
|
|
||||||
emit(state.copyWith(status: CustomerFilesStatus.uploading));
|
|
||||||
if (event.pickedFile != null) {
|
|
||||||
try {
|
|
||||||
await _repository.uploadAndRegisterFile(
|
|
||||||
customerId: customerId,
|
|
||||||
pickedFile: event.pickedFile!,
|
|
||||||
);
|
|
||||||
emit(state.copyWith(status: CustomerFilesStatus.success));
|
|
||||||
} catch (e) {
|
|
||||||
emit(
|
|
||||||
state.copyWith(
|
|
||||||
status: CustomerFilesStatus.failure,
|
|
||||||
error: e.toString(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FutureOr<void> _uploadMultipleCustomerFiles(
|
|
||||||
UploadMultipleCustomerFilesEvent event,
|
|
||||||
Emitter<CustomerFilesState> emit,
|
|
||||||
) async {
|
|
||||||
if (event.files.isEmpty) {
|
|
||||||
emit(
|
|
||||||
state.copyWith(
|
|
||||||
status: CustomerFilesStatus.failure,
|
|
||||||
error: "Nessun file selezionato",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emit(state.copyWith(status: CustomerFilesStatus.uploading, error: null));
|
|
||||||
try {
|
|
||||||
// 2. Creiamo una lista di "Promesse" (Futures) per il repository
|
|
||||||
final List<Future<void>> uploadTasks = [];
|
|
||||||
for (var file in event.files) {
|
|
||||||
// Aggiungiamo il task alla lista, ma NON usiamo await qui dentro!
|
|
||||||
uploadTasks.add(
|
|
||||||
_repository.uploadAndRegisterFile(
|
|
||||||
customerId: customerId,
|
|
||||||
pickedFile: file,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// 3. ESECUZIONE PARALLELA!
|
|
||||||
// Aspettiamo che tutti i file siano caricati contemporaneamente.
|
|
||||||
await Future.wait(uploadTasks);
|
|
||||||
// 4. GRAN FINALE: Tutto caricato, emettiamo il success!
|
|
||||||
emit(state.copyWith(status: CustomerFilesStatus.success));
|
|
||||||
} catch (e) {
|
|
||||||
// Se anche un solo file fallisce, catturiamo l'errore
|
|
||||||
emit(
|
|
||||||
state.copyWith(
|
|
||||||
status: CustomerFilesStatus.failure,
|
|
||||||
error: "Errore durante l'upload multiplo: $e",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _deleteCustomerFiles(
|
|
||||||
DeleteCustomerFilesEvent event,
|
|
||||||
Emitter<CustomerFilesState> emit,
|
|
||||||
) async {
|
|
||||||
emit(state.copyWith(status: CustomerFilesStatus.loading));
|
|
||||||
try {
|
|
||||||
await _repository.deleteDocuments(state.selectedFiles);
|
|
||||||
emit(
|
|
||||||
state.copyWith(status: CustomerFilesStatus.success, selectedFiles: []),
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
emit(
|
|
||||||
state.copyWith(
|
|
||||||
status: CustomerFilesStatus.failure,
|
|
||||||
error: e.toString(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _toggleCustomerFileSelection(
|
|
||||||
ToggleCustomerFileSelectionEvent event,
|
|
||||||
Emitter<CustomerFilesState> emit,
|
|
||||||
) {
|
|
||||||
List<AttachmentModel> selectedFiles = List.from(state.selectedFiles);
|
|
||||||
if (selectedFiles.contains(event.file)) {
|
|
||||||
selectedFiles.remove(event.file);
|
|
||||||
} else {
|
|
||||||
selectedFiles.add(event.file);
|
|
||||||
}
|
|
||||||
emit(state.copyWith(selectedFiles: selectedFiles));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
part of 'customer_files_bloc.dart';
|
|
||||||
|
|
||||||
abstract class CustomerFilesEvent extends Equatable {
|
|
||||||
const CustomerFilesEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoadCustomerFilesEvent extends CustomerFilesEvent {}
|
|
||||||
|
|
||||||
class UploadCustomerFileEvent extends CustomerFilesEvent {
|
|
||||||
final PlatformFile? pickedFile;
|
|
||||||
final File? photo;
|
|
||||||
const UploadCustomerFileEvent({this.pickedFile, this.photo});
|
|
||||||
}
|
|
||||||
|
|
||||||
class UploadMultipleCustomerFilesEvent extends CustomerFilesEvent {
|
|
||||||
final List<PlatformFile> files;
|
|
||||||
const UploadMultipleCustomerFilesEvent(this.files);
|
|
||||||
@override
|
|
||||||
List<Object> get props => [files];
|
|
||||||
}
|
|
||||||
|
|
||||||
class DeleteCustomerFilesEvent extends CustomerFilesEvent {}
|
|
||||||
|
|
||||||
class ToggleCustomerFileSelectionEvent extends CustomerFilesEvent {
|
|
||||||
final AttachmentModel file;
|
|
||||||
const ToggleCustomerFileSelectionEvent(this.file);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
part of 'customer_files_bloc.dart';
|
|
||||||
|
|
||||||
enum CustomerFilesStatus { initial, loading, uploading, success, failure }
|
|
||||||
|
|
||||||
class CustomerFilesState extends Equatable {
|
|
||||||
const CustomerFilesState({
|
|
||||||
required this.status,
|
|
||||||
this.error,
|
|
||||||
this.customerFiles = const [],
|
|
||||||
this.selectedFiles = const [],
|
|
||||||
});
|
|
||||||
|
|
||||||
final CustomerFilesStatus status;
|
|
||||||
final String? error;
|
|
||||||
final List<AttachmentModel> customerFiles;
|
|
||||||
final List<AttachmentModel> selectedFiles;
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [status, error, customerFiles, selectedFiles];
|
|
||||||
|
|
||||||
CustomerFilesState copyWith({
|
|
||||||
CustomerFilesStatus? status,
|
|
||||||
String? error,
|
|
||||||
List<AttachmentModel>? customerFiles,
|
|
||||||
List<AttachmentModel>? selectedFiles,
|
|
||||||
}) {
|
|
||||||
return CustomerFilesState(
|
|
||||||
status: status ?? this.status,
|
|
||||||
error: error,
|
|
||||||
customerFiles: customerFiles ?? this.customerFiles,
|
|
||||||
selectedFiles: selectedFiles ?? this.selectedFiles,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,8 +6,8 @@ import 'package:flux/core/theme/theme.dart';
|
|||||||
import 'package:flux/core/widgets/image_viewer_widget.dart';
|
import 'package:flux/core/widgets/image_viewer_widget.dart';
|
||||||
import 'package:flux/core/widgets/pdf_viewer_widget.dart';
|
import 'package:flux/core/widgets/pdf_viewer_widget.dart';
|
||||||
import 'package:flux/core/widgets/qr_upload_dialog.dart';
|
import 'package:flux/core/widgets/qr_upload_dialog.dart';
|
||||||
|
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||||
import 'package:flux/features/attachments/models/attachment_model.dart';
|
import 'package:flux/features/attachments/models/attachment_model.dart';
|
||||||
import 'package:flux/features/customers/blocs/customer_files_bloc.dart';
|
|
||||||
import 'package:flux/features/customers/models/customer_model.dart';
|
import 'package:flux/features/customers/models/customer_model.dart';
|
||||||
|
|
||||||
class CustomerDetailScreen extends StatefulWidget {
|
class CustomerDetailScreen extends StatefulWidget {
|
||||||
@@ -26,11 +26,13 @@ class _CustomerDetailScreenState extends State<CustomerDetailScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _loadFiles() {
|
void _loadFiles() {
|
||||||
context.read<CustomerFilesBloc>().add(LoadCustomerFilesEvent());
|
context.read<AttachmentsBloc>().add(
|
||||||
|
LoadAttachmentsEvent(parentId: widget.customer.id),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _pickAndUpload() async {
|
Future<void> _pickAndUpload() async {
|
||||||
CustomerFilesBloc customerFilesBloc = context.read<CustomerFilesBloc>();
|
AttachmentsBloc attachmentsBloc = context.read<AttachmentsBloc>();
|
||||||
|
|
||||||
// Chiamata statica pulita
|
// Chiamata statica pulita
|
||||||
FilePickerResult? result = await FilePicker.pickFiles(
|
FilePickerResult? result = await FilePicker.pickFiles(
|
||||||
@@ -40,17 +42,13 @@ class _CustomerDetailScreenState extends State<CustomerDetailScreen> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
for (var pickedFile in result.files) {
|
try {
|
||||||
try {
|
attachmentsBloc.add(UploadAttachmentsEvent(pickedFiles: result.files));
|
||||||
customerFilesBloc.add(
|
} catch (e) {
|
||||||
UploadCustomerFileEvent(pickedFile: pickedFile),
|
if (mounted) {
|
||||||
);
|
ScaffoldMessenger.of(
|
||||||
} catch (e) {
|
context,
|
||||||
if (mounted) {
|
).showSnackBar(SnackBar(content: Text("$e")));
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text("Errore upload ${pickedFile.name}: $e")),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,7 +141,7 @@ class _CustomerDetailScreenState extends State<CustomerDetailScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDocumentSection() {
|
Widget _buildDocumentSection() {
|
||||||
return BlocBuilder<CustomerFilesBloc, CustomerFilesState>(
|
return BlocBuilder<AttachmentsBloc, AttachmentsState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -213,9 +211,9 @@ class _CustomerDetailScreenState extends State<CustomerDetailScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
if (state.status == CustomerFilesStatus.loading)
|
if (state.status == AttachmentsStatus.loading)
|
||||||
const Center(child: CircularProgressIndicator())
|
const Center(child: CircularProgressIndicator())
|
||||||
else if (state.customerFiles.isEmpty)
|
else if (state.allFiles.isEmpty)
|
||||||
const Center(child: Text("Nessun documento presente"))
|
const Center(child: Text("Nessun documento presente"))
|
||||||
else
|
else
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -226,9 +224,9 @@ class _CustomerDetailScreenState extends State<CustomerDetailScreen> {
|
|||||||
crossAxisSpacing: 16,
|
crossAxisSpacing: 16,
|
||||||
childAspectRatio: 1.2,
|
childAspectRatio: 1.2,
|
||||||
),
|
),
|
||||||
itemCount: state.customerFiles.length,
|
itemCount: state.allFiles.length,
|
||||||
itemBuilder: (context, index) =>
|
itemBuilder: (context, index) =>
|
||||||
_FileCard(file: state.customerFiles[index], state: state),
|
_FileCard(file: state.allFiles[index], state: state),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -268,14 +266,14 @@ class _CustomerDetailScreenState extends State<CustomerDetailScreen> {
|
|||||||
|
|
||||||
class _FileCard extends StatelessWidget {
|
class _FileCard extends StatelessWidget {
|
||||||
final AttachmentModel file;
|
final AttachmentModel file;
|
||||||
final CustomerFilesState state;
|
final AttachmentsState state;
|
||||||
const _FileCard({required this.file, required this.state});
|
const _FileCard({required this.file, required this.state});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => context.read<CustomerFilesBloc>().add(
|
onTap: () => context.read<AttachmentsBloc>().add(
|
||||||
ToggleCustomerFileSelectionEvent(file),
|
ToggleAttachmentSelectionEvent(file),
|
||||||
),
|
),
|
||||||
onDoubleTap: () => _handleDoubleClickOnFile(context, file),
|
onDoubleTap: () => _handleDoubleClickOnFile(context, file),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
|
|||||||
@@ -1,304 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:image_picker/image_picker.dart';
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
|
||||||
import 'package:flux/features/customers/blocs/customer_files_bloc.dart';
|
|
||||||
|
|
||||||
class CustomerMobileUploadScreen extends StatefulWidget {
|
|
||||||
final String customerId;
|
|
||||||
final String customerName;
|
|
||||||
|
|
||||||
const CustomerMobileUploadScreen({
|
|
||||||
super.key,
|
|
||||||
required this.customerId,
|
|
||||||
required this.customerName,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<CustomerMobileUploadScreen> createState() =>
|
|
||||||
_CustomerMobileUploadScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CustomerMobileUploadScreenState
|
|
||||||
extends State<CustomerMobileUploadScreen> {
|
|
||||||
// 1. LA NOSTRA STAGING AREA (Il "Carrello")
|
|
||||||
final List<PlatformFile> _stagedFiles = [];
|
|
||||||
|
|
||||||
// 2. STATO DI CARICAMENTO GLOBALE
|
|
||||||
bool _isUploading = false;
|
|
||||||
|
|
||||||
// Funzione magica per capire se è un'immagine o un PDF dall'estensione
|
|
||||||
bool _isImage(String path) {
|
|
||||||
final ext = path.split('.').last.toLowerCase();
|
|
||||||
return ['jpg', 'jpeg', 'png', 'webp'].contains(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return BlocListener<CustomerFilesBloc, CustomerFilesState>(
|
|
||||||
listener: (context, state) {
|
|
||||||
// Quando il BLoC ci dice che ha finito l'upload (Success), chiudiamo la pagina!
|
|
||||||
if (state.status == CustomerFilesStatus.success && _isUploading) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content: Text("Tutti i file caricati con successo! ✅"),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
if (state.status == CustomerFilesStatus.failure) {
|
|
||||||
setState(() => _isUploading = false);
|
|
||||||
ScaffoldMessenger.of(
|
|
||||||
context,
|
|
||||||
).showSnackBar(SnackBar(content: Text("Errore: ${state.error}")));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text("Upload: ${widget.customerName}"),
|
|
||||||
// Togliamo la freccia indietro se stiamo caricando per evitare disastri
|
|
||||||
automaticallyImplyLeading: !_isUploading,
|
|
||||||
),
|
|
||||||
body: Stack(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
// --- SEZIONE PULSANTI (Fotocamera / Galleria) ---
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: ElevatedButton.icon(
|
|
||||||
onPressed: _isUploading ? null : _handleCamera,
|
|
||||||
icon: const Icon(Icons.camera_alt),
|
|
||||||
label: const Text("SCATTA"),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Expanded(
|
|
||||||
child: OutlinedButton.icon(
|
|
||||||
onPressed: _isUploading ? null : _handleFilePicker,
|
|
||||||
icon: const Icon(Icons.folder),
|
|
||||||
label: const Text("GALLERIA"),
|
|
||||||
style: OutlinedButton.styleFrom(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
const Divider(),
|
|
||||||
|
|
||||||
// --- SEZIONE ANTEPRIME (La GridView Magica) ---
|
|
||||||
Expanded(
|
|
||||||
child: _stagedFiles.isEmpty
|
|
||||||
? const Center(
|
|
||||||
child: Text(
|
|
||||||
"Nessun file selezionato.\nScatta una foto o scegli dalla galleria.",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(color: Colors.grey),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: GridView.builder(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
gridDelegate:
|
|
||||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
|
||||||
crossAxisCount:
|
|
||||||
3, // 3 colonne come la galleria dell'iPhone
|
|
||||||
crossAxisSpacing: 12,
|
|
||||||
mainAxisSpacing: 12,
|
|
||||||
),
|
|
||||||
itemCount: _stagedFiles.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final file = _stagedFiles[index];
|
|
||||||
final isImg = _isImage(file.name);
|
|
||||||
|
|
||||||
return Stack(
|
|
||||||
clipBehavior: Clip.none,
|
|
||||||
children: [
|
|
||||||
// L'ANTEPRIMA
|
|
||||||
Container(
|
|
||||||
width: double.infinity,
|
|
||||||
height: double.infinity,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade200,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(
|
|
||||||
color: Colors.grey.shade300,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
child: isImg
|
|
||||||
? Image.file(
|
|
||||||
File(file.path!),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
)
|
|
||||||
: const Column(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.picture_as_pdf,
|
|
||||||
color: Colors.red,
|
|
||||||
size: 36,
|
|
||||||
),
|
|
||||||
SizedBox(height: 4),
|
|
||||||
Text(
|
|
||||||
"PDF",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 10,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// IL PULSANTE CESTINO (In alto a destra)
|
|
||||||
Positioned(
|
|
||||||
top: -8,
|
|
||||||
right: -8,
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
_stagedFiles.removeAt(index);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(4),
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
color: Colors.red,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
child: const Icon(
|
|
||||||
Icons.close,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// --- SEZIONE INVIA E CHIUDI ---
|
|
||||||
SafeArea(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
height: 56,
|
|
||||||
child: ElevatedButton.icon(
|
|
||||||
// Il pulsante si accende SOLO se ci sono file nel carrello
|
|
||||||
onPressed: _stagedFiles.isEmpty || _isUploading
|
|
||||||
? null
|
|
||||||
: _submitAllFiles,
|
|
||||||
icon: const Icon(Icons.cloud_upload),
|
|
||||||
label: Text(
|
|
||||||
"INVIA ${_stagedFiles.length} FILE E CHIUDI",
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
backgroundColor: Theme.of(
|
|
||||||
context,
|
|
||||||
).colorScheme.primary,
|
|
||||||
foregroundColor: Theme.of(
|
|
||||||
context,
|
|
||||||
).colorScheme.onPrimary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
// --- OVERLAY DI CARICAMENTO (Impedisce tap multipli) ---
|
|
||||||
if (_isUploading)
|
|
||||||
Container(
|
|
||||||
color: Colors.black.withValues(alpha: 0.5),
|
|
||||||
child: const Center(
|
|
||||||
child: Card(
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.all(24.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
CircularProgressIndicator(),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Text(
|
|
||||||
"Caricamento in corso...",
|
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- LOGICA FOTOCAMERA E LIBRERIA ---
|
|
||||||
Future<void> _handleCamera() async {
|
|
||||||
final picker = ImagePicker();
|
|
||||||
final photo = await picker.pickImage(
|
|
||||||
source: ImageSource.camera,
|
|
||||||
imageQuality: 80,
|
|
||||||
);
|
|
||||||
if (photo != null) {
|
|
||||||
final photoBytes = await photo.readAsBytes(); // Sicuro anche per Web!
|
|
||||||
final photoSize = await photo.length();
|
|
||||||
|
|
||||||
final platformFile = PlatformFile(
|
|
||||||
name: photo.name,
|
|
||||||
size: photoSize,
|
|
||||||
path: photo.path,
|
|
||||||
bytes: photoBytes, // I bytes ci salvano la vita su Supabase!
|
|
||||||
);
|
|
||||||
setState(() {
|
|
||||||
_stagedFiles.add(platformFile); // Unifichiamo tutto in un dart:io File
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _handleFilePicker() async {
|
|
||||||
// allowMultiple: true permette di pescare 5 foto dalla galleria in un colpo solo!
|
|
||||||
final result = await FilePicker.pickFiles(allowMultiple: true);
|
|
||||||
if (result != null) {
|
|
||||||
setState(() {
|
|
||||||
_stagedFiles.addAll(result.files);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- LOGICA DI INVIO AL BLoC ---
|
|
||||||
void _submitAllFiles() {
|
|
||||||
setState(() => _isUploading = true);
|
|
||||||
|
|
||||||
// Diciamo al BLoC di caricare tutti i file.
|
|
||||||
// Usiamo il tuo evento esistente per ogni file (il BLoC li metterà in coda)
|
|
||||||
final bloc = context.read<CustomerFilesBloc>();
|
|
||||||
bloc.add(UploadMultipleCustomerFilesEvent(_stagedFiles));
|
|
||||||
|
|
||||||
// N.B: Il Navigator.pop() viene chiamato dal BlocListener in alto quando lo stato diventa "success"!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flux/features/master_data/products/blocs/product_cubit.dart';
|
import 'package:flux/core/widgets/shared_forms/shared_model_section.dart';
|
||||||
import 'package:flux/features/master_data/products/ui/quick_product_dialog.dart';
|
|
||||||
import 'package:flux/features/master_data/providers/blocs/provider_cubit.dart';
|
import 'package:flux/features/master_data/providers/blocs/provider_cubit.dart';
|
||||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||||
import 'package:flux/features/operations/models/operation_model.dart';
|
import 'package:flux/features/operations/models/operation_model.dart';
|
||||||
@@ -140,129 +139,6 @@ class DetailsSection extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showModelModal(BuildContext context) {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
isScrollControlled: true,
|
|
||||||
shape: const RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
||||||
),
|
|
||||||
builder: (modalContext) {
|
|
||||||
return DraggableScrollableSheet(
|
|
||||||
initialChildSize: 0.6,
|
|
||||||
minChildSize: 0.4,
|
|
||||||
maxChildSize: 0.9,
|
|
||||||
expand: false,
|
|
||||||
builder: (_, scrollController) {
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Seleziona Modello',
|
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.close),
|
|
||||||
onPressed: () => Navigator.pop(modalContext),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
||||||
child: TextField(
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: 'Cerca modello (es. iPhone 15...)',
|
|
||||||
prefixIcon: const Icon(Icons.search),
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onChanged: (query) =>
|
|
||||||
context.read<ProductsCubit>().searchModels(query),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: ElevatedButton.icon(
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
minimumSize: const Size.fromHeight(48),
|
|
||||||
),
|
|
||||||
icon: const Icon(Icons.add),
|
|
||||||
label: const Text('Aggiungi Modello al Volo'),
|
|
||||||
onPressed: () async {
|
|
||||||
final operationsCubit = context.read<OperationsCubit>();
|
|
||||||
final existingBrands = context
|
|
||||||
.read<ProductsCubit>()
|
|
||||||
.state
|
|
||||||
.brands;
|
|
||||||
|
|
||||||
final newModel = await showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (dialogContext) {
|
|
||||||
return BlocProvider.value(
|
|
||||||
value: context.read<ProductsCubit>(),
|
|
||||||
child: QuickProductDialog(
|
|
||||||
existingBrands: existingBrands,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newModel != null) {
|
|
||||||
operationsCubit.updateOperationFields(
|
|
||||||
modelId: newModel.id,
|
|
||||||
modelDisplayName: newModel.nameWithBrand,
|
|
||||||
);
|
|
||||||
if (context.mounted) Navigator.pop(modalContext);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Divider(),
|
|
||||||
Expanded(
|
|
||||||
child: BlocBuilder<ProductsCubit, ProductState>(
|
|
||||||
builder: (context, state) {
|
|
||||||
return ListView.builder(
|
|
||||||
controller: scrollController,
|
|
||||||
itemCount: state.models.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final deviceModel = state.models[index];
|
|
||||||
return ListTile(
|
|
||||||
leading: const Icon(Icons.devices),
|
|
||||||
title: Text(
|
|
||||||
deviceModel.nameWithBrand,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
context
|
|
||||||
.read<OperationsCubit>()
|
|
||||||
.updateOperationFields(
|
|
||||||
modelId: deviceModel.id,
|
|
||||||
modelDisplayName: deviceModel.nameWithBrand,
|
|
||||||
);
|
|
||||||
Navigator.pop(modalContext);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
@@ -334,30 +210,16 @@ class DetailsSection extends StatelessWidget {
|
|||||||
|
|
||||||
// 2. SCENARIO FIN (Ricerca Modello/Prodotto)
|
// 2. SCENARIO FIN (Ricerca Modello/Prodotto)
|
||||||
if (currentType == 'Fin') ...[
|
if (currentType == 'Fin') ...[
|
||||||
ListTile(
|
SharedModelSection(
|
||||||
title: const Text('Seleziona Dispositivo/Prodotto'),
|
label: 'Seleziona Dispositivo/Prodotto',
|
||||||
subtitle: Text(
|
modelId: currentOp?.modelId,
|
||||||
(currentOp?.modelDisplayName != null &&
|
modelName: currentOp?.modelDisplayName,
|
||||||
currentOp!.modelDisplayName!.isNotEmpty)
|
onModelSelected: (id, name) {
|
||||||
? currentOp!.modelDisplayName!
|
context.read<OperationsCubit>().updateOperationFields(
|
||||||
: 'Nessun modello selezionato',
|
modelId: id,
|
||||||
style: TextStyle(
|
modelDisplayName: name,
|
||||||
color:
|
);
|
||||||
(currentOp?.modelId == null || currentOp!.modelId!.isEmpty)
|
},
|
||||||
? Colors.grey
|
|
||||||
: null,
|
|
||||||
fontWeight:
|
|
||||||
(currentOp?.modelId == null || currentOp!.modelId!.isEmpty)
|
|
||||||
? FontWeight.normal
|
|
||||||
: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
trailing: const Icon(Icons.arrow_drop_down),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
side: BorderSide(color: theme.dividerColor),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
onTap: () => _showModelModal(context),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user