diet-guard/app/lib/widgets/pickers/year_wheel.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

51 lines
1.4 KiB
Dart

/// The date picker's year wheel: numerals, no loop.
library;
import 'package:diet_guard_app/widgets/pickers/numeral_wheel.dart';
import 'package:flutter/material.dart';
/// Out-of-range years listed beyond each bound, dimmed and inert, so the
/// wheel's ends read as limits rather than as a list that just stops.
const int kYearWheelPad = 2;
/// A non-looping wheel of the years [firstYear]..[lastYear], plus
/// [kYearWheelPad] dimmed, inert years past each end (a wheel dragged onto
/// one springs back).
class YearWheel extends StatelessWidget {
/// Creates a [YearWheel].
const YearWheel({
required this.firstYear,
required this.lastYear,
required this.value,
required this.onChanged,
this.autofocus = false,
super.key,
});
/// Earliest listed year.
final int firstYear;
/// Latest listed year.
final int lastYear;
/// The shown year.
final int value;
/// Called with a newly centred year.
final ValueChanged<int> onChanged;
/// Whether the wheel takes keyboard focus on open (the birth-date flow).
final bool autofocus;
@override
Widget build(BuildContext context) => NumeralWheel(
count: lastYear - firstYear + 1 + 2 * kYearWheelPad,
offset: firstYear - kYearWheelPad,
enabled: (y) => y >= firstYear && y <= lastYear,
value: value,
onChanged: onChanged,
semanticLabel: 'Year',
autofocus: autofocus,
);
}