Files
pipelines/app/lib/features/schedules/ui/pipeline/schedule_delete_dialog.dart
T
alan 4647b9c43e Remove Cupertino schedules branches
Keep the Material-only schedules implementation while preserving public Cupertino parameters for callers. Remove Cupertino-only test hosts and variants because the app runs every schedule screen under MaterialApp.
2026-11-11 04:26:05 +00:00

108 lines
2.9 KiB
Dart

import 'package:flutter/material.dart';
import 'schedule_pipeline_wording.dart';
/// Deletes the exact schedule revision. Returns null once the server accepted
/// the delete, or the server's own reasons verbatim.
typedef ScheduleDeleteSubmit = Future<String?> Function();
/// Opens the one native confirmation for a schedule deletion.
///
/// Nothing is sent until `Delete schedule` is pressed; `Keep schedule` only
/// closes the prompt. A refusal keeps the prompt open with the server's words.
Future<void> showScheduleDeleteDialog({
required BuildContext context,
required String name,
required ScheduleDeleteSubmit onSubmit,
}) {
final prompt = _ScheduleDeletePrompt(name: name, onSubmit: onSubmit);
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (_) => prompt,
);
}
class _ScheduleDeletePrompt extends StatefulWidget {
const _ScheduleDeletePrompt({required this.name, required this.onSubmit});
final String name;
final ScheduleDeleteSubmit onSubmit;
@override
State<_ScheduleDeletePrompt> createState() => _ScheduleDeletePromptState();
}
class _ScheduleDeletePromptState extends State<_ScheduleDeletePrompt> {
bool _sending = false;
String? _refusal;
void _keep() {
if (!_sending) Navigator.of(context).pop();
}
Future<void> _confirm() async {
if (_sending) return;
setState(() {
_sending = true;
_refusal = null;
});
final refusal = await widget.onSubmit();
if (!mounted) return;
if (refusal == null) {
Navigator.of(context).pop();
return;
}
setState(() {
_sending = false;
_refusal = refusal;
});
}
@override
Widget build(BuildContext context) {
return PopScope(canPop: !_sending, child: _material(context));
}
Widget _material(BuildContext context) {
return AlertDialog(
scrollable: true,
title: Text(scheduleDeleteTitle(widget.name)),
content: _body(
errorStyle: TextStyle(color: Theme.of(context).colorScheme.error),
),
actions: [
TextButton(
key: scheduleDeleteKeepKey,
onPressed: _sending ? null : _keep,
child: const Text(scheduleDeleteKeepLabel),
),
FilledButton(
key: scheduleDeleteConfirmKey,
onPressed: _sending ? null : _confirm,
child: const Text(scheduleDeleteConfirmLabel),
),
],
);
}
Widget _body({required TextStyle errorStyle}) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(scheduleDeleteMessage),
if (_refusal case final refusal?)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
refusal,
key: scheduleDeleteErrorKey,
style: errorStyle,
),
),
],
);
}
}