Skip to content

Commit 17e470b

Browse files
committed
Implement test wise the delete logic
1 parent 9ae16b9 commit 17e470b

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/feature/sound/card/sound_file_card.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ class SoundFileCard extends StatelessWidget {
88

99
static const double _fullCardMinWidth = 230;
1010

11-
const SoundFileCard({required this.source, super.key});
11+
const SoundFileCard({required this.source, this.onDeleteRequested, super.key});
1212

1313
final SoundFileSource source;
14+
final VoidCallback? onDeleteRequested;
1415

1516
@override
1617
Widget build(BuildContext context) {
@@ -52,7 +53,13 @@ class SoundFileCard extends StatelessWidget {
5253
],
5354
),
5455
),
55-
SoundCardButton(source: source)
56+
SoundCardButton(source: source),
57+
const SizedBox(width: 8),
58+
if (onDeleteRequested != null)
59+
OutlinedButton(
60+
onPressed: onDeleteRequested,
61+
child: const Text('Delete'),
62+
),
5663
],
5764
),
5865
),

lib/feature/sound/sound_file_entries.dart

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ class _SoundFileEntriesState extends State<SoundFileEntryPage> {
9090
minWidth: 220,
9191
maxWidth: 400,
9292
),
93-
child: SoundFileCard(source: files.items[index]),
93+
child: SoundFileCard(
94+
source: files.items[index],
95+
onDeleteRequested: () => _confirmAndDelete(context, files.items[index]),
96+
),
9497
);
9598
},
9699
);
@@ -123,4 +126,28 @@ class _SoundFileEntriesState extends State<SoundFileEntryPage> {
123126
),
124127
);
125128
}
129+
130+
Future<void> _confirmAndDelete(BuildContext context, SoundFileSource source) async {
131+
final bool? confirmed = await showDialog<bool>(
132+
context: context,
133+
builder: (ctx) => AlertDialog(
134+
title: const Text('Delete file'),
135+
content: const Text('Unlink this file from the sound event?'),
136+
actions: [
137+
TextButton(
138+
onPressed: () => Navigator.of(ctx).pop(false),
139+
child: const Text('Cancel'),
140+
),
141+
FilledButton(
142+
onPressed: () => Navigator.of(ctx).pop(true),
143+
child: const Text('Delete'),
144+
),
145+
],
146+
),
147+
);
148+
149+
if (confirmed == true) {
150+
context.dispatch(SoundFileSourceDeleteAction(source));
151+
}
152+
}
126153
}

0 commit comments

Comments
 (0)