sistemato deeplinking alla serviceformscreen, aggiunto logout e sistemate altre cose
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||
@@ -123,4 +124,34 @@ class ProductCubit extends Cubit<ProductState> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<ModelModel?> quickCreateProduct({
|
||||
required String brandName,
|
||||
required String modelName,
|
||||
}) async {
|
||||
try {
|
||||
await loadBrands();
|
||||
BrandModel? brand = state.brands.firstWhereOrNull(
|
||||
(b) => b.name.toLowerCase() == brandName.toLowerCase(),
|
||||
);
|
||||
// 1. Cerchiamo o creiamo il Brand
|
||||
// (Usa una funzione upsert o una ricerca rapida nel repository)
|
||||
brand ??= await _repository.upsertBrand(
|
||||
BrandModel(name: brandName, companyId: _sessionBloc.state.company!.id),
|
||||
);
|
||||
|
||||
// 2. Creiamo il Modello legato al Brand
|
||||
final newModel = await _repository.upsertModel(
|
||||
ModelModel(brandId: brand.id!, name: modelName),
|
||||
);
|
||||
|
||||
// 3. Aggiorniamo lo stato locale così la lista modelli lo vede subito
|
||||
emit(state.copyWith(models: [newModel, ...state.models]));
|
||||
|
||||
return newModel;
|
||||
} catch (e) {
|
||||
emit(state.copyWith(errorMessage: "Errore creazione rapida: $e"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class ModelModel extends Equatable {
|
||||
const ModelModel({
|
||||
this.id,
|
||||
required this.name,
|
||||
required this.nameWithBrand,
|
||||
this.nameWithBrand = '',
|
||||
required this.brandId,
|
||||
this.isActive = true,
|
||||
this.createdAt,
|
||||
|
||||
111
lib/features/master_data/products/ui/quick_product_dialog.dart
Normal file
111
lib/features/master_data/products/ui/quick_product_dialog.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
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/models/brand_model.dart';
|
||||
|
||||
class QuickProductDialog extends StatefulWidget {
|
||||
final List<BrandModel> existingBrands;
|
||||
|
||||
const QuickProductDialog({super.key, required this.existingBrands});
|
||||
|
||||
@override
|
||||
State<QuickProductDialog> createState() => _QuickProductDialogState();
|
||||
}
|
||||
|
||||
class _QuickProductDialogState extends State<QuickProductDialog> {
|
||||
final _modelCtrl = TextEditingController();
|
||||
String _selectedBrandName = "";
|
||||
bool _isLoading = false;
|
||||
|
||||
Future<void> _save() async {
|
||||
final NavigatorState navigator = Navigator.of(context);
|
||||
if (_selectedBrandName.isEmpty || _modelCtrl.text.isEmpty) return;
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
final newModel = await context.read<ProductCubit>().quickCreateProduct(
|
||||
brandName: _selectedBrandName.trim(),
|
||||
modelName: _modelCtrl.text.trim(),
|
||||
);
|
||||
|
||||
setState(() => _isLoading = false);
|
||||
|
||||
if (context.mounted) {
|
||||
navigator.pop(newModel); // Restituiamo il modello creato
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Nuovo Dispositivo"),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// AUTOCOMPLETE PER IL BRAND LOCALE
|
||||
Autocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
if (textEditingValue.text.isEmpty) {
|
||||
return const Iterable<String>.empty();
|
||||
}
|
||||
final query = textEditingValue.text.toLowerCase();
|
||||
// Filtriamo i brand che contengono la stringa cercata
|
||||
return widget.existingBrands
|
||||
.map((b) => b.name)
|
||||
.where((name) => name.toLowerCase().contains(query));
|
||||
},
|
||||
onSelected: (String selection) {
|
||||
_selectedBrandName = selection;
|
||||
},
|
||||
fieldViewBuilder:
|
||||
(
|
||||
context,
|
||||
textEditingController,
|
||||
focusNode,
|
||||
onFieldSubmitted,
|
||||
) {
|
||||
return TextField(
|
||||
controller: textEditingController,
|
||||
focusNode: focusNode,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Marca (es: Apple, Samsung)",
|
||||
hintText: "Inizia a scrivere...",
|
||||
),
|
||||
onChanged: (val) => _selectedBrandName = val,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _modelCtrl,
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Modello (es: iPhone 15 Pro)",
|
||||
),
|
||||
textInputAction: TextInputAction.done,
|
||||
onSubmitted: (_) => _save(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text("Annulla"),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: _isLoading ? null : _save,
|
||||
child: _isLoading
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Text("Crea"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ class ProviderModel extends Equatable {
|
||||
final bool energia;
|
||||
final bool assicurazioni;
|
||||
final bool intrattenimento;
|
||||
final bool finanziamenti;
|
||||
final bool altro;
|
||||
final bool isActive;
|
||||
final String companyId;
|
||||
@@ -22,6 +23,7 @@ class ProviderModel extends Equatable {
|
||||
required this.energia,
|
||||
required this.assicurazioni,
|
||||
required this.intrattenimento,
|
||||
required this.finanziamenti,
|
||||
required this.altro,
|
||||
required this.isActive,
|
||||
required this.companyId,
|
||||
@@ -48,6 +50,7 @@ class ProviderModel extends Equatable {
|
||||
energia: map['energia'] ?? false,
|
||||
assicurazioni: map['assicurazioni'] ?? false,
|
||||
intrattenimento: map['intrattenimento'] ?? false,
|
||||
finanziamenti: map['finanziamenti'] ?? false,
|
||||
altro: map['altro'] ?? false,
|
||||
isActive: map['is_active'] ?? true,
|
||||
companyId: map['company_id'],
|
||||
@@ -63,6 +66,7 @@ class ProviderModel extends Equatable {
|
||||
'energia': energia,
|
||||
'assicurazioni': assicurazioni,
|
||||
'intrattenimento': intrattenimento,
|
||||
'finanziamenti': finanziamenti,
|
||||
'altro': altro,
|
||||
'is_active': isActive,
|
||||
'company_id': companyId,
|
||||
@@ -84,6 +88,7 @@ class ProviderModel extends Equatable {
|
||||
energia,
|
||||
assicurazioni,
|
||||
intrattenimento,
|
||||
finanziamenti,
|
||||
altro,
|
||||
isActive,
|
||||
companyId,
|
||||
@@ -98,6 +103,7 @@ class ProviderModel extends Equatable {
|
||||
bool? energia,
|
||||
bool? assicurazioni,
|
||||
bool? intrattenimento,
|
||||
bool? finanziamenti,
|
||||
bool? altro,
|
||||
bool? isActive,
|
||||
String? companyId,
|
||||
@@ -111,6 +117,7 @@ class ProviderModel extends Equatable {
|
||||
energia: energia ?? this.energia,
|
||||
assicurazioni: assicurazioni ?? this.assicurazioni,
|
||||
intrattenimento: intrattenimento ?? this.intrattenimento,
|
||||
finanziamenti: finanziamenti ?? this.finanziamenti,
|
||||
altro: altro ?? this.altro,
|
||||
isActive: isActive ?? this.isActive,
|
||||
companyId: companyId ?? this.companyId,
|
||||
|
||||
@@ -20,6 +20,7 @@ class _ProviderFormSheetState extends State<ProviderFormSheet> {
|
||||
late bool _energia;
|
||||
late bool _assicurazioni;
|
||||
late bool _intrattenimento;
|
||||
late bool _finanziamenti;
|
||||
late bool _altro;
|
||||
late bool _isActive;
|
||||
final List<String> _tempSelectedStoreIds =
|
||||
@@ -38,6 +39,7 @@ class _ProviderFormSheetState extends State<ProviderFormSheet> {
|
||||
_energia = p?.energia ?? false;
|
||||
_assicurazioni = p?.assicurazioni ?? false;
|
||||
_intrattenimento = p?.intrattenimento ?? false;
|
||||
_finanziamenti = p?.finanziamenti ?? false;
|
||||
_altro = p?.altro ?? false;
|
||||
_isActive = p?.isActive ?? true;
|
||||
}
|
||||
@@ -61,6 +63,7 @@ class _ProviderFormSheetState extends State<ProviderFormSheet> {
|
||||
energia: _energia,
|
||||
assicurazioni: _assicurazioni,
|
||||
intrattenimento: _intrattenimento,
|
||||
finanziamenti: _finanziamenti,
|
||||
altro: _altro,
|
||||
isActive: _isActive,
|
||||
companyId:
|
||||
@@ -130,6 +133,11 @@ class _ProviderFormSheetState extends State<ProviderFormSheet> {
|
||||
_intrattenimento,
|
||||
(v) => setState(() => _intrattenimento = v),
|
||||
),
|
||||
_buildSwitch(
|
||||
"Finanziamenti",
|
||||
_finanziamenti,
|
||||
(v) => setState(() => _finanziamenti = v),
|
||||
),
|
||||
_buildSwitch(
|
||||
"Altro/Accessori",
|
||||
_altro,
|
||||
|
||||
Reference in New Issue
Block a user