diet-guard/app/lib/widgets/pickers/picker_frame.dart
Krzysztof kuhy Rudnicki 4eca59bac9
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (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) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Icon-only date and time pickers
Replace showDatePicker, showDateRangePicker and showTimePicker with
numeral grid/wheel dialogs confirmed by check and close icons. Adds a
no-words picker guard and a repo invariant banning the framework pickers.

Todo: e09dac36

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

76 lines
2.4 KiB
Dart

/// The shared dialog around every picker: a centred, width-capped [Dialog]
/// with a close icon (cancel) and a check icon (confirm), no words.
library;
import 'package:diet_guard_app/ui/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// Picker chrome. Outside tap and Esc cancel (the dialog route's own
/// dismiss); Enter confirms when [canConfirm].
///
/// The icons carry spoken-only `semanticLabel`s and no `tooltip:`, which
/// would paint the word on long-press.
class PickerFrame extends StatelessWidget {
/// Creates a [PickerFrame].
const PickerFrame({
required this.child,
required this.canConfirm,
required this.onConfirm,
super.key,
});
/// The picker body.
final Widget child;
/// Whether the check is enabled (a half-chosen range is not).
final bool canConfirm;
/// Pops the dialog with the chosen value.
final VoidCallback onConfirm;
void _enter() {
if (canConfirm) onConfirm();
}
@override
Widget build(BuildContext context) => Dialog(
insetPadding: const EdgeInsets.all(AppSpacing.md),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: AppWidth.picker),
child: SingleChildScrollView(
padding: const EdgeInsets.all(AppSpacing.md),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Around the body only: Enter on a focused close icon must
// reach that button (cancel), not bubble up into a confirm.
CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.enter): _enter,
const SingleActivator(LogicalKeyboardKey.numpadEnter): _enter,
},
child: child,
),
const SizedBox(height: AppSpacing.sm),
Row(
mainAxisAlignment: MainAxisAlignment.end,
spacing: AppSpacing.sm,
children: [
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.close, semanticLabel: 'Cancel'),
),
IconButton.filled(
onPressed: canConfirm ? onConfirm : null,
icon: const Icon(Icons.check, semanticLabel: 'Confirm'),
),
],
),
],
),
),
),
);
}