@@ -22,7 +22,12 @@ enum DeletionStatus {
2222@immutable
2323class DeletionEvent <T > extends Equatable {
2424 /// {@macro deletion_event}
25- const DeletionEvent (this .id, this .status, {this .item});
25+ const DeletionEvent (
26+ this .id,
27+ this .status, {
28+ this .item,
29+ this .message,
30+ });
2631
2732 /// The unique identifier of the item.
2833 final String id;
@@ -34,8 +39,11 @@ class DeletionEvent<T> extends Equatable {
3439 /// This is typically provided when a deletion is undone.
3540 final T ? item;
3641
42+ /// An optional message associated with the event, e.g., for snackbars.
43+ final String ? message;
44+
3745 @override
38- List <Object ?> get props => [id, status, item];
46+ List <Object ?> get props => [id, status, item, message ];
3947}
4048
4149/// {@template pending_deletions_service}
@@ -60,10 +68,12 @@ abstract class PendingDeletionsService {
6068 /// - [item] : The item to be deleted. Must have an `id` property.
6169 /// - [repository] : The `DataRepository<T>` responsible for deleting the item.
6270 /// - [undoDuration] : The duration to wait before confirming the deletion.
71+ /// - [messageBuilder] : An optional function to build a localized message for the UI.
6372 void requestDeletion <T >({
6473 required T item,
6574 required DataRepository <T > repository,
6675 required Duration undoDuration,
76+ String Function ()? messageBuilder,
6777 });
6878
6979 /// Cancels a pending deletion for the item with the given [id] .
@@ -106,6 +116,7 @@ class PendingDeletionsServiceImpl implements PendingDeletionsService {
106116 required T item,
107117 required DataRepository <T > repository,
108118 required Duration undoDuration,
119+ String Function ()? messageBuilder,
109120 }) {
110121 // The item must have an 'id' property.
111122 final id = (item as dynamic ).id as String ;
@@ -133,7 +144,12 @@ class PendingDeletionsServiceImpl implements PendingDeletionsService {
133144 }
134145 });
135146
136- _pendingDeletionTimers[id] = _PendingDeletion <T >(timer: timer, item: item);
147+ final message = messageBuilder? .call ();
148+ _pendingDeletionTimers[id] = _PendingDeletion <T >(
149+ timer: timer,
150+ item: item,
151+ message: message,
152+ );
137153 }
138154
139155 @override
@@ -174,11 +190,16 @@ class PendingDeletionsServiceImpl implements PendingDeletionsService {
174190/// A private class to hold the timer and the item for a pending deletion.
175191@immutable
176192class _PendingDeletion <T > extends Equatable {
177- const _PendingDeletion ({required this .timer, required this .item});
193+ const _PendingDeletion ({
194+ required this .timer,
195+ required this .item,
196+ this .message,
197+ });
178198
179199 final Timer timer;
180200 final T item;
201+ final String ? message;
181202
182203 @override
183- List <Object ?> get props => [timer, item];
204+ List <Object ?> get props => [timer, item, message ];
184205}
0 commit comments