import 'package:flutter/material.dart'; /// Per-row action for DataGrid. class DataGridAction { const DataGridAction({ required this.icon, required this.label, required this.onTap, this.showWhen, this.destructive = false, this.requiresConfirmation = false, this.confirmationMessage, }); /// Icon to display in the action menu. final IconData icon; /// Label for the action. final String label; /// Callback when the action is triggered. final Future Function(T item) onTap; /// Condition to show/hide this action for specific items. final bool Function(T item)? showWhen; /// Whether this is a destructive action (styled differently). final bool destructive; /// Whether to show a confirmation dialog before executing. final bool requiresConfirmation; /// Custom confirmation message. Defaults to "Are you sure?". final String? confirmationMessage; /// Checks if this action should be shown for the given item. bool shouldShow(T item) => showWhen?.call(item) ?? true; } /// Bulk action for selected rows in DataGrid. class DataGridBulkAction { const DataGridBulkAction({ required this.icon, required this.label, required this.onTap, this.minSelected = 1, this.maxSelected, this.destructive = false, this.requiresConfirmation = false, this.confirmationMessage, }); /// Icon to display. final IconData icon; /// Label for the action. final String label; /// Callback when the action is triggered with selected items. final Future Function(List items) onTap; /// Minimum number of items that must be selected. final int minSelected; /// Maximum number of items that can be selected (null = no limit). final int? maxSelected; /// Whether this is a destructive action. final bool destructive; /// Whether to show a confirmation dialog before executing. final bool requiresConfirmation; /// Custom confirmation message. final String? confirmationMessage; /// Checks if this action is available for the given selection count. bool isAvailable(int selectedCount) { if (selectedCount < minSelected) return false; if (maxSelected != null && selectedCount > maxSelected!) return false; return true; } }