mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-19 22:34:25 +01:00
Flutter 3.50 deprecates package:flutter/material.dart; 73 deprecation infos failed flutter analyze --fatal-infos, and four Dart pins were behind (crdt_sync_flutter 0.8.2, flutter_local_notifications 23.0.2, github_device_auth 0.5.0, sync_settings_ui 0.8.2). Those UI packages now sit on material_ui, so the app has to as well or their widgets lose MaterialLocalizations. Imports swap one-for-one and dart fix re-sorted the directives; no behaviour change. analyze is clean and all six test shards pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
92 lines
2.6 KiB
Dart
92 lines
2.6 KiB
Dart
/// The time picker's two looping wheels: hour 00-23 and minute 00-59, 24 h.
|
|
library;
|
|
|
|
import 'package:diet_guard_app/ui/theme.dart';
|
|
import 'package:diet_guard_app/widgets/pickers/numeral_wheel.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
|
|
/// Width of one time wheel.
|
|
const double kTimeWheelWidth = 72;
|
|
|
|
/// Whether hour [h] holds any minute of day in [min]..[max].
|
|
bool hourAllowed(int h, int min, int max) =>
|
|
h * 60 + 59 >= min && h * 60 <= max;
|
|
|
|
/// [minute] of day pulled into [min]..[max].
|
|
int clampMinute(int minute, int min, int max) => minute.clamp(min, max);
|
|
|
|
/// Hour and minute wheels for a minute of day within [minMinute]..[maxMinute].
|
|
///
|
|
/// Hours and minutes outside the range are dimmed and inert. Changing the
|
|
/// hour pulls the minute to the nearest allowed one in that hour, so the
|
|
/// value reported is always in range.
|
|
class TimeWheels extends StatelessWidget {
|
|
/// Creates a [TimeWheels].
|
|
const TimeWheels({
|
|
required this.minute,
|
|
required this.minMinute,
|
|
required this.maxMinute,
|
|
required this.onChanged,
|
|
super.key,
|
|
});
|
|
|
|
/// The current minute of day (in range).
|
|
final int minute;
|
|
|
|
/// Earliest allowed minute of day.
|
|
final int minMinute;
|
|
|
|
/// Latest allowed minute of day.
|
|
final int maxMinute;
|
|
|
|
/// Called with each new in-range minute of day.
|
|
final ValueChanged<int> onChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final hour = minute ~/ 60;
|
|
Widget wheel(Widget child) => SizedBox(
|
|
width: kTimeWheelWidth,
|
|
height: kWheelItemExtent * 5,
|
|
child: child,
|
|
);
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
spacing: AppSpacing.xs,
|
|
children: [
|
|
wheel(
|
|
NumeralWheel(
|
|
key: const ValueKey('hour'),
|
|
count: 24,
|
|
value: hour,
|
|
loop: true,
|
|
digits: 2,
|
|
semanticLabel: 'Hour',
|
|
autofocus: true,
|
|
enabled: (h) => hourAllowed(h, minMinute, maxMinute),
|
|
onChanged: (h) => onChanged(
|
|
clampMinute(h * 60 + minute % 60, minMinute, maxMinute),
|
|
),
|
|
),
|
|
),
|
|
const Text(':', style: TextStyle(fontSize: AppTextSize.title)),
|
|
wheel(
|
|
NumeralWheel(
|
|
key: const ValueKey('minute'),
|
|
count: 60,
|
|
value: minute % 60,
|
|
loop: true,
|
|
digits: 2,
|
|
semanticLabel: 'Minute',
|
|
enabled: (m) {
|
|
final v = hour * 60 + m;
|
|
return v >= minMinute && v <= maxMinute;
|
|
},
|
|
onChanged: (m) => onChanged(hour * 60 + m),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|