| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import 'package:flutter/material.dart';
- import 'package:ristoris/core/constants.dart';
- import 'package:ristoris/database/database.dart';
- class OrderActions extends StatelessWidget {
- final VOrdiniData order;
- final VoidCallback onEdit;
- final VoidCallback onDelete;
- const OrderActions({
- super.key,
- required this.order,
- required this.onEdit,
- required this.onDelete,
- });
- @override
- Widget build(BuildContext context) {
- final cs = Theme.of(context).colorScheme;
- if (order.stato == AppConstants.kStatusNew) {
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- IconButton(
- icon: const Icon(Icons.edit, size: 20),
- onPressed: onEdit,
- visualDensity: VisualDensity.compact,
- ),
- IconButton(
- icon: Icon(Icons.delete_outline, size: 20, color: cs.error),
- onPressed: () => _confirmDelete(context),
- visualDensity: VisualDensity.compact,
- ),
- ],
- );
- }
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- IconButton(
- icon: Icon(Icons.visibility, size: 20, color: cs.secondary),
- onPressed: onEdit,
- visualDensity: VisualDensity.compact,
- ),
- ],
- );
- }
- Future<void> _confirmDelete(BuildContext context) async {
- final confirmed = await showDialog<bool>(
- context: context,
- builder: (ctx) => AlertDialog(
- title: const Text('Elimina ordine'),
- content: Text(
- 'Vuoi eliminare l\'ordine n. ${order.numeroOrdine ?? order.idOrdine}?',
- ),
- actions: [
- TextButton(
- onPressed: () => Navigator.pop(ctx, false),
- child: const Text('Annulla'),
- ),
- FilledButton(
- onPressed: () => Navigator.pop(ctx, true),
- child: const Text('Elimina'),
- ),
- ],
- ),
- );
- if (confirmed == true && context.mounted) {
- onDelete();
- }
- }
- }
|