Files
pipelines/app/lib/features/runs/actions/delete_runs_dialog.dart
T
alan 9551eceaed Complete Material-only APIs and fixtures
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
2026-11-11 21:55:39 +00:00

122 lines
3.2 KiB
Dart

import 'package:flutter/material.dart';
import '../domain/run_deletion.dart';
const deleteRunsConfirmKey = ValueKey<String>('runs.delete.confirm');
const deleteRunsKeepKey = ValueKey<String>('runs.delete.keep');
const deleteRunsErrorKey = ValueKey<String>('runs.delete.error');
/// Sends the confirmed deletion. Returns null once the server replied, or the
/// failure to show in the still-open prompt.
typedef DeleteRunsSubmit = Future<String?> Function();
/// Opens the native destructive confirmation for deleting [count] runs.
///
/// Nothing is sent until Delete is pressed; Cancel only closes the prompt.
/// Resolves true when the server answered the deletion.
Future<bool> showDeleteRunsPrompt({
required BuildContext context,
required int count,
required String? size,
required DeleteRunsSubmit onSubmit,
}) async {
final prompt = _DeleteRunsPrompt(
count: count,
size: size,
onSubmit: onSubmit,
);
final result = await showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (_) => prompt,
);
return result ?? false;
}
class _DeleteRunsPrompt extends StatefulWidget {
const _DeleteRunsPrompt({
required this.count,
required this.size,
required this.onSubmit,
});
final int count;
final String? size;
final DeleteRunsSubmit onSubmit;
@override
State<_DeleteRunsPrompt> createState() => _DeleteRunsPromptState();
}
class _DeleteRunsPromptState extends State<_DeleteRunsPrompt> {
bool _sending = false;
String? _error;
Future<void> _confirm() async {
if (_sending) return;
setState(() {
_sending = true;
_error = null;
});
final error = await widget.onSubmit();
if (!mounted) return;
if (error == null) {
Navigator.of(context).pop(true);
return;
}
setState(() {
_sending = false;
_error = error;
});
}
void _keep() {
if (!_sending) Navigator.of(context).pop(false);
}
@override
Widget build(BuildContext context) =>
PopScope(canPop: !_sending, child: _material(context));
Widget _material(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return AlertDialog(
scrollable: true,
title: Text(deleteRunsTitle(widget.count)),
content: _body(TextStyle(color: scheme.error)),
actions: [
TextButton(
key: deleteRunsKeepKey,
onPressed: _sending ? null : _keep,
child: const Text('Cancel'),
),
FilledButton(
key: deleteRunsConfirmKey,
style: FilledButton.styleFrom(
backgroundColor: scheme.error,
foregroundColor: scheme.onError,
),
onPressed: _sending ? null : _confirm,
child: Text(_sending ? 'Deleting…' : 'Delete'),
),
],
);
}
Widget _body(TextStyle errorStyle) => Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(deleteRunsMessage(widget.count, size: widget.size)),
if (_error case final error?)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Semantics(
liveRegion: true,
child: Text(error, key: deleteRunsErrorKey, style: errorStyle),
),
),
],
);
}