rifatta operation form e diverse migliorie generali
This commit is contained in:
@@ -3,9 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/routes/routes.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/features/customers/blocs/customers_cubit.dart';
|
||||
import 'package:flux/features/customers/blocs/customers_list_cubit.dart';
|
||||
import 'package:flux/features/customers/models/customer_model.dart';
|
||||
import 'package:flux/features/customers/ui/customer_form.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class CustomersListScreen extends StatefulWidget {
|
||||
@@ -27,14 +26,14 @@ class _CustomersListScreenState extends State<CustomersListScreen> {
|
||||
void _loadInitialCustomers() {
|
||||
final companyId = context.read<SessionCubit>().state.company?.id;
|
||||
if (companyId != null) {
|
||||
context.read<CustomersCubit>().loadCustomers();
|
||||
context.read<CustomersListCubit>().loadCustomers();
|
||||
}
|
||||
}
|
||||
|
||||
void _onSearch(String query) {
|
||||
final companyId = context.read<SessionCubit>().state.company?.id;
|
||||
if (companyId != null) {
|
||||
context.read<CustomersCubit>().searchCustomers(query);
|
||||
context.read<CustomersListCubit>().searchCustomers(query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +52,12 @@ class _CustomersListScreenState extends State<CustomersListScreen> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 16),
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () => openCustomerForm(context: context),
|
||||
onPressed: () {
|
||||
context.pushNamed(
|
||||
Routes.customerForm,
|
||||
pathParameters: {'id': 'new'},
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.person_add_alt_1_rounded, size: 20),
|
||||
label: const Text('NUOVO'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
@@ -87,9 +91,9 @@ class _CustomersListScreenState extends State<CustomersListScreen> {
|
||||
|
||||
// LISTA CLIENTI
|
||||
Expanded(
|
||||
child: BlocBuilder<CustomersCubit, CustomersState>(
|
||||
child: BlocBuilder<CustomersListCubit, CustomersListState>(
|
||||
builder: (context, state) {
|
||||
if (state.status == CustomersStatus.loading &&
|
||||
if (state.status == CustomersListStatus.loading &&
|
||||
state.customers.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
@@ -214,8 +218,16 @@ class _CustomerTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
trailing: IconButton(
|
||||
onPressed: () =>
|
||||
openCustomerForm(context: context, customer: customer),
|
||||
onPressed: () async {
|
||||
final CustomersListCubit customersCubit = context
|
||||
.read<CustomersListCubit>();
|
||||
await context.pushNamed(
|
||||
Routes.customerForm,
|
||||
pathParameters: {'id': customer.id!},
|
||||
extra: customer,
|
||||
);
|
||||
customersCubit.loadCustomers();
|
||||
},
|
||||
icon: Icon(Icons.edit_note_rounded, color: context.accent),
|
||||
),
|
||||
),
|
||||
@@ -224,7 +236,7 @@ class _CustomerTile extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Funzione unica per gestire Creazione e Modifica
|
||||
void openCustomerForm({
|
||||
/* void openCustomerForm({
|
||||
CustomerModel? customer,
|
||||
required BuildContext context,
|
||||
}) {
|
||||
@@ -257,4 +269,4 @@ void openCustomerForm({
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} */
|
||||
|
||||
Reference in New Issue
Block a user