364fd5b538
Keep the Material-only run action behavior while preserving public Cupertino parameters for callers that will be cleaned up separately. Narrow the related tests to the supported Material path.
41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../data/runs_repository.dart';
|
|
import '../domain/run_deletion.dart';
|
|
import 'delete_runs_dialog.dart';
|
|
|
|
/// Confirms and deletes the finished runs among [runs].
|
|
///
|
|
/// Active runs are left out; nothing is sent unless the operator confirms. A
|
|
/// transport or server error stays in the open prompt. The server's reply,
|
|
/// including any refusals, goes to [onDeleted] exactly as received.
|
|
Future<bool> confirmDeleteRuns(
|
|
BuildContext context, {
|
|
required Iterable<JsonMap> runs,
|
|
required ApiGateway gateway,
|
|
required ValueChanged<RunsDeletion> onDeleted,
|
|
bool? cupertino,
|
|
}) {
|
|
final deletable = runs.where(runIsDeletable).toList();
|
|
final ids = deletableRunIds(deletable);
|
|
if (ids.isEmpty) return Future.value(false);
|
|
return showDeleteRunsPrompt(
|
|
context: context,
|
|
count: ids.length,
|
|
size: runsSizeLabel(deletable),
|
|
cupertino: cupertino ?? false,
|
|
onSubmit: () async {
|
|
try {
|
|
onDeleted(await RunsRepository(gateway).deleteRuns(ids));
|
|
return null;
|
|
} catch (error) {
|
|
final message = '$error'.trim();
|
|
return message.isEmpty
|
|
? 'The server did not delete the runs.'
|
|
: message;
|
|
}
|
|
},
|
|
);
|
|
}
|