wake-alarm/phone_app/lib/screens/escape_dialog.dart
Krzysztof kuhy Rudnicki 8e6fa90c80
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Bump Flutter to 3.50.0 via material_ui
Flutter 3.50 deprecates package:flutter/material.dart, so the app
moves to material_ui 1.11.0 together with sync_settings_ui 0.8.0
and github_device_auth 0.5.0 (crdt_sync 0.13.1 rides along).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 09:06:16 +01:00

103 lines
3.2 KiB
Dart

import 'package:material_ui/material_ui.dart';
import 'package:wake_alarm_sync/services/stakes.dart';
/// Asks why this morning should be excused; the reason, or null if
/// cancelled.
///
/// The confirm button stays disabled until the reason has at least
/// [escapeReasonMinChars] characters: the hatch exists for bugs, and a typed
/// explanation is what the incident report is read against.
Future<String?> showEscapeDialog(BuildContext context) =>
showDialog<String>(context: context, builder: (_) => const EscapeDialog());
/// The escape-hatch dialog; see [showEscapeDialog].
class EscapeDialog extends StatefulWidget {
/// Creates the dialog.
const EscapeDialog({super.key});
@override
State<EscapeDialog> createState() => _EscapeDialogState();
}
class _EscapeDialogState extends State<EscapeDialog> {
final TextEditingController _reason = TextEditingController();
@override
void dispose() {
_reason.dispose();
super.dispose();
}
int get _length => _reason.text.trim().length;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final ready = _length >= escapeReasonMinChars;
const reasonWords = 'What went wrong?';
return AlertDialog(
// The keyboard covers half a small screen; scroll instead of overflow.
scrollable: true,
icon: const Icon(
Icons.bug_report_outlined,
semanticLabel: 'That was a bug',
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
MergeSemantics(
child: Semantics(
label: reasonWords,
child: TextField(
controller: _reason,
autofocus: true,
maxLines: 4,
minLines: 2,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.edit_note),
border: OutlineInputBorder(),
),
onChanged: (_) => setState(() {}),
),
),
),
const SizedBox(height: 8),
Row(
children: <Widget>[
Expanded(
child: LinearProgressIndicator(
value: (_length / escapeReasonMinChars)
.clamp(0, 1)
.toDouble(),
),
),
const SizedBox(width: 8),
Text(
'$_length/$escapeReasonMinChars',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
],
),
actions: <Widget>[
IconButton(
key: const Key('escape-cancel'),
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.close, semanticLabel: 'Cancel'),
),
FilledButton(
key: const Key('escape-confirm'),
onPressed: ready
? () => Navigator.of(context).pop(_reason.text.trim())
: null,
child: const Icon(Icons.check, semanticLabel: 'Excuse this morning'),
),
],
);
}
}